Behat tests fail at random - symfony

I test my Symfony2 project with PHPUnit and behat/mink. This morning I added more behat tests to my project and all of a sudden random tests started failing. It seems like I hit a limit (memory? execution time? something else?) but I can't find anything.
Travis-ci does not fail on this http://travis-ci.org/#!/tvlooy/ReadingCorner/builds/383016
My local machine does fail (Lenovo R60, 2GB RAM, 2x 1.8Ghz CPU). I run Fedora 16 on x86, 32bit. PHP 5.3.8 (cli), with Xdebug v2.1.2, PHPUnit 3.6.2.
(edit: I just updated to PHPUnit 3.6.4 and removed Xdebug but the problem remains)
I run my Behat tests with:
$ app/console behat -e=test
=> random tests fail
When I run the tests like this:
$ for feature in 'find src/Ctors/ReadingCornerBundle/Features/ -name *.feature'; do app/console behat -e=test $feature; done
=> all tests pass
I already raised my memory_limit in php.ini to 768M but it didn't help.
I have 7 feature files with a total of 57 scenario's. Not much, nothing exotic. The files are in https://github.com/tvlooy/ReadingCorner/tree/master/src/Ctors/ReadingCornerBundle/Features
I need the tests to work on my local machine in one command because I generate code coverage from it with PHPUnit (wrapped behat features in PHPUnit).
Any clues?

#jakub_zalas blogged about a fix. See http://www.zalas.eu/fixing-failing-behat-scenarios-in-large-suites
Setting 1002: 'SET SESSION wait_timeout=30;' fixed it for me too.

Please, run your features with -v and gist the output

Related

PhpStorm + PHPUnit failures not displayed in Test Tab

I want to run tests in my applications in PhpStorm. Application is running on Symfony, for tests I am using PHPUnit and Symfony PHPUnit bridge.
Tests are running, but PhpStorm does not display any failure - it says: "All tests passed". In raw output is log of failure, so test failed (see screenshot), but PhpStorm did not show it.
Can anyone help me please?
Please follow the issue, Sebastian has changed line endings so we'll have to update our parser.
https://youtrack.jetbrains.com/issue/WI-42390
https://github.com/sebastianbergmann/phpunit/commit/56de7e9f96869a808fefc5a2fefbca7970ad2aab
I am using newest version of PHPStorm. I tried to downgrade from PHPUnit 7^ to PHPUnit 6^, after that downgrade it works perfectly. So I found temorary fix for this.

PhpStorm: error executing Behat tests No specifications found at path(s) but works from command line

I'm using PhpStorm and Vagrant to develop a Symfony project.
I configured PhpStorm to execute Behat tests with the Vagrant machine but when I try to run or debug them I got this error:
vagrant:///Users/jose/Documents/WWW/symfony_project/usr/bin/php /home/vagrant/.phpstorm_helpers/behat.php --format PhpStormBehatFormatter --config /var/www/symfony/behat.yml /var/www/symfony/features/api/brand/full_rest.feature:13
Testing started at 10:48 ...
0 scenario0 step0m0.05s (14.76Mb)
[Behat\Testwork\Tester\Exception\WrongPathsException]
No specifications found at path(s) `/var/www/symfony/features/api/brand/full_rest.feature:13`. This might be because of incorrect paths configuration in your `suites`.
Although if I execute it from the command line inside the Vagrant machine it works OK:
./vendor/bin/behat --config /var/www/symfony/behat.yml /var/www/symfony/features/api/brand/full_rest.feature:13
#brands #api
Feature: API to manage the brands
As a frontend app
.......
I've configured the PHP Interpreter with my Vagrant VM and I also think the Behat configuration is set OK: I see the Behat version, I've set the behat config path... I don't understand why the execution from PhpStorm fails.
Any ideas? Thanks in advance
This a bug in behat 3.4.0 breaks the ability to run individual tests
Try to switch back to "behat/behat": "3.3.1".

Running PHPUnit test in PhpStorm adds "--teamcity" option causing error

I have the latest PhpStorm (2016.2) and PHPUnit phar (5.5.4). For some reason when I run a PHPUnit test in my project in PhpStorm, it is adding on --teamcity to the run command, resulting in a failure:
Testing started at 12:52 PM ...
Unit test suite invoked with a path to a non-unit test: --teamcity
Process finished with exit code 1
I have no idea where this --teamcity option is coming from, it happens no matter what test I run, and even when starting from a blank configuration. I also do NOT have the TeamCity plugin installed, I don't even use TeamCity.
Here's what the full command appears as:
/usr/local/Cellar/php70/7.0.9/bin/php /Users/name/bin/phpunit-5.5.4.phar --configuration /path/to/config/my-phpunit.xml ClassNameTest /Users/name/PhpstormProjects/path/to/tests/unit/app/ClassNameTest.php --teamcity
(sensitive information swapped out)
All I want to do is get rid of this --teamcity option, everything works if I run in a separate terminal window without that option. This only recently started happening, maybe after a PhpStorm update.
tl;dr
I only could resolve this by removing the system installed phpunit instance from my system (Linux):
sudo apt remove phpunit-*
Details
Even if the setting in PhpStorm was to use composer autoloader:
for some reason it ended up using TeamCity from /usr/share/php/PHPUnit/Util/Log/TeamCity.php:
Project's local PHPUnit was 6.2 while the system default was 5.1 -> they're incompatible.
I spent half a day struggling with this. The underlying issue is switching between PHPUnit versions (6.x.x -> 4.x.x). (Happened to me by switching branches)
A click on the refresh button in the PHPUnit preferences fixes it.
(Languages & Frameworks > PHP > PHPUnit)
Make sure the version of PHPUnit it thinks you have matches the one it reports.
This --teamcity option is used by PHPStorm to output tests result.
What you're facing is an issue caused by PHP7 and an old version of PHPUnit.
Remove your PHPUnit 5 and install the latest one (currently 6.2) with composer and use PHPUnit namespaces instead.
More info on this bug: https://github.com/sebastianbergmann/phpunit/issues/2460
Problem was internal to the project. PHPUnit does not contain that error message. Sorry!

Twig Error after Symfony 2.7 Upgrade: "The "native_profiler" extension is not enabled

After A Symfony Upgrade, composer.json
"symfony/symfony": "2.4.*",
"symfony/symfony": "2.7.*",
I get a Error while running phpunit tests. In env dev and prod everything works fine.
log output:
request.CRITICAL: Uncaught PHP Exception Twig_Error_Runtime: "The native_profiler" extension is not enabled in "#WebProfiler/Profiler/toolbar_js.html.twig"
The twig native profile extension is turned on automatically if the debug mode is on and turned off if the debug mode is off in Symfony 2.7. So if you warming up the cache with debug mode on the twig templates are rendered with the profiler enabled.
But if a test runs with debug off (for example Kris Wallsmith solution is used) the extension is disabled in the tests (but still enabled in pre-rendered templates), that cause the error.
Solution: before running tests clear the cache with debug mode off.
app/console cache:clear --env=test --no-debug
The cache will be cleared and warmed up without the twig profiler.
I had the same issue today, but slightly different. At the end I found out, that the TwigProfiler is enabled in debug-mode automatically.
In KernelTestCase.php I found:
isset($options['debug']) ? $options['debug'] : true
So in my TestCases I added the option 'debug' => false and it worked again.
I had a similar error on our jenkins. Our CI job runs (1) PHPUnit tests, than (2) functional tests with LiipFunctionalTestBundle and at the end (3) protractor tests.
The twig templates were compiled by the functional tests (2) which configures the kernel to be in debug mode. The Protractor tests however start a PHP server in test env but not in debug mode. So the twig templates were not compatible. I solved the problem by deleting the cache between step (2) and (3).
Clearing the cache after changing debug mode appears to have solved my issue.
I had to use --no-debug switch also when generating javascript translation files with bazinga:js-translation:dump
For example like this command
../app/console bazinga:js-translation:dump -vvv --no-debug -e stage
Try updating version. It helped for me from version 1.18 to 1.24.
Using Symfony 2.7 with Sylius 0.13
More info:
https://github.com/symfony/symfony/issues/15318
https://github.com/twigphp/Twig/pull/1824

Running phpunit to test composer plugin vfsStream

Using PHPStorm on a project with Composer and PHPUnit (all of which have already work correctly) how do I run PHPUnit test on a composer plugin inside "vendor" in this case mikey179/vfsStream?
My project structure looks like this:
myscripts/
vendor/
- mikey179
- vfsStream
composer.json
I want to run PHPUnit to test vfsStream plugin.
I was able to run Testing on my own test code (outside vendor directory).
When I run PHPUnit test (That little green play button on top) I got the following:
usr/bin/php /tmp/ide-phpunit.php --bootstrap /path/to/project/vendor/autoload.php --configuration /path/to/project/vendor/mikey179/vfsStream/phpunit.xml.dist /path/to/project/vendor/mikey179/vfsStream
Testing started at 5:53 PM ...
PHPUnit 3.8-g8d770d8 by Sebastian Bergmann.
Configuration read from /path/to/project/vendor/mikey179/vfsStream/phpunit.xml.dist
Time: 2.22 seconds, Memory: 2.25Mb
No tests executed!
PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /path/to/project/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Report/HTML.php on line 127
PHP Stack trace:
PHP 1. {main}() /tmp/ide-phpunit.php:0
PHP 2. IDE_Base_PHPUnit_TextUI_Command::main() /tmp/ide-phpunit.php:506
PHP 3. PHPUnit_TextUI_Command->run() /tmp/ide-phpunit.php:268
PHP 4. PHPUnit_TextUI_TestRunner->doRun() /path/to/project/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php:173
PHP 5. PHP_CodeCoverage_Report_HTML->process() /path/to/project/vendor/phpunit/phpunit/PHPUnit/TextUI/TestRunner.php:465
PHP 6. date() /path/to/project/vendor/phpunit/php-code-coverage/PHP/CodeCoverage/Report/HTML.php:127
Generating code coverage report in HTML format ... done
Process finished with exit code 0
From what I see it's an issue with PhpStorm's helper/wrapper script (/tmp/ide-phpunit.php), which is used for integration purposes (track tests progress in real time -- messages must be formatted in specific way; etc).
Test files do not have standard and expected Test.php ending -- instead they have custom TestCase.php .. and helper script seems to be unable to apply that config option from phpunit.xml.dist file correctly (it will search for *Test.php files only).
If you rename all *TestCase.php file to be *Test.php it will start working in PhpStorm (I've renamed just a few .. and they got detected and executed just fine).
Right now I may only suggest to either rename test files as described above (which is not a good idea in long run if you plan to run those tests on regular basis and keep downloading latest sources of that library) or submit a bug ticket to PhpStorm Issue Tracker explaining the situation: http://youtrack.jetbrains.com/issues/WI and hopefully devs will fix it soon.
You don't run a test on a package in vendor/. You clone the repo and follow the instructions they've given in the testing documentation. In the case of mikey179/vfsStream, there's a github repo: https://github.com/bovigo/vfsStream and it even has a .travis.yml file you can read for inspiration: https://github.com/bovigo/vfsStream/blob/master/.travis.yml
If you're concerned that you've got a version of vfsstream that doesn't pass tests, then you can look at the version that's installed in your project with composer show mikey179/vfsStream and then check out that tag in the repo before running the tests.
The reason is that the package might very well have different dev dependencies than your project, so no matter what else you do you'll end up with broken test runs. Composer ignores dev dependencies for packages other than the main project.

Resources