Running Acceptance Tests With Codeception
I stumbled over Codeception and thought it looks pretty nice based from what I’ve seen in their docs. So I tried to install it and “play” with it.
Where the troubles started
Just adding the codeception package as a dependency in the composer.json file and running
composer update installed a bunch of other packages. So far everything went fine. But then, my Flow based app didn’t work anymore. Running a ``./flow flow:cache:flush` (or warmup) just ended in some heavy-duty low-level Exceptions:
Uncaught Exception [Semantical Error] The annotation "@something" in method SomeClass::someMethod() was never imported. Did you maybe forget to add a "use" statement for this annotation? More Information Exception code #0 File /var/www/flow/Packages/Libraries/doctrine/annotations/lib/Doctrine/ Common/Annotations/AnnotationException.php line 52
This could be solved with the first solution below. But then the next issue popped up: Some Exceptions for almost every single dependency that was installed. For most of them, something complained about a PHPUnit-Class:
PHP Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /var/www/flow/Packages/Libraries/fabpot/goutte/Goutte/Tests/ClientTest.php on line 31 Uncaught Exception Execution of subprocess failed with exit code 255 and no output.
A possible solution
After being stuck there, Christian Müller gave me an important hint, thanks again!
In my Flow Package’s config, within the Settings.yaml I’ve added the following lines that solved the issue so far:
TYPO3: Flow: reflection: # adding some custom annotations because of simplepie and codeception ignoredTags: ['api', 'package', 'subpackage', 'license', 'copyright', 'author', 'const', 'see', 'todo', 'scope', 'fixme', 'test', 'expectedException', 'depends', 'dataProvider', 'group', 'codeCoverageIgnore', 'xml_lang', 'source', 'type', 'id'] object: # we need to exclude some additional classes from the reflection because of # simplepie, codeception and all their dependencies... excludeClasses: 'simplepie.simplepie' : ['.*'] 'Codeception.*' : ['.*'] 'videlalvaro.*' : ['.*'] 'Psr.*' : ['.*'] 'fabpot.*' : ['.*'] 'behat.*' : ['.*']
Attention: The ignoredTags must be on one single line within the config.
Running the first test
After adding the above mentioned config lines, I was able to get both my Flow application back to run and also run my first acceptance test. Here’s how I did that:
This prepared some directories and files in the
tests directory. There was also a configuration file generated at
flow/tests/acceptance.suite.yml where I only had to change the base URL of my application to define, where the WebGuy tries to execute it’s checks.
The next step was to create my first test scenario. This could be created with the following command:
Packages/Libraries/codeception/codeception/codecept generate:cept acceptance Signin
The command generates a file in
flow/tests/acceptance/SigninCept.php which I extended to contain the following code lines:
<?php $I = new WebGuy($scenario); $I->wantTo('perform actions and see result'); $I->amOnPage('/'); $I->see('Welcome to MyNewProject!');
Then finally I could execute the test with the following command:
Of course, this is just a very basic setup. But so far it looks very promising - besides it’s slowness (as mentioned in the documentation) :-)