Skip to content

Provide Easy Mocking For Cake3 Table Classes #140

Description

@justinyost

Create a Trait that provide a getTableMock($tableName, $methodsToMock = []) method.

Maybe also create a class that extends IntegrationTestCase that pulls that trait in by default.

This is the basic flow to mock a Table Class for a Controller Structure.

$connection = \Cake\Datasource\ConnectionManager::get('test');
$config = ['connection' => $connection];

$UsersTable = $this->getMock(
    'App\Model\Table\UsersTable',
    ['save'],
    [$config]
);

$UsersTable->expects($this->once())
    ->method('save')
    ->will($this->returnValue(false));

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions