Running phpunit to test composer plugin vfsStream - phpunit

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.

Related

How to override a JMetre plugin jar in a Blazemeter Run

I am trying to troubleshot an error I'm getting in Blazemeter for random-csv-data-set.
The btz.log from the Blazemeter Test run shows the below line...
2021-02-10 10:14:52,518 INFO o.j.r.JARSourceHTTP: Downloading: https://search.maven.org/remotecontent?filepath=com/blazemeter/jmeter-plugins-random-csv-data-set/0.7/jmeter-plugins-random-csv-data-set-0.7.jar
Which could be the point it downloads the jar (latest one?) for the required plugins for my test.
And during the test I am getting an exception from one of the classes in the plugin jar.
I have cloned the plugin project (opensource) and started adding some debug lines and compiled a new jar version.
I was advised If I upload the plugin jar along with my tests files to Blazemeter, the uploaded jar should be taken in for the run. But I still see the exception from the old line numbers which means its still referring to the original jar version 0.7.
How can I override this with my version of the plugin?
I believe you should ask this type of questions via BlazeMeter Support as I doubt that everyone here is fully aware of what's going on there
Whatever.
Looking into Taurus documentation it looks like that Random CSV Data Set Config is being detected and automatically downloaded using JMeter Plugins Manager so in order to prevent Taurus from downloading the "vanilla" version of the plugin which doesn't contain your changes you need to add the following line to your Taurus YAML file:
modules:
jmeter:
detect-plugins: false

Codeception/Symfony4 Environment variable not found: "DATABASE_URL"

I have a project in Symfony4 with doctrine DB, everything flies.
I would like to add some functional and unit testing with Codeception. I followed the docs and added this to my functional.suite.yml:
actor: FunctionalTester
modules:
enabled:
- Symfony:
app_path: 'src'
environment: 'test'
- Doctrine2:
depends: Symfony
# cleanup: true
- \Helper\Functional
# - Db
step_decorators: ~
However, when running vendor/bin/codecept run I get an ugly:
In EnvVarProcessor.php line 131:
Environment variable not found: "DATABASE_URL".
I can't see anything else related in the docs, so not sure what I'm missing.
Does your codeception.yml configuration file have this section:
params:
- .env
- .env.test
- ...
If it has, you need to check the last .env file on the list and make sure that it has the DATABASE_URL variable set.
The other solution is that you remove every file from the list except the .env your app is using. (I don't suggest it)
When each file from this list loads, it overrides the variables that are present in the previous file.
I can't unfortunately explain the mechanisms behind it, but to resolve it I had to add DATABASE_URL environment variable to my OS.
export DATABASE_URL='mysql: ...';
This seemed very weird solution to me (which, again, I have no idea why Codeception would require this), so I kept digging. Something I discovered later, but seems actually cause the whole situation is how I installed Codeception. If you go to codeception docs you can read:
If you don't plan to do acceptance testing, you can get minimal installation of Codeception by requiring codeception/base
EDIT July 2020: Information about minimal install was removed from the linked website, looks like Codeception doesn't provide that option anymore.
This was how I had it installed. After playing around a lot I pulled a version of my code before codeception and installed using composer require codeception/codeception --dev (so the full version). After installing this way I had no issues.

PhpStorm: "Run with coverage" results in "Cannot load Xdebug - extension already loaded"

I just upgraded my PhpStorm project from PHPUnit 4.x to PHPUnit 5.x. Running my unit tests works fine.
In order to get "run with coverage" working, I had to edit my Run/Debug configuration and add --whitelist=/path/to/whitelisted/dir to Test Runner options. Now coverage is generated when I choose "Run with coverage," but I get this Xdebug warning.
Testing started at 12:06 PM ...
/usr/local/opt/php56/bin/php -dzend_extension=/usr/local/opt/php56-
xdebug/xdebug.so -dxdebug.coverage_enable=1
/Users/bwood/code/php/WpsConsole/vendor/phpunit/phpunit/phpunit --
whitelist=/Users/bwood/code/php/WpsConsole/src --coverage-clover /Users/bwood/Library/Caches/PhpStorm2017.3/coverage/WpsConsole$NEW.coverage --no-configuration /Users/bwood/code/php/WpsConsole/tests/UnitTests --teamcity
Cannot load Xdebug - extension already loaded
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.
I think the issue is that php is being called with
-dzend_extension=/usr/local/opt/php56-xdebug/xdebug.so
But I can't figure out where I can remove that option. I'm testing a console application so there is no webserver configuration.
I had two different problems that led to this same situation. (Mine was saying already loaded twice).
The first was the above debugger extension field in PHPStorm. I fixed that but was still having problems.
So then I ran:
>php --ini
Cannot load Xdebug - it was already loaded
Configuration File (php.ini) Path: /usr/local/etc/php/7.2
Loaded Configuration File: /usr/local/etc/php/7.2/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.2/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.2/conf.d/ext-opcache.ini
Since all of those files were in the same base directory I went to /usr/local/etc/php
$:/usr/local/etc/$ grep -r 'xdebug' .
./php/7.2/php.ini:zend_extension="xdebug.so"
./php/7.2/php.ini:zend_extension="xdebug.so"
This showed me that the problem was in my php.ini file. For some reason, I had this at the top of my php.ini file.
zend_extension="xdebug.so"
zend_extension="xdebug.so"
[PHP]
I removed one of the lines and the warning went away!
Check your PHP Interpreter in PhpStorm -- there is a separate field for xdebug extension. It allows you to not to have xdebug loaded in actual php.ini (so the ordinary script execution will be faster) and only load xdebug when needed (debug/coverage).
Based on your info so far you have it in php.ini and there. Proposed solution is to remove it from that field.
P.S. Obviously, it works for CLI stuff only and dopes not affect browser based debug in any way (as it's web server that runs PHP so IDE cannot pass such parameter there).

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!

Grunt build fails in travis - "Cannot find any-promise implementation"

I'm using travis to test my code. Recently the grunt tasks have started to fail without no change being made to anything involved with grunt. (The new commit which is tested contains just very minor changes in two PHP files.)
Here is the part of log from travis:
$ grunt build:app
Running "typings:default" (typings) task
Warning: Cannot find any-promise implementation nor global.Promise. You must install polyfill or call require("any-promise/register") with your preferred implementation, e.g. require("any-promise/register")("bluebird") on application load prior to any require("any-promise"). Use --force to continue.
Aborted due to warnings.
The command "grunt build:app" exited with 3.
I tried to search for that warning message but couldn't find anything useful.
One more thing: When I run grunt build:app locally on my pc it works just fine.
Thanks for your time :)
I had the same problem when I started using grunt-typings. Worked locally and didn't work on my CI server. Ended up fixing it by doing what the error message suggests:
npm install bluebird
npm install any-promise
In GruntFile.js:
require("any-promise/register")("bluebird");
Update your node.js version to >v0.12. To check your version of node.js use node -v. The documentation of any-promise explains:
Node.js versions prior to v0.12 may have contained buggy versions of the global Promise. For this reason, the global Promise is not loaded automatically for these old versions. If using any-promise in Node.js versions versions <= v0.12, the user should register a desired implementation.

Resources