Skip to content

Commit 61e838e

Browse files
committed
Merge pull request #384 from cakephp/fix-fixture-issue
Correctly set the connection when using fixtures.
2 parents 6381728 + f024a20 commit 61e838e

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

src/Model/Table/LazyTableTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function ensureTables(array $fixtures)
4545
if ($class === false) {
4646
throw new \RuntimeException("Unknown fixture '$name'.");
4747
}
48-
$fixture = new $class();
48+
$fixture = new $class($this->connection()->configName());
4949
$table = $fixture->table;
5050
if (in_array($table, $existing)) {
5151
continue;

tests/Fixture/PanelsFixture.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*/
2222
class PanelsFixture extends TestFixture
2323
{
24-
2524
/**
2625
* fields property
2726
*
@@ -61,4 +60,17 @@ class PanelsFixture extends TestFixture
6160
'content' => 'a:5:{s:6:"params";a:5:{s:6:"plugin";N;s:10:"controller";s:5:"Tasks";s:6:"action";s:3:"add";s:4:"_ext";N;s:4:"pass";a:0:{}}s:5:"query";a:0:{}s:4:"data";a:0:{}s:6:"cookie";a:2:{s:14:"toolbarDisplay";s:4:"show";s:7:"CAKEPHP";s:26:"9pk8sa2ot6pclki9f4iakio560";}s:3:"get";a:0:{}}'
6261
]
6362
];
63+
64+
/**
65+
* Constructor
66+
*
67+
* @param string $connection The connection name to use.
68+
*/
69+
public function __construct($connection = null)
70+
{
71+
if ($connection) {
72+
$this->connection = $connection;
73+
}
74+
$this->init();
75+
}
6476
}

tests/Fixture/RequestsFixture.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*/
2222
class RequestsFixture extends TestFixture
2323
{
24-
2524
/**
2625
* fields property
2726
*
@@ -53,4 +52,17 @@ class RequestsFixture extends TestFixture
5352
'requested_at' => '2014-08-21 7:41:12'
5453
]
5554
];
55+
56+
/**
57+
* Constructor
58+
*
59+
* @param string $connection The connection name to use.
60+
*/
61+
public function __construct($connection = null)
62+
{
63+
if ($connection) {
64+
$this->connection = $connection;
65+
}
66+
$this->init();
67+
}
5668
}

tests/TestCase/Model/Table/RequestTableTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ public function testInitializeCreatesSchema()
3333
{
3434
$connection = ConnectionManager::get('test');
3535
$this->skipIf($connection->driver() instanceof Sqlite, 'Schema insertion/removal breaks SQLite');
36-
3736
TableRegistry::clear();
38-
37+
3938
$stmt = $connection->execute('DROP TABLE IF EXISTS panels');
4039
$stmt->closeCursor();
4140

0 commit comments

Comments
 (0)