Load a fixture and its data

I’m trying to load a fixture and its data into my CakePHP Unit tests.

The fixture listener is set in phpunit.xml.dist.

There’s the fixture ‘AdminServiceFixture.php’ in the tests/Fixture folder with the content:

namespace App\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

class AdminServiceFixture extends TestFixture
    public $connection = 'test';

    public $fields = [
        'id' => ['type' => 'integer'],
        'user_id' => ['type' => 'integer'],
        'service_id' => ['type' => 'integer'],
        '_constraints' => [
            'primary' => ['type' => 'primary', 'columns' => ['id']]
    public $records = [
            'user_id' => 1,
            'service_id' => 2,

There’s the model test file ‘AdminServiceTableTest’ defined as:

namespace App\Test\TestCase\Model\Table;

use App\Model\Table\AdminServiceTable;
use Cake\TestSuite\TestCase;

class AdminServiceTableTest extends TestCase
    private $AdminService;
    protected $fixtures = ['app.AdminService'];

    function setUp(): void {
        $this->AdminService = new AdminServiceTable;

    function testGetAdminService() {

        $user_id = 1;

        $actual = $this->AdminService->getAdminService($user_id);

        $expected = 1;
        $this->assertEquals($expected, $actual);

But it doesn’t load and test against the fixture and its data, it’s still using the data in the Test database.

@thornstrom I am not an expert nor a big fan of fixtures. I can only recommend you to use test fixture factories. This does not answer your question, but might avoid lots of others in the future.