From 9dd3b122d11b41e3c30d2d214c2ddc561dbd13b4 Mon Sep 17 00:00:00 2001 From: Oliver Nowak Date: Sat, 9 Sep 2017 16:22:39 +0200 Subject: [PATCH] Add tests for connection and table name configuration. (#1176) * Add tests for connection and table name configuration. Adds tests for #1173, #1171, #1167. * Avoid serialization error for PDO mocks. --- tests/Phinx/Db/Adapter/PdoAdapterTest.php | 33 ++++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tests/Phinx/Db/Adapter/PdoAdapterTest.php b/tests/Phinx/Db/Adapter/PdoAdapterTest.php index 012c62539..ab21d1751 100644 --- a/tests/Phinx/Db/Adapter/PdoAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PdoAdapterTest.php @@ -4,6 +4,13 @@ use Phinx\Db\Adapter\PdoAdapter; +class PdoAdapterTestPDOMock extends \PDO +{ + public function __construct() + { + } +} + class PdoAdapterTest extends \PHPUnit_Framework_TestCase { private $adapter; @@ -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')); @@ -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();