Skip to content
Permalink
Browse files

Make Query take required arguments in its constructor.

Calling the repository() method was not optional. Since the dependency
is required it makes the most sense as a constructor argument.
  • Loading branch information...
markstory committed Aug 5, 2013
1 parent c6a5ab0 commit 34425c6358e2453fcebd5abf2de3b1dcd995d4a9
@@ -90,6 +90,15 @@ class Query extends DatabaseQuery {
*/
protected $_results;
/**
* @param Cake\Database\Connection $connection
* @param Cake\ORM\Table $table
*/
public function __construct($connection, $table) {
$this->connection($connection);
$this->repository($table);
}
/**
* Returns the default table object that will be used by this query,
* that is, the table that will appear in the from clause.
@@ -523,8 +523,7 @@ public function findAll(Query $query, array $options = []) {
* @return \Cake\ORM\Query
*/
protected function _buildQuery() {
$query = new Query($this->connection());
return $query->repository($this);
return new Query($this->connection(), $this);
}
/**
@@ -157,7 +157,7 @@ public function testPivotWithDefaultTableName() {
* @return void
*/
public function testAttachTo() {
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null]);
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null, null]);
$config = [
'sourceTable' => $this->article,
'targetTable' => $this->tag,
@@ -207,7 +207,7 @@ public function testAttachTo() {
* @return void
*/
public function testAttachToNoFields() {
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null]);
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null, null]);
$config = [
'sourceTable' => $this->article,
'targetTable' => $this->tag,
@@ -263,7 +263,7 @@ public function testEagerLoader() {
]);
$association = new BelongsToMany('Tag', $config);
$keys = [1, 2, 3, 4];
$query = $this->getMock('Cake\ORM\Query', ['execute', 'contain'], [null]);
$query = $this->getMock('Cake\ORM\Query', ['execute', 'contain'], [null, null]);
$this->tag->expects($this->once())->method('find')->with('all')
->will($this->returnValue($query));
$results = [
@@ -320,7 +320,7 @@ public function testEagerLoaderWithDefaults() {
$association = new BelongsToMany('Tag', $config);
$keys = [1, 2, 3, 4];
$methods = ['execute', 'contain', 'where', 'order'];
$query = $this->getMock('Cake\ORM\Query', $methods, [null]);
$query = $this->getMock('Cake\ORM\Query', $methods, [null, null]);
$this->tag->expects($this->once())->method('find')->with('all')
->will($this->returnValue($query));
$results = [
@@ -372,7 +372,7 @@ public function testEagerLoaderWithOverrides() {
$association = new BelongsToMany('Tag', $config);
$keys = [1, 2, 3, 4];
$methods = ['execute', 'contain', 'where', 'order', 'select'];
$query = $this->getMock('Cake\ORM\Query', $methods, [null]);
$query = $this->getMock('Cake\ORM\Query', $methods, [null, null]);
$this->tag->expects($this->once())->method('find')->with('all')
->will($this->returnValue($query));
$results = [
@@ -441,7 +441,7 @@ public function testEagerLoaderFieldsException() {
$association = new BelongsToMany('Tag', $config);
$keys = [1, 2, 3, 4];
$methods = ['execute', 'contain', 'where', 'order', 'select'];
$query = $this->getMock('Cake\ORM\Query', $methods, [null]);
$query = $this->getMock('Cake\ORM\Query', $methods, [null, null]);
$this->tag->expects($this->once())->method('find')->with('all')
->will($this->returnValue($query));
$query->expects($this->any())->method('contain')->will($this->returnSelf());
@@ -474,14 +474,14 @@ public function testEagerLoaderSubquery() {
]
]);
$association = new BelongsToMany('Tag', $config);
$parent = (new Query(null))
$parent = (new Query(null, null))
->join(['foo' => ['table' => 'foo', 'type' => 'inner', 'conditions' => []]])
->join(['bar' => ['table' => 'bar', 'type' => 'left', 'conditions' => []]]);
$query = $this->getMock(
'Cake\ORM\Query',
['execute', 'where', 'andWhere', 'order', 'select', 'contain'],
[null]
[null, null]
);
$this->tag->expects($this->once())->method('find')->with('all')
@@ -75,7 +75,7 @@ public function testCanBeJoined() {
* @return void
*/
public function testAttachTo() {
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null]);
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null, null]);
$config = [
'foreignKey' => 'company_id',
'sourceTable' => $this->client,
@@ -106,7 +106,7 @@ public function testAttachTo() {
* @return void
*/
public function testAttachToConfigOverride() {
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null]);
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null, null]);
$config = [
'foreignKey' => 'company_id',
'sourceTable' => $this->client,
@@ -140,7 +140,7 @@ public function testAttachToConfigOverride() {
* @return void
*/
public function testAttachToNoFields() {
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null]);
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null, null]);
$config = [
'sourceTable' => $this->client,
'targetTable' => $this->company,
@@ -108,7 +108,7 @@ public function testEagerLoader() {
];
$association = new HasMany('Article', $config);
$keys = [1, 2, 3, 4];
$query = $this->getMock('Cake\ORM\Query', ['execute'], [null]);
$query = $this->getMock('Cake\ORM\Query', ['execute'], [null, null]);
$this->article->expects($this->once())->method('find')->with('all')
->will($this->returnValue($query));
$results = [
@@ -152,7 +152,7 @@ public function testEagerLoaderWithDefaults() {
$query = $this->getMock(
'Cake\ORM\Query',
['execute', 'where', 'andWhere', 'order'],
[null]
[null, null]
);
$this->article->expects($this->once())->method('find')->with('all')
->will($this->returnValue($query));
@@ -197,7 +197,7 @@ public function testEagerLoaderWithOverrides() {
$query = $this->getMock(
'Cake\ORM\Query',
['execute', 'where', 'andWhere', 'order', 'select', 'contain'],
[null]
[null, null]
);
$this->article->expects($this->once())->method('find')->with('all')
->will($this->returnValue($query));
@@ -262,7 +262,7 @@ public function testEagerLoaderFieldsException() {
$query = $this->getMock(
'Cake\ORM\Query',
['execute'],
[null]
[null, null]
);
$this->article->expects($this->once())->method('find')->with('all')
->will($this->returnValue($query));
@@ -281,14 +281,14 @@ public function testEagerLoaderSubquery() {
'targetTable' => $this->article,
];
$association = new HasMany('Article', $config);
$parent = (new Query(null))
$parent = (new Query(null, null))
->join(['foo' => ['table' => 'foo', 'type' => 'inner', 'conditions' => []]])
->join(['bar' => ['table' => 'bar', 'type' => 'left', 'conditions' => []]]);
$query = $this->getMock(
'Cake\ORM\Query',
['execute', 'where', 'andWhere', 'order', 'select', 'contain'],
[null]
[null, null]
);
$this->article->expects($this->once())->method('find')->with('all')
@@ -340,7 +340,7 @@ public function testEagerLoaderSubquery() {
* @return void
*/
public function testAttachTo() {
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null]);
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null, null]);
$config = [
'sourceTable' => $this->author,
'targetTable' => $this->article,
@@ -371,7 +371,7 @@ public function testAttachTo() {
* @return void
*/
public function testAttachToConfigOverride() {
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null]);
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null, null]);
$config = [
'sourceTable' => $this->author,
'targetTable' => $this->article,
@@ -405,7 +405,7 @@ public function testAttachToConfigOverride() {
* @return void
*/
public function testAttachToNoFields() {
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null]);
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null, null]);
$config = [
'sourceTable' => $this->author,
'targetTable' => $this->article,
@@ -75,7 +75,7 @@ public function testCanBeJoined() {
* @return void
*/
public function testAttachTo() {
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null]);
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null, null]);
$config = [
'foreignKey' => 'user_id',
'sourceTable' => $this->user,
@@ -107,7 +107,7 @@ public function testAttachTo() {
* @return void
*/
public function testAttachToConfigOverride() {
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null]);
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null, null]);
$config = [
'foreignKey' => 'user_id',
'sourceTable' => $this->user,
@@ -142,7 +142,7 @@ public function testAttachToConfigOverride() {
* @return void
*/
public function testAttachToNoFields() {
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null]);
$query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null, null]);
$config = [
'sourceTable' => $this->user,
'targetTable' => $this->profile,
Oops, something went wrong.

0 comments on commit 34425c6

Please sign in to comment.
You can’t perform that action at this time.