Skip to content

Instantly share code, notes, and snippets.

@hopeseekr
Created March 14, 2019 17:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hopeseekr/7c5feddeacf9fbcb386cb6fc0894a197 to your computer and use it in GitHub Desktop.
Real-World Continuous Integration

Real-World Continuous Integration

What is Continuous Integration (CI)?

Continuous Integration (CI) is the process of automating the build and testing of code every time a team member commits changes to version control. 

Here are the basic parts of a modern CI system:

  1. Automated Tests:
  • Unit Tests focus on one class at a time and thoroughly test -what- the class does. Unit tests typically don't test that features work, but that the code in isolation is sane.
  • Integration Tests focus on the whole application/library working as a whole. Integration tests always test from a high level, usually from the URL level and usally test stacks as well, like a mock web server and a test database
  • Acceptance Tests are formal tests that verify if the web app satisfies the anticipated business requirements. They require the entire application to be up and running. Acceptance tests are designed to test actual user behaviors. Think: Automated QA.
  1. Code Improving Utilities: A suite of projects that make code better.
  • Code Style Enforcement: Projects like php-cs-fixer actually change the code style so that consistent, industry- adopted standards are automagically maintained.
  • Static Analysis: Suites like phpstan and CodeClimate analyze the project's code for everything from syntax errors to high-level best practices that aren't implemented.
  1. Continuous Improvement: The most important benefit of CI is that it leads to continuous improvement of both the code base and the developers' capabilities. This is accomplished by the following:
  • Reporting Test Code Coverage: Every line of code that is tested via Unit and Integration tests is logged and a report is generated showing what code hasn't been tested yet.
  • Reporting code quality over time: Services such as CodeClimate and Scrutinizer CI keep records of the code quality and you can see quickly as a team whether the code is getting better or worse over time.
  • Sharing best practices with developers: Most CI tools and services point out areas of deficiencies and give developers insights and documentation on how to resolve them.

Real-World Project

The RESTSpeaker library is a good example of well-crafted PHP and a completely set up CI system.

Check it out over at https://github.com/phpexpertsinc/RESTSpeaker

Click on the badges at the top of the README to see the CI in action: CI Badges

Also pay special attention what happens when a PR is created. See PHPExpertsInc/RESTSpeaker#2 (comment)

In order for a PR to be merged, all tests must pass.

This ensures that only working code ever makes it into master, leading to a better experience for everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment