Settings up a fixture listener for PHP Unit tests in CakePHP 4.1

214 views Asked by At

I’m having trouble setting up the fixture listener for a CakePHP 4.1 project, using PHPUnit 9.4.

I’ve added the xml in phpunit.xml.dist:

<!-- Setup a listener for fixtures -->
<listeners>
    <listener class="Cake\TestSuite\Fixture\FixtureInjector">
        <arguments>
            <object class="Cake\TestSuite\Fixture\FixtureManager"/>
        </arguments>
    </listener>
</listeners>

My composer.json contains the following rows:

"autoload": {
    "psr-4": {
        "App\\": "src/"
    }
},
"autoload-dev": {
    "psr-4": {
        "App\\Test\\": "tests/",
        "Cake\\Test\\": "vendor/cakephp/cakephp/tests/"
    }
},

But when I run ‘phpunit.bat tests’ from the cli, it gives me the following error:

Class ‘Cake\TestSuite\Fixture\FixtureManager’ not found

Anyone knows why?

1

There are 1 answers

0
Anders Thörnström On

I solved it by executing the tests with the framework’s phpunit.bat, instead of the one from my local web server (xampp):

vendor/bin/phpunit.bat tests