Must implement interface PHPUnit_Framework_Test
codeasashu opened this issue · 3 comments
composer.json
{
"description": "The CodeIgniter framework",
"name": "codeigniter/framework",
"type": "project",
"homepage": "https://codeigniter.com",
"license": "MIT",
"require": {
"php": ">=5.3",
},
"require-dev": {
"mikey179/vfsstream": "1.1.*",
"phpunit/phpunit": "^9.3"
}
}
I've installed this project using zip method. Now, whenever I try to run:
vendor/bin/phpunit -c application/tests/phpunit.xml application/tests/controllers/Example_test.php
it results in following error:
An uncaught Exception was encountered
Type: PHPUnit\TextUI\RuntimeException
Message: Argument 1 passed to PHPUnit_Framework_TestSuite::addTest() must implement interface PHPUnit_Framework_Test, instance of Example_Test given, called in /Users/ashutoshchaudhary/code/test/application/vendor/phpunit/phpunit/src/Framework/TestSuite.php on line 564
Filename: /Users/ashutoshchaudhary/code/test/vendor/phpunit/phpunit/src/TextUI/Command.php
Line Number: 98
Backtrace:
File: /Users/ashutoshchaudhary/code/test/vendor/phpunit/phpunit/phpunit
Line: 76
Function: main
When I remove the configuration, it works but then I can not use resetInstances
method. For example:
vendor/bin/phpunit application/tests/controllers/Example_test.php
Results in following:
PHPUnit 9.5.6 by Sebastian Bergmann and contributors.
E 1 / 1 (100%)
Time: 00:00.025, Memory: 4.00 MB
There was 1 error:
1) Example_Test::testExample
Error: Call to undefined method Example_Test::resetInstance()
/Users/ashutoshchaudhary/code/test/application/tests/controllers/Example_test.php:9
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
It seems it is a problem in Example_test.php
, not in ci-phpunit-test.
Can you show it?
If you remove configuration, ci-phpunit-test does not work correctly.
As it turns out, I had two composer.json installed, one in <project root>/vendor
and the other in <project root>/application/vendor
.
I had composer_autoload=true
set in config, which was autoloading application/vendor
, while I was using PHPUnit from root vendor location.
Setting composer_autoload=false
fixed the issue for me
Good to hear it.
If you want to autoload composer packages in <project root>/vendor
:
$config['composer_autoload'] = realpath(APPPATH . '../vendor/autoload.php');