Skip to content

Commit

Permalink
Making first param for Table::find() optional
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Dec 20, 2013
1 parent 956f4cc commit a162606
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Cake/ORM/Association.php
Expand Up @@ -433,8 +433,9 @@ public function type() {
* and modifies the query accordingly based of this association
* configuration
*
* @param string $type
* @param array $options options for query
* @param string|array $type the type of query to perform, if an array is passed,
* it will be interpreted as the `$options` parameter
* @param array $options
* @see \Cake\ORM\Table::find()
* @return \Cake\ORM\Query
*/
Expand Down
42 changes: 42 additions & 0 deletions Cake/Test/TestCase/ORM/TableTest.php
Expand Up @@ -2941,4 +2941,46 @@ public function testReplacelinksBelongsToManyWithJoint() {
$this->assertEquals(3, $article->tags[1]->id);
}

/**
* Tests that it is possible to call find with no arguments
*
* @return void
*/
public function testSimplifiedFind() {
$table = $this->getMock(
'\Cake\ORM\Table',
['callFinder'],
[[
'connection' => $this->connection,
'schema' => ['id' => ['type' => 'integer']]
]]
);

$query = (new \Cake\ORM\Query($this->connection, $table))->select();
$table->expects($this->once())->method('callFinder')
->with('all', $query, []);
$table->find();
}

/**
* Tests that it is possible to pass the conditions as first argument in find
*
* @return void
*/
public function testFindFirstParamAsArray() {
$table = $this->getMock(
'\Cake\ORM\Table',
['callFinder'],
[[
'connection' => $this->connection,
'schema' => ['id' => ['type' => 'integer']]
]]
);

$query = (new \Cake\ORM\Query($this->connection, $table))->select(['id']);
$table->expects($this->once())->method('callFinder')
->with('all', $query, ['fields' => ['id']]);
$table->find(['fields' => ['id']]);
}

}

0 comments on commit a162606

Please sign in to comment.