lchrusciel / ApiTestCase

Handy PHPUnit test case for testing JSON APIs in your Symfony applications.
MIT License
410 stars 35 forks source link

Bug in ApiTestCase __construct() function #153

Closed imbpp123 closed 5 years ago

imbpp123 commented 5 years ago

I use PHPUnit 8.2, Symfony 4.2 and i have following problem.

[docker-compose://[/home/nikolay/PhpstormProjects/klubok/docker-compose.yml]:php/]:php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=172.17.0.1 /srv/api/vendor/phpunit/phpunit/phpunit --configuration /srv/api/phpunit.xml.dist --filter "/(::testUsersRegisterValidation)( .*)?$/" App\Tests\Functional\Users\RegisterTest /srv/api/tests/functional/Users/RegisterTest.php --teamcity
PHP Fatal error:  Uncaught TypeError: Argument 3 passed to ApiTestCase\ApiTestCase::__construct() must be of the type string, int given, called in /srv/api/vendor/phpunit/phpunit/src/Framework/TestBuilder.php on line 160 and defined in /srv/api/vendor/lchrusciel/api-test-case/src/ApiTestCase.php:67
Stack trace:
#0 /srv/api/vendor/phpunit/phpunit/src/Framework/TestBuilder.php(160): ApiTestCase\ApiTestCase->__construct('testUsersRegist...', Array, 0)
#1 /srv/api/vendor/phpunit/phpunit/src/Framework/TestBuilder.php(96): PHPUnit\Framework\TestBuilder->buildDataProviderTestSuite('testUsersRegist...', 'App\\Tests\\Funct...', Array, false, NULL, false, Array)
#2 /srv/api/vendor/phpunit/phpunit/src/Framework/TestSuite.php(732): PHPUnit\Framework\TestBuilder->build(Object(ReflectionClass), 'testUsersRegist...')
#3 /srv/api/vendor/phpunit/phpunit/src/Framework/TestSuite.php(194): PHPUnit\Framework\TestSuite->addTestMethod(Object(ReflectionClass), Object(ReflectionMethod))
#4 /srv/api/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php( in /srv/api/vendor/lchrusciel/api-test-case/src/ApiTestCase.php on line 67

Fatal error: Uncaught TypeError: Argument 3 passed to ApiTestCase\ApiTestCase::__construct() must be of the type string, int given, called in /srv/api/vendor/phpunit/phpunit/src/Framework/TestBuilder.php on line 160 and defined in /srv/api/vendor/lchrusciel/api-test-case/src/ApiTestCase.php on line 67

TypeError: Argument 3 passed to ApiTestCase\ApiTestCase::__construct() must be of the type string, int given, called in /srv/api/vendor/phpunit/phpunit/src/Framework/TestBuilder.php on line 160 in /srv/api/vendor/lchrusciel/api-test-case/src/ApiTestCase.php on line 67

Call Stack:
    0.0523     399432   1. {main}() /srv/api/vendor/phpunit/phpunit/phpunit:0
    0.0605    1206136   2. PHPUnit\TextUI\Command::main(???) /srv/api/vendor/phpunit/phpunit/phpunit:61
    0.0605    1206248   3. PHPUnit\TextUI\Command->run(???, ???) /srv/api/vendor/phpunit/phpunit/src/TextUI/Command.php:160
    0.0834    2118304   4. PHPUnit\TextUI\TestRunner->getTest(???, ???, ???) /srv/api/vendor/phpunit/phpunit/src/TextUI/Command.php:178
    0.0901    3300032   5. PHPUnit\Framework\TestSuite->__construct(???, ???) /srv/api/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php:124
    0.0902    3382184   6. PHPUnit\Framework\TestSuite->addTestMethod(???, ???) /srv/api/vendor/phpunit/phpunit/src/Framework/TestSuite.php:194
    0.0916    3748632   7. PHPUnit\Framework\TestBuilder->build(???, ???) /srv/api/vendor/phpunit/phpunit/src/Framework/TestSuite.php:732
    3.6729    3775632   8. PHPUnit\Framework\TestBuilder->buildDataProviderTestSuite(???, ???, ???, ???, ???, ???, ???) /srv/api/vendor/phpunit/phpunit/src/Framework/TestBuilder.php:96
    4.9519    3794704   9. App\Tests\Functional\Users\RegisterTest->__construct(???, ???, ???) /srv/api/vendor/phpunit/phpunit/src/Framework/TestBuilder.php:160

Process finished with exit code 255

Problem is in following:

abstract class ApiTestCase extends WebTestCase
{
    public function __construct(?string $name = null, array $data = [], string $dataName = '')
    {
        parent::__construct($name, $data, $dataName);

        $this->matcherFactory = new MatcherFactory();
    }
}

But please take a look at WebTestCase __construct

abstract class TestCase extends Assert implements SelfDescribing, Test
{
    public function __construct($name = null, array $data = [], $dataName = '')
    {
        // ...
    }
}

Check 3d parameter type. It is different. Unfortunatelly, i dont have time to fix it and create PR.