Running phpunit tests using PhpStorm.
Receiving this error:
/usr/local/php5/bin/php
/private/var/folders/m8/k61mmmmj7g732j3pd0_91s0c0000gn/T/ide-phpunit.php
--configuration /Users/psteinheuser/unity/test/phpunit.xml DatabaseDumperTest
/Users/psteinheuser/unity/test/DatabaseDumperTest.inc Testing started
at 11:36 AM ...
Fatal error: Class IDE_PHPUnit_Framework_TestListener contains 1
abstract method and must therefore be declared abstract or implement
the remaining methods (PHPUnit_Framework_TestListener::addRiskyTest)
in
/private/var/folders/m8/k61mmmmj7g732j3pd0_91s0c0000gn/T/ide-phpunit.php
on line 504
Call Stack:
0.0013 340096 1. {main}() /private/var/folders/m8/k61mmmmj7g732j3pd0_91s0c0000gn/T/ide-phpunit.php:0
PHP Fatal error: Class IDE_PHPUnit_Framework_TestListener contains 1
abstract method and must therefore be declared abstract or implement
the remaining methods (PHPUnit_Framework_TestListener::addRiskyTest)
in
/private/var/folders/m8/k61mmmmj7g732j3pd0_91s0c0000gn/T/ide-phpunit.php
on line 504
Have found previous posts which have said this is fixed, though I seem to have the correct versions where it should work.
PHPStorm 7.1.3
phpunit 3.7.28
php 5.4.24
The OS is Mac 10.9.2
Have removed and re-installed PHPStorm, upgraded php, re-installed phpunit, restarted apache, rebooted, scratched my head, etc.
Running the phpunit tests manually from the terminal, works fine.
Looking at Preferences within PHpStorm, it seems to be pointing to phpunit correctly.
I'm thinking it's a permission or path issue, but I don't know where to look next.
Appreciate any input or direction.
In PHPStorm, the only way I was able to solve this was by manually updating the contents of the jar file where this error exists.
We're both on Mac OSX 10.9, so these instructions should work for you.
Begin by making a copy of the existing jar file:
cp /Applications/PhpStorm.app/plugins/php/lib/php.jar /Applications/PhpStorm.app/plugins/php/lib/php.jar.orig
Now, create a temporary directory to hold your jar file's contents and extract
mkdir ~/jarfiles
cd ~/jarfiles
jar xf /Applications/PhpStorm.app/plugins/php/lib/php.jar
Once extracted, you'll need to edit the phpunit.php file to add the missing method stub
vi scripts/phpunit.php
Around line 310 in my file is a class 'IDE_PHPUnit_Framework_TestListener'. Insert the following method stub:
public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time){}
Now just re-pack your jar and replace it into your PhpStorm:
jar cf0 php.jar ./*
mv php.jar /Applications/PhpStorm.app/plugins/php/lib/php.jar
That fixed it for me. Hope it fixes it for you too. Good luck!
Related
I have created a number of selenium IDE files that I converted to phpunit format in Firefox IDE 2.9.1.1 (on a Windows box), using Options -> Format converter. Those converted files define a class "Example" that is derived from class PHPUnit_Extensions_SeleniumTestCase. I now know that this class needs to be changed to PHPUnit_Extensions_Selenium2TestCase. The problem is, I cannot get this to run with recent versions of phpunit.
I am running these tests on a Fedora 24 VM which is using php 5.6.30, java 1.8.0_121-b14, and firefox 51.0.1-2. I have tried to get these to run using selenium standalone server 3.0.1 (and now 3.1.0), and phpunit 5.7.13. I have the latest php facebook WebDriver installed. The error I keep getting is that the above mentioned class is not found. I did a grep on that class and this is what I found:
[root#localhost bin]# grep -r "PHPUnit_Extensions_Selenium2TestCase" .
Binary file ./phpunit/phpunit-4.6.7.phar matches
Binary file ./phpunit/phpunit-4.7.6.phar matches
So, it appears that this class does not exist in phpunit 5.7 and above (which are in that directory), nor does it exist in html-runner.phar, which is in the same directory. The seleniumhq.org site says to use html runner if you convert from IDE, but I can find no examples of how to use the html-runner.phar file (and no documentation).
Can someone please tell me what I should change the class name to, to get this test to work?
UPDATE:
I now know that if I want to use phpunit and selenium server to drive a firefox browser, I have to get selenium talking to geckodriver. I have installed:
geckodriver 0.14.0 at /usr/local/bin/geckodriver
selenium server 3.0.1 at /usr/local/bin/selenium
phpunit-5.7.13.phar installed at /usr/local/bin/phpunit
I used composer to add webdrivers (facebook 1.3.0 :
[root#localhost composer]# cat composer.json
{
"require": {
"facebook/webdriver": "^1.3",
"phpunit/phpunit": ">=3.7",
"phpunit/phpunit-selenium": ">=1.2"
}
}
php composer.phar install
They were added to the PATH:
[bjt#localhost projects]$ echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/local/bin/selenium:/usr/local/bin/phpunit:/usr/local/bin/composer:/usr/local/bin/geckodriver
I have a small test file:
?php
require_once('/usr/local/bin/composer/vendor/autoload.php');
class test extends PHPUnit_Extensions_Selenium2TestCase
{
protected function setUp()
{
$this->setBrowser("*firefox");
$this->setBrowserUrl("https://fakeurl.com/");
}
public function testMyTestCase()
{
$this->open("/");
}
}
Starting the selenium server:
java -jar /usr/local/bin/selenium/selenium-standalone-3.0.1.jar
When I run the test:
/usr/local/bin/phpunit/phpunit-5.7.13.phar --verbose test.php
Yields this error:
PHPUnit_Extensions_Selenium2TestCase_WebDriverException: The best matching driver provider Firefox/Marionette driver can't create a new driver instance for Capabilities [{browserName=*firefox}]
So, it appears that geckodriver is not talking to selenium server. If I try to force the issue by changing the execution of the server:
java -Dwebdriver.gecko.driver="/usr/local/bin/geckodriver/geckodriver" -jar /usr/local/bin/selenium-server-standalone-3.0.1.jar
or
sudo java -Dwebdriver.gecko.driver="/usr/local/bin/geckodriver/geckodriver" -jar /usr/local/bin/selenium-server-standalone-3.0.1.jar
It makes no difference. I'm hoping someone can point out what I am missing. I'm at a dead end.
I am currently working through the same process of getting this to work and would like to point out a few things:
htmlrunner is meant to run the test cases saved directly from the Selenium IDE in the default format, which is html.
Make sure you can run firefox from the terminal running the selenium server.
You added two different selenium php bindings. The facebook one and the phpunit-selenium. I currently have it working with only the facebook binding and phpunit extending the class PHPUnit_Framework_TestCase. I would recommend using the example provided within github for facebook/webdriver without phpunit to verify that your selenium config is working, then add phpunit.
I'm trying to run the PHPUnit into the NetBeans 8.0.2.
If I run # phpunit inside my folder tests all tests run. So it's seems been set right.
But in the NetBeans output I always got:
"C:\nginx\php\5.6.12\php.exe" "C:\nginx\php\5.6.12\phpunit.phar" "--colors" "--log-junit" "C:\Users\...\AppData\Local\Temp\nb-phpunit-log.xml" "--bootstrap" "E:\var\www\...\tests\TestHelper.php" "--configuration" "E:\var\www\...\tests\phpunit.xml" "C:\Program Files\NetBeans 8.0.2\php\phpunit\NetBeansSuite.php" "--run=E:\var\www\...\tests\app\utils\FormatUtilTest.php"
PHPUnit 4.8.2 by Sebastian Bergmann and contributors.
unrecognized option --run
Done.
Maybe the "--run message" it's right, because this command doesn't exist in the PHPUnit manual. But if is that so, how to create another script for the NetBeans execute the tests?
I ran into the same issue yesterday after a PHPUnit update. So I reverted back to PHPUnit 4.7.7 for now, until this is fixed in NB.
I too have encountered this error causing the latest version of PHPUnit not to work with NetBeans v8.0.2.
Further investigating this issue has resulted in determining that there is an incompatibility between NetBeansSuite.php and the latest version of PHPUnit.
The error 'unrecognized option --run' is being thrown by the phpunit.phar and not being thrown by NetBeansSuite.php. I also do not believe the NetBeansSuite.php is even being executed.
phpunit.phar, line 63816 or 63894, is where the exception is being thrown.
Until this is fixed, PHPUnit will not work from NetBeans v8.0.2.
#Pablo: I thank you for opening an issue and have commented on your issue.
PHPUnit v4.7.7 works correctly.
Opened a bug report: https://netbeans.org/bugzilla/show_bug.cgi?id=254276
The answer is: This was indeed a bug in NB and is now fixed in nightly.
Possible solutions:
Upgrade to latest nightly from http://bits.netbeans.org/dev/nightly/
Use PHPUnit 4.7.7 as mentioned by Luuk
"--run" option is used in the NetBeansSuite.php for running tests. So, you should submit that to NetBeans bugzilla [1] if you want to avoid that.
[1] https://netbeans.org/community/issues.html (PHP/PHPUnit)
2019 and the problem still exists. Downgrading PHPUnit is no option anymore today. So I created, as a workaround, a wrapper script for phpunit which takes care of removing the bad parameters.
It also removes the NetBeansSuite.php file completely because it does the same a call directly to the phpunit script would.
My setup is Windows Netbeans 11, Windows PHP 7.3, and a cygwin wrapper (because it's bash code). If somebody feels like porting this to native windows, please leave a comment here.
#!/usr/bin/env sh
# modified phpunit script originally from vendors dir
# 1. cygwin default search path is bad in my installation...
PATH="$PATH:/bin:/usr/bin"
# original code, only adjust the ../../ to match your installation.
# the directory this is run in is where the wrapper script resides
dir=$(cd "${0%[/\\]*}" > /dev/null; cd "../../vendor/phpunit/phpunit" && pwd)
if [ -d /proc/cygdrive ] && [[ $(which php) == $(readlink -n /proc/cygdrive)/* ]]; then
# We are in Cgywin using Windows php, so the path must be translated
dir=$(cygpath -m "$dir");
fi
# fix netbeans parameters
while [ $# -gt 0 ]; do
case "$1" in
*NetBeansSuite.php) shift;;
--run=*) PARAMS="$PARAMS ${1#--run=}"; shift;;
--) shift ;;
*) PARAMS="$PARAMS $1"; shift;;
esac
done
"${dir}/phpunit" $PARAMS
You have to adjust both occurrences of "../"s to your folder structure.
This solution works with ALT-F6 (run all tests), right clicking a test folder "Run Tests" and also single test files right click "Run".
The setting for "Netbeans: Tools/Options/Frameworks & Tools/PHPUnit" is then:
C:\cygwin\bin\bash.exe /cygdrive/c/workspace/Project/src/cli/phpunit
Adjust these path names to your needs, again.
HTH,
M.
I've started learning how to use PHPUnit. However, I'm facing a problem which I have no clue how to solve.
I have a folder called lessons and inside there is a composer.json which I installed PHPUnit with.
The output resulted in a folder called vendor and a sub-folder called bin which has the phpunit file in it.
In the cmd I typed: cd c:/xampp/htdocs/lessons/vendor/bin. Now the cmd folder sets to the same folder as phpunit. I've created a directory in lessons which I called tests (lessons/tests) which I store all of my tests in. I've created a file called PracticeTest.php with a very simple test script in it.
When I go back to the cmd and type phpunit tests I get cannot open file tests.php When I try to type phpunit PracticeTest I get cannot open file PracticeTest.php. When I try phpunit tests/PracticeTest (with .php or without) I get the same error that the file could not be opened.
My suspicious that it has something to do with that face that the cmd is pointing at the lessons/vendor/bin directory, but I'm not sure if it is really the problem or how to fix it.
just to arrange the paths:
lessons\vendor\bin\
lessons\tests\
lessons\tests\PracticeTest.php
Thanks in advance!
Go to path project:
D:\>cd www
D:\wwww>cd lessons
And execute:
D:\www\lessons>vendor\bin\phpunit tests
PHPUnit 4.8.27 by Sebastian Bergmann and contributors.
.....E.
Time: 1.34 seconds, Memory: 5.50MB
There was 1 error:
1) UserTest::it_should_be_able_to_construct
PHPUnit_Framework_Exception: Argument #1 (No Value) of PHPUnit_Framework_Assert
:assertInstanceOf() must be a class or interface name
D:\www\lessons\tests\UserTest.php:10
FAILURES!
Tests: 7, Assertions: 4, Errors: 1.
It Works!!!!
This is what worked for me.
vendor/bin/phpunit ./tests/PracticeTest
I was getting the same, but if you type phpunit then tab you will see what directory you are in and it should autosuggest. Then navigate to your test file.
I had include_path sections separated by comma. It has to be semicolon on Windows.
I have created a phpunit.bat in the root folder of my project containing
#ECHO OFF SET BIN_TARGET=%~dp0/vendor/phpunit/phpunit/phpunit php "%BIN_TARGET%" %*
Now it works.
I was happily working away in my development environment and suddenly I started getting the following error:
PHP Fatal error: Cannot redeclare composerRequire7a368ac394ae1d2e857becf2a235ebaa() (previously declared in [APP_ROOT]/vendor/composer/autoload_real.php:56) in [APP_ROOT]/vendor/composer/autoload_real.php on line 59
I haven't made any changes to speak of in composer dependencies (although I think I did do a composer update somewhere in that timeframe but no changes to the dependencies/packages used so nothing big should have changed.
Notably, when I checkout the repo on my laptop I do NOT get this error but if I git clone a clean repo and then composer install on my main development machine I DO get this error. So I'm assuming it must have some machine-specific origin but I'm running out of ideas on what that might be.
Any help would be greatly appreciated.
Note: I'm running PHP 5.3.28 on OSX; my app uses namespacing and is PSR0 compliant
Also of note is that I'm running PHPUnit 4.0.17 and the error is triggered at the very first stages of trying to run a unit test (it doesn't matter WHICH unit test). Here's the stack trace:
0.0009 636648 1. {main}() [APP_BASE]/vendor/phpunit/phpunit/phpunit:0
0.0465 1423664 2. PHPUnit_TextUI_Command::main() [APP_BASE]/vendor/phpunit/phpunit/phpunit:54
0.0465 1424280 3. PHPUnit_TextUI_Command->run() [APP_BASE]/vendor/phpunit/phpunit/src/TextUI/Command.php:132
0.0465 1424280 4. PHPUnit_TextUI_Command->handleArguments() [APP_BASE]/vendor/phpunit/phpunit/src/TextUI/Command.php:141
0.0674 2123344 5. PHPUnit_TextUI_Command->handleBootstrap() [APP_BASE]/vendor/phpunit/phpunit/src/TextUI/Command.php:638
0.0681 2139872 6. PHPUnit_Util_Fileloader::checkAndLoad() [APP_BASE]/vendor/phpunit/phpunit/src/TextUI/Command.php:808
0.0681 2140008 7. PHPUnit_Util_Fileloader::load() [APP_BASE]/vendor/phpunit/phpunit/src/Util/Fileloader.php:77
0.0774 2144176 8. include_once('[APP_BASE]/tests/test-loader.php') [APP_BASE]/vendor/phpunit/phpunit/src/Util/Fileloader.php:93
0.0775 2146736 9. include('[APP_BASE]/vendor/autoload.php') [APP_BASE]/tests/test-loader.php:2
Delete composer.lock and vendor/ and run composer update again.
I had this problem when I made a copy of an existing project directory and tried to run phpunit on the new directory. Finally figured out that when I executed phpunit, it was running out of the old directory. I ran this:
which phpunit
And saw that it was running from my composer vendor directory:
/home/vagrant/Code/MYOLDPROJECT/api/vendor/bin/phpunit
I ran phpunit from the new directory and the problem disappeared:
/home/vagrant/Code/mynewproject/api/vendor/bin/phpunit
I have created my own codesniffer rules standards.They are working fine. Now I want to test codesniffer rules using PHP UnitTest. PhpCodesniffer has already have their framework for PHPUnit test case.
So using that I have extended their AbstractSniffUnitTest and unit test class at location
Standards/TestRules/Tests/Function/FunctionUnitTest.php and script on which is to be tested kept in Standards/TestRules/Tests/Function/FunctionUnitTest.inc.
But when I am going to run the script by command phpunit PEAR\PHP\tests\AllTests.php, it gives following error.
PHPUnit 3.5.14 by Sebastian Bergmann.
......................................F
Time: 6 seconds, Memory: 10.00Mb
There was 1 failure:
1) TestRules_Tests_Function_FunctionUnitTest::getErrorList
An unexpected exception has been caught: Source file C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.inc does not exist
C:\Program Files\PHP\PEAR\PHP\tests\Standards\AbstractSniffUnitTest.php:138
C:\Program Files\PHP\PEAR\PHP\tests\TestSuite.php:48
FAILURES!
Tests: 39, Assertions: 146, Failures: 1.
Warning: Deprecated PHPUnit features are being used 2 times!
Use --verbose for more information.
It gives error file FunctionUnitTest.inc not found at given location. I have given full permission to folder also verify the path and file location, but it gives same error. I have tested it on linux machine also, but it gives same error.
Is it a my code issue or codesniffer unittest framework issue?
Are your files in the top-level tests or CodeSniffer directory? Note that the abstract test case you're extending is in tests
C:\Program Files\PHP\PEAR\PHP\tests\Standards\AbstractSniffUnitTest.php
but is trying to include the file from CodeSniffer:
C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.inc
Try moving your two files to the other directory.
I see a space near i i nc - make sure if that is mis-typo and correct it, it should work. Other than this I don't see any problem.
Change:
C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.i nc
To
C:/Program Files/PHP/PEAR/PHP/CodeSniffer/Standards/TestRules/Tests/Function/FunctionUnitTest.inc
It seems that it has path issue on windows. I tested the test cases on Linux, it works fine. When I checked the actual code, it seems that on there is file mapping from test case file to sniff file. But on window, after file being mapped , the file path contains mixing of forward & backward slahes.But codesniffer not going to allow this. Because of that it is returning that “file is not found error”. Test cases are executing fine on Linux.