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:
- 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.
- 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.
- 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.
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:
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.