Skip to content

Commit

Permalink
The create() and drop() methods should be no-op
Browse files Browse the repository at this point in the history
Since the user is using an existing table, we should not make any asumption and consider that the table should not be created nor dropped by the TestSuite
  • Loading branch information
HavokInspiration committed Feb 3, 2016
1 parent b81f889 commit f40dd42
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/TestSuite/Fixture/TestFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ protected function _schemaFromReflection()
);
}

$this->_schema = $schema = $db->schemaCollection()->describe($this->table);
$this->_schema = $schemaCollection->describe($this->table);
}

/**
Expand All @@ -271,6 +271,10 @@ public function create(ConnectionInterface $db)
return false;
}

if (empty($this->import) && empty($this->fields)) {
return true;
}

try {
$queries = $this->_schema->createSql($db);
foreach ($queries as $query) {
Expand Down Expand Up @@ -299,6 +303,11 @@ public function drop(ConnectionInterface $db)
if (empty($this->_schema)) {
return false;
}

if (empty($this->import) && empty($this->fields)) {
return true;
}

try {
$sql = $this->_schema->dropSql($db);
foreach ($sql as $stmt) {
Expand Down
13 changes: 10 additions & 3 deletions tests/TestCase/TestSuite/TestFixtureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public function testInitNoImportNoFieldsException()

/**
* test schema reflection without $import or $fields will reflect the schema
*.
*
* @return void
*/
public function testInitNoImportNoFields()
Expand All @@ -285,7 +285,7 @@ public function testInitNoImportNoFields()
if (!in_array('letters', $collection->listTables())) {
$table = new Table('letters', [
'id' => ['type' => 'integer'],
'letters' => ['type' => 'integer', 'null' => true]
'letter' => ['type' => 'string', 'length' => 1]
]);
$table->addConstraint('primary', ['type' => 'primary', 'columns' => ['id']]);
$sql = $table->createSql($db);
Expand All @@ -297,8 +297,15 @@ public function testInitNoImportNoFields()

$fixture = new LettersFixture();
$fixture->init();
$this->assertEquals(['id', 'letter'], $fixture->schema()->columns());

$this->assertEquals(['id', 'letters'], $fixture->schema()->columns());
$db = $this->getMock('Cake\Database\Connection', ['prepare', 'execute'], [], '', false);
$db->expects($this->never())
->method('prepare');
$db->expects($this->never())
->method('execute');
$this->assertTrue($fixture->create($db));
$this->assertTrue($fixture->drop($db));
}

/**
Expand Down

0 comments on commit f40dd42

Please sign in to comment.