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));

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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