Skip to content

Commit

Permalink
bugfix: could not set different table name, subclasses had table name…
Browse files Browse the repository at this point in the history
… hard coded
  • Loading branch information
frederikbosch committed Dec 15, 2014
1 parent 3ee7c95 commit 8e8edd7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
10 changes: 9 additions & 1 deletion src/Adapters/AbstractPdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class AbstractPdoAdapter implements AdapterInterface
/**
* @var string
*/
private $table = 'migrations';
protected $table = 'migrations';

/**
* @param PDO $pdo
Expand All @@ -30,6 +30,14 @@ public function __construct(PDO $pdo)
$this->pdo = $pdo;
}

/**
* @param $tableName
*/
public function setTableName ($tableName)
{
$this->table = $tableName;
}

/**
* @return void
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Adapters/PdoMysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ protected function createTableIfNotExists()
{
$this->getPdo()->exec(

'CREATE TABLE IF NOT EXISTS `migrations` (
"CREATE TABLE IF NOT EXISTS `{$this->table}` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`migration` VARCHAR(255) NOT NULL,
`direction` TINYINT(1) UNSIGNED NOT NULL,
`migrated_on` DATETIME NOT NULL,
PRIMARY KEY (`id`))'
PRIMARY KEY (`id`))"

);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Adapters/PdoSqliteAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PdoSqliteAdapter extends AbstractPdoAdapter
protected function createTableIfNotExists()
{
$this->getPdo()->exec(
'CREATE TABLE IF NOT EXISTS migrations(id INTEGER PRIMARY KEY ASC, name TEXT, migration TEXT, direction INTEGER, migrated_on TEXT)'
"CREATE TABLE IF NOT EXISTS {$this->table} (id INTEGER PRIMARY KEY ASC, name TEXT, migration TEXT, direction INTEGER, migrated_on TEXT)"
);
}
}
22 changes: 18 additions & 4 deletions tests/Integration/MigrateTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php
namespace Genkgo\Migrations\Integration;

use InvalidArgumentException;
use PDO;
use InvalidArgumentException;
use Genkgo\Migrations\Adapters\PdoSqliteAdapter;
use Genkgo\Migrations\Utils\FileList;
use Genkgo\Migrations\AbstractTestCase;
use Genkgo\Migrations\Factory;
use Genkgo\Migrations\MigrationInterface;
Expand All @@ -16,7 +15,7 @@
class MigrateTest extends AbstractTestCase
{
/**
* @var AdapterInterface
* @var PdoSqliteAdapter
*/
private $adapter;

Expand Down Expand Up @@ -112,7 +111,7 @@ public function testNamespace()
$this->assertEquals(1, $this->adapter->getNumberOfMigrations());

$this->setExpectedException(InvalidArgumentException::class);
$list = $this->factory->newListFromDirectory(__DIR__.'/namespaced', 'namespaced');
$this->factory->newListFromDirectory(__DIR__.'/namespaced', 'namespaced');
}

/**
Expand All @@ -133,4 +132,19 @@ public function testCallback()

$this->assertCount(1, $result);
}

/**
*
*/
public function testDifferentTableName ()
{
$this->adapter->setTableName('other_table_name');

$list = $this->factory->newListFromDirectory(__DIR__.'/migrations');
$this->assertCount(2, $list);

$result = $list->migrate();
$this->assertCount(2, $result);
$this->assertEquals(2, $this->adapter->getNumberOfMigrations());
}
}
13 changes: 11 additions & 2 deletions tests/Unit/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,29 @@ class CollectionTest extends AbstractTestCase
* @var Collection
*/
private $collection;


/**
*
*/
protected function setUp()
{
$this->collection = new Collection(
new PdoSqliteAdapter(new PDO('sqlite::memory:'))
);
}


/**
*
*/
public function testAttach()
{
$this->collection->attach(new TestMigration());
$this->assertCount(1, $this->collection);
}

/**
*
*/
public function testDetach()
{
$script = new TestMigration();
Expand Down

0 comments on commit 8e8edd7

Please sign in to comment.