Setting up PHPSPEC tests on Atlassian Bamboo can be a real pain; it's fundamentally simple, but it's so easy to kludge and the build process logs aren't that great. This guide will help you set things up from A to Z.
Setting up your Stages
A single stage should do. Click on the Create Stage button, give it a name, and save.
With your Stage created, access the Tasks tab, and configure your Source Code Checkout, defining the repository it will download. It will draw a list of repositories from any source control tool you've linked. [If you haven't yet done this, do it before continuing]
Next, we configure our tasks.
The Composer Build Task
- Click on 'Add Task'
- Find the 'Script' task and click 'Add'
- In its configuration window, give Task Description a name of 'Composer Build'
- Interpreter will be Shell
- Script Location will be Inline
- Your Script Body will contain:
/usr/local/bin/composer update 1>&2
Leave the remaining details blank, and click save.
The PHPSPEC Task
If your developers are like mine, they run their spec tests in pretty mode, but we'll need the output as junit would expect. Configure a script task as you previously did, changing the name to be something meaningful like Run PHPSpec, yet selecting an Interpreter of /bin/sh and use this Script body to sub pretty for junit:
#!/bin/bash sed -i -e 's/formatter.name: pretty/formatter.name: junit/g' phpspec.yml vendor/bin/phpspec run > build/junit.xml 2>/dev/null exit 0
The remaining fields are left blank, and you click Save. We do things this way, because phpspec will not exit with 0 if there are errors, and this is what Bamboo considers a success. This'll let phpspec finish, and subsequent tasks will run (such as the one where your JUNIT results are evaluated).
The JUnit Task
Lastly, you'll need to configure the test task.
- Click on Add Task and select the JUNIT type
- Give it a Task Description of Evaluate Test Results
- Specify custom results directories should read build/junit.xml
- Click Save
Still on the same screen, click on the Artifacts tab up top. Then, click on the Create definition button in the left hand corner of this tab.
- Location should read build
- Copy pattern should read *.xml
- The Shared checkbox remains unchecked
- Click Save
Done with Artifacts, click on the Miscellaneous tab, and check the User Clover to collect Code Coverage for this build checkbox. A section will expand, in which you select Clover is already integrated into this build and a clover.xml file will be produced. Lastly, specify Clover XML Location to be build/coverage.xml.
Putting it all together
The rest of the magic is actually done in your code's phpspec.yml configuration, and in your project's composer.json
Your phpspec configuration would typically look like this
suites: Lemonade: namespace: Lemonade spec_prefix: Spec src_path: module/Lemonade/src/ spec_path: module/Lemonade/bundle # # .... the rest of your suites are here # formatter.name: pretty extensions: PhpSpecCodeCoverage\CodeCoverageExtension: format: - html - clover output: html: build/coverage clover: build/coverage.xml whitelist: - module
Note the inclusion of the PhpSpecCodeCoverage\CodeCoverageExtension that's outputting into our build folder, that's keeping all .xml artifacts in Bamboo. Install that extension through composer, by installing henrikbjorn/phpspec-code-coverage