From 1dbb6dd0e4a899071a1be114785ad8d68104af00 Mon Sep 17 00:00:00 2001 From: thomasv Date: Thu, 10 Sep 2015 00:25:39 +0200 Subject: [PATCH 1/4] Update DatabaseSession.php To prevent error: "Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous" when using a custom Session object in relationship with another object (belongsTo <-| hasMany) --- lib/Cake/Model/Datasource/Session/DatabaseSession.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/Session/DatabaseSession.php b/lib/Cake/Model/Datasource/Session/DatabaseSession.php index 08c398a7a..1076f829c 100644 --- a/lib/Cake/Model/Datasource/Session/DatabaseSession.php +++ b/lib/Cake/Model/Datasource/Session/DatabaseSession.php @@ -90,7 +90,7 @@ class DatabaseSession implements CakeSessionHandlerInterface { */ public function read($id) { $row = $this->_model->find('first', array( - 'conditions' => array($this->_model->primaryKey => $id) + 'conditions' => array($this->_model->alias . '.' . $this->_model->primaryKey => $id) )); if (empty($row[$this->_model->alias]['data'])) { From 81cbb52f74e9380f3b666c9bf609686b7ab23988 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Tue, 22 Sep 2015 13:04:28 +0200 Subject: [PATCH 2/4] Only array-wrap 'order' if it's not already an array. --- lib/Cake/Model/Model.php | 2 +- .../Test/Case/Controller/Component/PaginatorComponentTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 9ded1b59e..e0f64acab 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -3071,7 +3071,7 @@ class Model extends Object implements CakeEventListener { $query['order'] = $this->order; } - $query['order'] = array($query['order']); + $query['order'] = (array)$query['order']; if ($query['callbacks'] === true || $query['callbacks'] === 'before') { $event = new CakeEvent('Model.beforeFind', $this, array($query)); diff --git a/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php b/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php index 234d2dac3..a4113c102 100644 --- a/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php @@ -361,13 +361,13 @@ class PaginatorComponentTest extends CakeTestCase { $Controller->request->params['named'] = array('sort' => 'NotExisting.field', 'direction' => 'desc', 'limit' => 2); $Controller->Paginator->paginate('PaginatorControllerPost'); $this->assertEquals(1, $Controller->params['paging']['PaginatorControllerPost']['page']); - $this->assertEquals(array(), $Controller->PaginatorControllerPost->lastQueries[1]['order'][0], 'no order should be set.'); + $this->assertEquals(array(), $Controller->PaginatorControllerPost->lastQueries[1]['order'], 'no order should be set.'); $Controller->request->params['named'] = array( 'sort' => 'PaginatorControllerPost.author_id', 'direction' => 'allYourBase' ); $results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerPost'), '{n}.PaginatorControllerPost.id'); - $this->assertEquals(array('PaginatorControllerPost.author_id' => 'asc'), $Controller->PaginatorControllerPost->lastQueries[0]['order'][0]); + $this->assertEquals(array('PaginatorControllerPost.author_id' => 'asc'), $Controller->PaginatorControllerPost->lastQueries[0]['order']); $this->assertEquals(array(1, 3, 2), $results); $Controller->request->params['named'] = array(); From 8909b2ed42168dc6168bdee6828b3b3be89a0000 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Tue, 22 Sep 2015 14:21:04 +0200 Subject: [PATCH 3/4] Fix remaining test. --- lib/Cake/Test/Case/Model/ModelReadTest.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index 255371253..e592a42a3 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -6309,9 +6309,7 @@ class ModelReadTest extends BaseModelTest { 'joins' => array(), 'limit' => null, 'offset' => null, - 'order' => array( - 0 => null - ), + 'order' => array(), 'page' => 1, 'group' => null, 'callbacks' => true, @@ -8079,8 +8077,8 @@ class ModelReadTest extends BaseModelTest { /** * test after find callback on related model - * - * @return void + * + * @return void */ public function testRelatedAfterFindCallback() { $this->loadFixtures('Something', 'SomethingElse', 'JoinThing'); From 5b41a9b52da28ea53f3c72a781e3559c14a6c60f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=BCrth?= Date: Tue, 22 Sep 2015 13:35:42 +0200 Subject: [PATCH 4/4] Swallow the "--quiet" shell parameter before calling PHPUnit. PHPUnit does not provide a silent or quiet mode, so we cannot pass it along: https://phpunit.de/manual/3.7/en/phpunit-book.html#textui.clioptions Resolves #7432 --- lib/Cake/Console/Command/TestShell.php | 1 + .../Case/Console/Command/TestShellTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/Cake/Console/Command/TestShell.php b/lib/Cake/Console/Command/TestShell.php index 15012bfeb..7d17899a9 100644 --- a/lib/Cake/Console/Command/TestShell.php +++ b/lib/Cake/Console/Command/TestShell.php @@ -222,6 +222,7 @@ class TestShell extends Shell { $options = array(); $params = $this->params; unset($params['help']); + unset($params['quiet']); if (!empty($params['no-colors'])) { unset($params['no-colors'], $params['colors']); diff --git a/lib/Cake/Test/Case/Console/Command/TestShellTest.php b/lib/Cake/Test/Case/Console/Command/TestShellTest.php index 132f6ed1e..d3d379a1d 100644 --- a/lib/Cake/Test/Case/Console/Command/TestShellTest.php +++ b/lib/Cake/Test/Case/Console/Command/TestShellTest.php @@ -341,4 +341,22 @@ class TestShellTest extends CakeTestCase { ); $this->Shell->main(); } + +/** + * Tests that the 'quiet' parameter gets swallowed before calling PHPUnit + * + * @return void + */ + public function testRunnerOptionsQuiet() { + $this->Shell->startup(); + $this->Shell->args = array('core', 'Basics'); + $this->Shell->params = array('quiet' => true); + + $this->Shell->expects($this->once())->method('_run') + ->with( + array('app' => false, 'plugin' => null, 'core' => true, 'output' => 'text', 'case' => 'Basics'), + array('--colors') + ); + $this->Shell->main(); + } }