Open
Description
Description
At the present time there is a method
public function getMockForModel(string $alias, array $methods = [], array $options = [])
Too much boilerplate code, the method name is repeated, the alias is a magic string:
$mock = $this->getMockForModel('My', ['delete']);
$mock->expects($this->once())
->method('delete')
->willReturn(false);
I would suggest something like this:
public function mockTable(string $className, array $options = [])
so that it would be possible to simplify the mocking:
$mock = $this->mockTable(MyTable::class)
->method('save')
->willReturn(false);
and in case of multiple methods to be mocked:
$mock = $this->mockTable(MyTable::class);
$mock->method('save')->willReturn(false);
$mock->method('delete')->willReturn(false);
or
$mock = $this->mockTable(MyTable::class)
->method('save')
->willReturn(false)
->method('delete')
->willReturn(false);
or something similar but as simple as this.
If the alias or the table class name violates naming conventions:
$mock = $this->mockTable(MyTable::class, ['alias' => 'MyAlias'])
->method('save')
->willReturn(false);
CakePHP Version
No response