I have chosen to use a Phar of PHPUnit (phpunit-4.8.26.phar) to unit test my custom built PHP Framework and Application. The reason I am using the old stable release is because I need compatibility with PHP 5.4.29.
The reason I have chosen not to use Composer to get PHPUnit is because it's tends to pollute my vendors folder with dependencies. I like to keep it as lean as possible.
I am using Windows 7 Pro SP1, WampDeveloper v5.4.0.1, ProPhpStorm 2016.1.2, Phing and a whole bunch of other cool stuff to do my thing.
The Problem
I CAN run a passing unit test successfully from within PhpStorm.
I CAN run a group of passing unit tests successfully from within PhpStorm.
I CAN NOT run a FAILING unit test successfully from within PhpStorm.
I CAN run a passing unit test successfully from the command line.
I CAN run a group of passing unit test successfully from the command.
I CAN NOT run a FAILING unit test successfully from the command line.
Instead of PHPUnit display a typical test failure message it exits with the below errors:
Warning: require(Composer\Autoload\ClassLoader.php): failed to open stream: No such file or directory in D:\WampDeveloper\Websites\qclean.development\bootstrap\Autoloader.php on line 23
Fatal error: require(): Failed opening required 'Composer\Autoload\ClassLoader.php' (include_path='.;D:\WampDeveloper\Tools\PEAR\pear;D:\WampDeveloper\Tools\PEAR;D:\WampDeveloper\Components\Php\PEAR;D:\WampDeveloper\Tools\PHPMailer;') in D:\WampDeveloper\Websites\qclean.development\bootstrap\Autoloader.php on line 23
And a screen shot to expand on the above:
Supporting Info
My directory structure:
My unit test script ConfigurationTest.php
<?php
/**
* Created by PhpStorm
* User:
* Date: 04/06/16
* Time: 12:04 PM
*/
namespace nova\tests\configuration;
use PHPUnit_Framework_TestCase as TestCase;
/**
* Class ConfigurationTest
*
* #package nova\tests\configuration
*/
class ConfigurationTest extends TestCase
{
protected function setUp()
{
parent::setUp();
}
public function test()
{
$result = false;
$this->assertTrue($result);
}
protected function tearDown()
{
parent::tearDown();
}
}
My PHPUnit XML configuration file TestAll.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="../../../bootstrap/Start.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
syntaxCheck="false"
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
verbose="false">
<testsuites>
<testsuite name="Nova Framework Test Suite">
<!-- <directory>.</directory> -->
<directory>./configuration</directory>
<exclude>./input</exclude>
<exclude>./request</exclude>
<exclude>./security</exclude>
<exclude>./validation</exclude>
</testsuite>
</testsuites>
</phpunit>
And lastly my Autoloader Autoloader.php
<?php
// Ref: https://github.com/philsturgeon/fig-standards
/**
* Define the application autoloader function.
*/
function autoload($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$namespace = '';
if ($lastNsPos = strrpos($className, '\\'))
{
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}
$fileName .= str_replace('_', DIRECTORY_SEPARATOR, $namespace) . '.php';
require $fileName;
}
/**
* Register the autoloader functions.
*/
spl_autoload_register('autoload');
The error and warning indicate the inability to load the Composer\Autoload\ClassLoader.php file. What I don't understand is why it is asking for this file when I am using a Phar? Reading snippets off the internet indicate the Phar should have an internal autoloader though I am unable to see one.
I do not want to have to install Composer just to get it's autoloader. That would defeat the purpose of trying to solely use the Phar.
I added the PHPUnit Phar path to my Windows %path% but this did not make any difference. I understand that this should be done if PHPUnit was installed using PEAR.
Any help on this 'hair pulling out matter' would be greatly appreciated...
If you look at the stack trace, you'll see that the error is triggered on class_exists. This function calls __autoload by default. This means that the autoloader you registered will be called. In this case it will be called for a class that exists outside of your project.
So you should add an extra file_exists check to your autoloader before requiring the file. You're requiring a file that doesn't exist.
if (file_exists($fileName)) {
require $fileName;
}
Or just suppress the error (require doesn't throw an exception, so use #):
#require $fileName;
All what you need to do it to go to Settings > Language & Frameworks > PHP > PHPUnit and Choose PHPUnit library - and set path to phpunit.phar, that's all.
Related
I have just installed PHPUnit version 3.7.19 by Sebastian Bergmann via Composer and have written a class I would like to unit test.
I would like to have all my classes autoloaded into each unit test without having to use include or require at the top of my test but this is proving to be difficult!
This is what my directory structure looks like (a trailing / slash indicates a directory, not a file):
* composer.json
* composer.lock
* composer.phar
* lib/
* returning.php
* tests/
* returningTest.php
* vendor/
* bin/
* phpunit
* composer/
* phpunit/
* symfony/
* autoload.php
My composer.json file includes the following:
"require": {
"phpunit/phpunit": "3.7.*",
"phpunit/phpunit-selenium": ">=1.2"
}
My returning.php class file includes the following:
<?php
class Returning {
public $var;
function __construct(){
$this->var = 1;
}
}
?>
My returningTest.php test file includes the following:
<?php
class ReturningTest extends PHPUnit_Framework_TestCase
{
protected $obj = null;
protected function setUp()
{
$this->obj = new Returning;
}
public function testExample()
{
$this->assertEquals(1, $this->obj->var);
}
protected function tearDown()
{
}
}
?>
However, when I run ./vendor/bin/phpunit tests from the command-line, I get the following error:
PHP Fatal error: Class 'Returning' not found in
/files/code/php/db/tests/returningTest.php on line 8
I noticed that composer produced an autoload.php file in vendor/autoload.php but not sure if this is relevant for my problem.
Also, in some other answers on Stack Overflow people have mentioned something about using PSR-0 in composer and the namespace command in PHP, but I have not been successful in using either one.
Please help! I just want to autoload my classes in PHPUnit so I can just use them to create objects without worrying about include or require.
Update: 14th of August 2013
I have now created an Open Source project called PHPUnit Skeleton to help you get up and running with PHPUnit testing easily for your project.
Well, at first. You need to tell the autoloader where to find the php file for a class. That's done by following the PSR-0 standard.
The best way is to use namespaces. The autoloader searches for a Acme/Tests/ReturningTest.php file when you requested a Acme\Tests\ReturningTest class. There are some great namespace tutorials out there, just search and read. Please note that namespacing is not something that came into PHP for autoloading, it's something that can be used for autoloading.
Composer comes with a standard PSR-0 autoloader (the one in vendor/autoload.php). In your case you want to tell the autoloader to search for files in the lib directory. Then when you use ReturningTest it will look for /lib/ReturningTest.php.
Add this to your composer.json:
{
...
"autoload": {
"psr-0": { "": "lib/" }
}
}
More information in the documentation.
Now the autoloader can find your classes you need to let PHPunit know there is a file to execute before running the tests: a bootstrap file. You can use the --bootstrap option to specify where the bootstrap file is located:
$ ./vendor/bin/phpunit tests --bootstrap vendor/autoload.php
However, it's nicer to use a PHPunit configuration file:
<!-- /phpunit.xml.dist -->
<?xml version="1.0" encoding="utf-8" ?>
<phpunit bootstrap="./vendor/autoload.php">
<testsuites>
<testsuite name="The project's test suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
Now, you can run the command and it will automatically detect the configuration file:
$ ./vendor/bin/phpunit
If you put the configuration file into another directory, you need to put the path to that directory in the command with the -c option.
[Update2] Another simpler alternative approach is to use the autoload-dev directive in composer.json (reference). The benefit is that you don't need to maintain two bootstrap.php (one for prod, one for dev) just in order to autoload different classes.
{
"autoload": {
"psr-4": { "MyLibrary\\": "src/" }
},
"autoload-dev": {
"psr-4": { "MyLibrary\\Tests\\": "tests/" }
}
}
[Update] Wouter J's answer is more complete. But mine can help people who want to set up PSR-0 autoloading in tests/ folder.
Phpunit scans all files with this pattern *Test.php. So we don't need to autoload them ourselves. But we still want to autoload other supporting classes under tests/ such as fixture/stub or some parent classes.
An easy way is to look at how Composer project itself is setting up the phpunit test. It's actually very simple. Note the line with "bootstrap".
reference: https://github.com/composer/composer/blob/master/phpunit.xml.dist
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="Composer Test Suite">
<directory>./tests/Composer/</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>slow</group>
</exclude>
</groups>
<filter>
<whitelist>
<directory>./src/Composer/</directory>
<exclude>
<file>./src/Composer/Autoload/ClassLoader.php</file>
</exclude>
</whitelist>
</filter>
</phpunit>
reference: https://github.com/composer/composer/blob/master/tests/bootstrap.php
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman#naderman.de>
* Jordi Boggiano <j.boggiano#seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
error_reporting(E_ALL);
$loader = require __DIR__.'/../src/bootstrap.php';
$loader->add('Composer\Test', __DIR__);
The last line above is autoloading phpunit test classes under the namespace Composer\Test.
None of these answers were what I was looking for. Yes PHPUnit loads test files, but not stubs/fixtures. Chaun Ma's answer doesn't cut it because running vendor/bin/phpunit already includes the autoload, so there's no way to get an instance of the autoloader to push more paths to it's stack at that point.
I eventually found this in the docs:
If you need to search for a same prefix in multiple directories, you
can specify them as an array as such:
{
"autoload": {
"psr-0": { "Monolog\\": ["src/", "lib/"] }
}
}
There is a really simple way to set up phpunit with autoloading and bootstap. Use phpunit's --generate-configuration option to create your phpunit.xml configuration in a few seconds-:
vendor/bin/phpunit --generate-configuration
(Or just phpunit --generate-configuration if phpunit is set in your PATH). This option has been available from version phpunit5 and upwards.
This option will prompt you for your bootstrap file (vendor/autoload.php), tests and source directories. If your project is setup with composer defaults (see below directory structure) the default options will be all you need. Just hit RETURN three times!
project-dir
-- src
-- tests
-- vendor
You get a default phpunit.xml which is good to go. You can of course edit to include any specialisms (e.g. colors="true") you require-:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.1/phpunit.xsd"
bootstrap="vendor/autoload.php"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
If you are using PHPUnit 7 you can make your classes from src/ folder to autoload in tests like this:
Ensure that your composer.json file looks similar to this:
{
"autoload": {
"classmap": [
"src/"
]
},
"require-dev": {
"phpunit/phpunit": "^7"
}
}
To apply changes in composer.json run command:
composer install
Finally you can run tests in tests/ folder:
./vendor/bin/phpunit tests/
Trying to integrate PHPUnit and my IDE (PhpStorm 2017.2). I'm executing the phpunit.phar file directly (version 5.7.21) as I don't use Composer and don't have it installed.
phpunit.xml
<phpunit bootstrap="phpunit-bootstrap.php">
<testsuites>
<testsuite name="Test suite">
<directory>./</directory>
</testsuite>
</testsuites>
</phpunit>
phpunit-bootstrap.php
spl_autoload_register('my_autoload');
/**
* #param string $className Fully qualified name to autoload
*/
function my_autoload($className){
require $_SERVER['DOCUMENT_ROOT'] . "\\$className.php";
}
This autoloader works fine when I execute my project files. However when I try to run any PHPUnit test, I see this error:
Fatal error: require(): Failed opening required '\Composer\Autoload\ClassLoader.php'
If I remove the autoload, then my project classes can no longer be found (same error, different class name).
Does PHPUnit depend on Composer being installed globally and available on the system path?
Update 1
Following kuba's suggestion in comments, I changed the autoload to:
require __DIR__ . "\\$className.php";
New error:
Fatal error: require(): Failed opening required 'C:\project-root\Composer\Autoload\ClassLoader.php'
I needed to adjust my autoloader to do nothing when PHP tried to load Composer\Autoload\ClassLoader.php. So I changed my Autoloader from:
function my_autoload($className){
require __DIR__ . "\\$className.php";
}
to
function my_autoload($className){
$path = __DIR__ . "\\$className.php";
if (file_exists($path)) require $path;
}
I'm new in PHPUnit and unit-testing, so I was install PHPUnit and phar via composer and everything had been going fine until I was try to start my simple test. I'm using PhpStorm where I can see all classes were autoload, but when I trying to start my test I got an error:
Fatal error: Class 'PharIo\Manifest\Simple' not found in C:\xampp\htdocs\mydocs\
I don't understand why he is looking for It in folder upper than PHPUnit is exists ?
I was trying to configure autoload section in composer.json and checking settings in phpunit.xml but nothing works.
Add:
I have to reinstall PHPUnit without PharIO, so now I have a little bit of progress, now I have a situation where I can test my class if I make require_once line with a name of the tested class. It looks like:
require_once '../src/Simple.php';
class SimpleTest extends PHPUnit_Framework_TestCase
{
public function testAdd() {
$sum = new Simple();
$this->assertEquals(5, $sum->add(2, 3));
}
}
So my simple class is:
class Simple {
public function add($a, $b) {
return (int) $a + (int) $b;
}
}
But, of course, I want to use namespaces. I try to make some changes based on this question: Autoloading classes in PHPUnit using Composer and autoload.php (I was try even use that repo for test, but an error is still exists) but nothing works for me. I was try to edit my autoload section in the composer.json like this
"autoload": {
"psr-4": {
"app\\": "src/"
}
},
But an error is still exists, another words autoload cannot see It. I was create phpunit.xml and phpunit.dist.xml with a same settings
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/3.7/phpunit.xsd"
backupGlobals="true"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php">
<testsuites>
<testsuite name="The project's test suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
and I made tests/bootstrap.php too with
require_once '../vendor/autoload.php';
I know this is an old question, but maybe you need to do
composer dump-autoload for composer to generate the map of classes.
I wasted 30mins trying to understand why PHPUnit was giving me:
Cannot stub or mock class or interface XXX because it doesn't exists
You should specify the script with autoloading classes.
You can either specify the file with autoloading in XML-file, as suggested in the other answer, or just by specifying --bootstrap option in your command to run tests:
phpunit --bootstrap vendor/autoload.php tests
Composer's autoload relies on configuration located in the vendor/autoload.php file which needs to be loaded at some point in your execution thread. You application already includes this and that's why it works, but the tests use a different entry point so you need to configure it with a file called phpunit.xml.dist.
Assuming your file structure is something like:
app/
src/
tests/
bootstrap.php <- create it in your test folder
vendor/
...
composer.json
composer.lock
phpunit.xml.dist <- create it if does not exist
You can see the various options here, but for a basic config, you can use this.
File phpunit.xml.dist:
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/3.7/phpunit.xsd"
backupGlobals="true"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php">
</phpunit>
File tests/bootstrap.php:
require_once '../vendor/autoload.php';
You should run phpunit from the root.
I have a fairly simple problem that I cannot seem to figure out.
I am developing an OOP-based PHP application using the Composer Dependency Manager, PHPUnit for testing. I am hosting the repository on GitLab and am using GitLab-CI to run the PHPUnit tests.
My file directory is fairly simple:
├──_data
├──_2016
├──_federal
├──fit.json
├──_libs
├──_paycheckCalculator
├──paycheck.php
├──taxCalc.php
├──_public_html
├──index.php
├──_vendor
├──[composer dependencies]
├──autoload.php
├──_tests
├──paycheckTest.php
├──taxCalcTest.php
├──_templates
├──[Twig templates]
taxCalc.php contains:
public static function calcFIT($taxableWages, array $taxStatus, int $frequency = 52):float {
$fitFile = "../data/2016/federal/fit.json";
...
That works just fine on my production server and I can run the PHPunit tests just fine via PHPUnit integration with PhpStorm, but when I try to get GitLab-CI to work I consistently get an error:
...
$ vendor/bin/phpunit --configuration phpunit.xml PHPUnit 5.5.4 by
Sebastian Bergmann and contributors.
EE..EII 7
/ 7 (100%)
Time: 32 ms, Memory: 4.00MB
There were 3 errors:
1) paycheckTest::calcNetTest
file_get_contents(../data/2016/federal/fit.json): failed to open
stream: No such file or directory
/builds/calebrw/paycheckCalculator/libs/paycheckCalculator/taxCalc.php:100
/builds/calebrw/paycheckCalculator/libs/paycheckCalculator/paycheck.php:49
/builds/calebrw/paycheckCalculator/libs/paycheckCalculator/paycheck.php:28
/builds/calebrw/paycheckCalculator/tests/paycheckTest.php:34
2) paycheckTest::calcTaxesTest
file_get_contents(../data/2016/federal/fit.json): failed to open
stream: No such file or directory
/builds/calebrw/paycheckCalculator/libs/paycheckCalculator/taxCalc.php:100
/builds/calebrw/paycheckCalculator/tests/paycheckTest.php:58
3) taxCalcTest::calcFITTest
file_get_contents(../data/2016/federal/fit.json): failed to open
stream: No such file or directory
/builds/calebrw/paycheckCalculator/libs/paycheckCalculator/taxCalc.php:100
/builds/calebrw/paycheckCalculator/tests/taxCalcTest.php:53
ERRORS! Tests: 7, Assertions: 11, Errors: 3, Incomplete: 2. ERROR:
Build failed: exit code 1
My .gitlab_ci.yml is as follows:
# Select image from https://hub.docker.com/_/php/
image: php:7.0
# Select what we should cache
cache:
paths:
- vendor/
before_script:
# Install git, the php image doesn't have installed
- apt-get update -yqq
- apt-get install git -yqq
# Install composer
- curl -sS https://getcomposer.org/installer | php
# Install all project dependencies
- php composer.phar install
PHPUnit:testsuite:
script:
- vendor/bin/phpunit --configuration phpunit.xml
My phpunit.xml file contains:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<testsuites>
<testsuite name="Paycheck Tests">
<directory>tests/</directory>
</testsuite>
</testsuites>
<php>
<includePath>/builds/calebrw/paycheckCalculator</includePath>
</php>
</phpunit>
Please note that I've used this with or without the <includePath> tag and there is no difference if I use <includePath>/../</includePath> or anything else for that matter.
I appreciate any help you can give.
EDIT:
I finally got this to work. I added a function (in the global space for now) to my config.php file:
/**
* Required Functions
*/
function getDirectory(bool $html = false):string
{
$htmlBaseDirectory = '/webprojects/paycheckCalculator';
if ($html == true) {
return $htmlBaseDirectory;
} else {
return dirname(__DIR__);
}
}
That meant I could update my index.php:
require_once('config.php'); // Configuration Variables
require_once( getDirectory() . '/vendor/autoload.php'); // Composer Autoload
$dir = getDirectory(true) . $htmlPublicDirectory; // Combined variable needed for Twig compatibility
but I was still having problems with the GitLab-Ci runner having yet a completely different environment that doesn't call my config.php at all, so I added a fix (or hack really) to get the test to pass to taxCalc.php:
if (getenv('CI_BUILD_ID') !== false) {
define('MAIN_PATH', '/builds/calebrw/paycheckCalculator/');
} else {
define('MAIN_PATH', dirname(__DIR__));
}
...
class taxCalc
{
...
public static function calcFIT($taxableWages, array $taxStatus, int $frequency = 52):float {
$fitFile = MAIN_PATH . "/data/2016/federal/fit.json";
And now the build passes.
Thanks for all the help to both people who responded.
Make sure that the file is commited (usually you don't commit data you may place it under resources). I think you did already.
The second thing is also just a suggestion:
define a PATH constant and use this. Because in your case you never know where is your current working directory.
Define a bootstrap file in phpunit and define the MAIN_PATH. Example:
<?php
define('MAIN_PATH', dirname(__DIR__));
require MAIN_PATH . '/vendor/autoload.php';
In the index you have to provide this MAIN_PATH too and in calcFit you write:
<?php
function calcFit() {
$fitFile = MAIN_PATH . '/data/2016/federal/fit.json';
}
The issue is very probably that you are using a relative path in your require. See here for explanations and solutions : PHP - Failed to open stream : No such file or directory
I have little problem when I'm trying to run PHPUnit test in IDE PhpStorm.
I use composer file which looks:
{
"require": {
"phpunit/phpunit": "3.7.19"
}
}
Now when I run test I recive exception:
PHP Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Class "PHPUnit_Extensions_RepeatedTest" does not extend PHPUnit_Framework_TestCase.'
What is wrong? When I included pear installed version test working OK.
//EDIT
Sample test class:
class ReaderTest extends PHPUnit_Framework_TestCase
{
/**
* #test
*/
public function shouldGetReadedValue ()
{
$this->assertTrue(true);
}
}
//EDIT2
Trace:
/usr/bin/php /tmp/ide-phpunit.php --no-configuration /path/to/my/project
Testing started at 14:53 ...
PHP Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Class "PHPUnit_Extensions_RepeatedTest" does not extend PHPUnit_Framework_TestCase.' in /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php:183
Stack trace:
#0 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php(315): PHPUnit_Framework_TestSuite->__construct(Object(ReflectionClass))
#1 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php(389): PHPUnit_Framework_TestSuite->addTestSuite(Object(ReflectionClass))
#2 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php(416): PHPUnit_Framework_TestSuite->addTestFile('/var/www/php-sh...')
#3 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Runner/BaseTestRunner.php(96): PHPUnit_Framework_TestSuite->addTestFiles(Array)
#4 /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/TextUI/Command.php(150): PHPUnit_Runner_BaseTestRunner->getTest('/var/www/php-sh...', '', A in /path/to/my/project/vendor/phpunit/phpunit/PHPUnit/Framework/TestSuite.php on line 183
Process finished with exit code 255
I found solution about this problem.
In Edit configurations in directory I set path to my tests catalog (/path/to/my/project/tests), after this tests are running properly.
This is what worked for me, thanks to Piotr's answer above, but I'm providing with a bit more exact detail here all the steps I had to do:
Steps to make it work (test in PHPStorm 8.0.1):
1) In Preferences > PHP > PHPUnit make sure that nothing is set for Default configuration file or default bootstrap file.
2) Make a custom PHPUnit Configuration via Run > Edit Configurations > in the Command Line subsection, and be sure to:
a) set Custom working directory: to be /absolute/path/to/vendor.
b) check "Use alternative configuration file:" and set it to /absolute/path/to/vendor/your_app/(sub_app_if_applicable)/phpunit.xml.dist
Then you can run any test class in the suite by specifying the class and file, or just check "Defined in the configuration file" to run all of them according to the config.
I have same problem when using composer.
The solution is to put your test file in its own directory. Here is my working phpunit, i put all my test in test directory.
<phpunit bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="true">
<testsuites>
<testsuite name="Test Suite">
<directory>test</directory>
</testsuite>
</testsuites>
</phpunit>
Hope it solves if anyone have same problem.. :)
Inside the PHPUnit_Framework_TestSuite, this code exists in the constructor:
if (!$theClass->isSubclassOf('PHPUnit_Framework_TestCase')) {
throw new PHPUnit_Framework_Exception(
'Class "' . $theClass->name . '" does not extend PHPUnit_Framework_TestCase.'
);
}
I see in your example that you are extending PHPUnit_Framework_TestCase but the error suggests you are using PHPUnit_Extensions_RepeatedTest which extends PHPUnit_Extensions_TestDecorator which ultimately extends PHPUnit_Framework_Assert
PHPUnit_Framework_Assert
|
--PHPUnit_Extensions_TestDecorator
|
--PHPUnit_Extensions_RepeatedTest
Double check your tests because the error suggests you are attempting to run a TestSuite using a test extending PHPUnit_Extensions_RepeatedTest. Were you instead trying to extend PHUnit using Test Decorators?
http://docs.tadiavo.com/phpunit/www.phpunit.de/pocket_guide/3.1/en/extending-phpunit.html
That is all the advice I can currently offer without seeing your actual tests and how you are running them.