Skip to content

Commit

Permalink
Some tests where not actually running, specifically for the subquery
Browse files Browse the repository at this point in the history
strategry, making them run and fixing broken tests
  • Loading branch information
lorenzo committed Jun 11, 2013
1 parent 819643a commit e4fbba3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Database/Expression/Comparison.php
@@ -1,6 +1,6 @@
<?php
/**
*
*
* PHP Version 5.4
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
Expand Down
7 changes: 3 additions & 4 deletions lib/Cake/ORM/Association.php
Expand Up @@ -369,7 +369,7 @@ public function attachTo(Query $query, array $options = []) {
}

$joinOptions = ['table' => 1, 'conditions' => 1, 'type' => 1];
$query->join([$target->alias() => array_intersect_key($options, $joinOptions)]);
$query->join([$this->_name => array_intersect_key($options, $joinOptions)]);

if (empty($options['fields'])) {
$f = isset($options['fields']) ? $options['fields'] : null;
Expand All @@ -379,7 +379,7 @@ public function attachTo(Query $query, array $options = []) {
}

if (!empty($options['fields'])) {
$query->select($query->aliasFields($options['fields'], $target->alias()));
$query->select($query->aliasFields($options['fields'], $this->_name));
}
}

Expand All @@ -392,8 +392,7 @@ public function attachTo(Query $query, array $options = []) {
*/
public function transformRow($row) {
$sourceAlias = $this->source()->alias();
$targetAlias = $this->target()->alias();
$row[$sourceAlias][$this->property()] = $row[$targetAlias];
$row[$sourceAlias][$this->property()] = $row[$this->_name];
return $row;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/ORM/Association/BelongsTo.php
Expand Up @@ -61,7 +61,7 @@ public function foreignKey($key = null) {
*/
protected function _joinCondition(array $options) {
return sprintf('%s.%s = %s.%s',
$this->target()->alias(),
$this->_name,
$this->_targetTable->primaryKey(),
$this->_sourceTable->alias(),
$options['foreignKey']
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/ORM/Association/ExternalAssociationTrait.php
Expand Up @@ -238,6 +238,7 @@ protected function _buildSubquery($query, $foreignKey) {
unset($joins[$i]);
}
}

$filterQuery->join($joins, [], true);
return $filterQuery->select($foreignKey, true);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/Cake/ORM/Query.php
Expand Up @@ -412,8 +412,9 @@ protected function _transformQuery() {
if (!$this->_dirty) {
return parent::_transformQuery();
}

$this->from([$this->_table->alias() => $this->_table->table()]);
if (empty($this->_parts['from'])) {
$this->from([$this->_table->alias() => $this->_table->table()]);
}
$this->_addDefaultFields();
$this->_addContainments();
return parent::_transformQuery();
Expand Down
18 changes: 9 additions & 9 deletions lib/Cake/Test/TestCase/ORM/QueryTest.php
Expand Up @@ -76,19 +76,19 @@ public function tearDown() {
* @return void
*/
protected function _createTables() {
$table = 'CREATE TEMPORARY TABLE authors(id int, name varchar(50))';
$table = 'CREATE TABLE authors(id int, name varchar(50))';
$this->connection->execute($table);

$table = 'CREATE TEMPORARY TABLE articles(id int, title varchar(20), body varchar(50), author_id int)';
$table = 'CREATE TABLE articles(id int, title varchar(20), body varchar(50), author_id int)';
$this->connection->execute($table);

$table = 'CREATE TEMPORARY TABLE publications(id int, title varchar(20), body varchar(50), author_id int)';
$table = 'CREATE TABLE publications(id int, title varchar(20), body varchar(50), author_id int)';
$this->connection->execute($table);

$table = 'CREATE TEMPORARY TABLE tags(id int, name varchar(20))';
$table = 'CREATE TABLE tags(id int, name varchar(20))';
$this->connection->execute($table);

$table = 'CREATE TEMPORARY TABLE articles_tags(article_id int, tag_id int)';
$table = 'CREATE TABLE articles_tags(article_id int, tag_id int)';
$this->connection->execute($table);

Table::config('authors', ['connection' => $this->connection]);
Expand Down Expand Up @@ -362,7 +362,7 @@ public function testContainResultFetchingOneLevel() {
* @return void
*/
public function strategiesProvider() {
return [['subquery', 'select']];
return [['subquery'], ['select']];
}

/**
Expand Down Expand Up @@ -463,7 +463,7 @@ public function testHasManyEagerLoadingFields($strategy) {
* @dataProvider strategiesProvider
* @return void
**/
public function testHasManyEagerLoadingOrder() {
public function testHasManyEagerLoadingOrder($strategy) {
$statement = $this->_insertRecords();
$statement->bindValue(1, 3, 'integer');
$statement->bindValue(2, 'a fine title');
Expand Down Expand Up @@ -511,7 +511,7 @@ public function testHasManyEagerLoadingOrder() {
* @dataProvider strategiesProvider
* @return void
**/
public function testHasManyEagerLoadingDeep() {
public function testHasManyEagerLoadingDeep($strategy) {
$this->_insertRecords();

$query = new Query($this->connection);
Expand Down Expand Up @@ -558,7 +558,7 @@ public function testHasManyEagerLoadingDeep() {
* @dataProvider strategiesProvider
* @return void
**/
public function testHasManyEagerLoadingFromSecondaryTable() {
public function testHasManyEagerLoadingFromSecondaryTable($strategy) {
$this->_insertRecords();

$query = new Query($this->connection);
Expand Down

0 comments on commit e4fbba3

Please sign in to comment.