Skip to content

Commit

Permalink
Add tests for connection and table name configuration. (#1176)
Browse files Browse the repository at this point in the history
* Add tests for connection and table name configuration.

Adds tests for #1173, #1171, #1167.

* Avoid serialization error for PDO mocks.
  • Loading branch information
ndm2 authored and lorenzo committed Sep 9, 2017
1 parent 9514ebf commit 9dd3b12
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions tests/Phinx/Db/Adapter/PdoAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

use Phinx\Db\Adapter\PdoAdapter;

class PdoAdapterTestPDOMock extends \PDO
{
public function __construct()
{
}
}

class PdoAdapterTest extends \PHPUnit_Framework_TestCase
{
private $adapter;
Expand All @@ -25,18 +32,36 @@ public function testOptions()
$this->assertEquals('bar', $options['foo']);
}

public function testOptionsSetConnection()
{
$this->assertNull($this->adapter->getConnection());

$connection = new PdoAdapterTestPDOMock();
$this->adapter->setOptions(['connection' => $connection]);

$this->assertSame($connection, $this->adapter->getConnection());
}

public function testOptionsSetSchemaTableName()
{
$this->assertEquals('phinxlog', $this->adapter->getSchemaTableName());
$this->adapter->setOptions(['default_migration_table' => 'schema_table_test']);
$this->assertEquals('schema_table_test', $this->adapter->getSchemaTableName());
}

public function testSchemaTableName()
{
$this->assertEquals('phinxlog', $this->adapter->getSchemaTableName());
$this->adapter->setSchemaTableName('schema_table_test');
$this->assertEquals('schema_table_test', $this->adapter->getSchemaTableName());
}

/**
* @dataProvider getVersionLogDataProvider
*/
public function testGetVersionLog($versionOrder, $expectedOrderBy)
{
$adapter = $this->getMockForAbstractClass('\Phinx\Db\Adapter\PdoAdapter',
$adapter = $this->getMockForAbstractClass('\Phinx\Db\Adapter\PdoAdapter',
array(array('version_order' => $versionOrder)), '', true, true, true,
array('fetchAll', 'getSchemaTableName'));

Expand Down Expand Up @@ -87,14 +112,14 @@ public function getVersionLogDataProvider()
),
);
}

/**
* @expectedException RuntimeException
* @expectedExceptionMessage Invalid version_order configuration option
*/
public function testGetVersionLogInvalidVersionOrderKO()
{
$adapter = $this->getMockForAbstractClass('\Phinx\Db\Adapter\PdoAdapter',
$adapter = $this->getMockForAbstractClass('\Phinx\Db\Adapter\PdoAdapter',
array(array('version_order' => 'invalid')));

$adapter->getVersionLog();
Expand Down

0 comments on commit 9dd3b12

Please sign in to comment.