Skip to content

Commit

Permalink
Test for custom finder in Table::get().
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpustulka committed Jul 21, 2015
1 parent 0e24f36 commit 5468cdc
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -3822,6 +3822,58 @@ public function testGet($options)
$this->assertSame($entity, $result);
}

public function providerForTestGetWithCustomFinder()
{
return [
[ ['fields' => ['id'], 'finderName' => 'custom'] ]
];
}

/**
* Test that get() will call a custom finder.
*
* @dataProvider providerForTestGetWithCustomFinder
* @param array $options
* @return void
*/
public function testGetWithCustomFinder($options)
{
$table = $this->getMock(
'\Cake\ORM\Table',
['callFinder', 'query'],
[[
'connection' => $this->connection,
'schema' => [
'id' => ['type' => 'integer'],
'bar' => ['type' => 'integer'],
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['bar']]]
]
]]
);

$query = $this->getMock(
'\Cake\ORM\Query',
['addDefaultTypes', 'firstOrFail', 'where', 'cache'],
[$this->connection, $table]
);

$entity = new \Cake\ORM\Entity;
$table->expects($this->once())->method('query')
->will($this->returnValue($query));
$table->expects($this->once())->method('callFinder')
->with('custom', $query, ['fields' => ['id']])
->will($this->returnValue($query));

$query->expects($this->once())->method('where')
->with([$table->alias() . '.bar' => 10])
->will($this->returnSelf());
$query->expects($this->never())->method('cache');
$query->expects($this->once())->method('firstOrFail')
->will($this->returnValue($entity));
$result = $table->get(10, $options);
$this->assertSame($entity, $result);
}

public function providerForTestGetWithCache()
{
return [
Expand Down

0 comments on commit 5468cdc

Please sign in to comment.