diff --git a/tests/Phinx/Migration/Manager/EnvironmentTest.php b/tests/Phinx/Migration/Manager/EnvironmentTest.php index 059fe423e..4ebeea88b 100644 --- a/tests/Phinx/Migration/Manager/EnvironmentTest.php +++ b/tests/Phinx/Migration/Manager/EnvironmentTest.php @@ -2,12 +2,12 @@ namespace Test\Phinx\Migration\Manager; +use PDO; use Phinx\Db\Adapter\AdapterFactory; use Phinx\Migration\Manager\Environment; use Phinx\Migration\MigrationInterface; use PHPUnit\Framework\TestCase; use RuntimeException; -use Test\Phinx\Migration\Manager\Mock\PDOMock; class EnvironmentTest extends TestCase { @@ -57,21 +57,36 @@ public function testNoAdapter() $this->environment->getAdapter(); } + private function getPdoMock() + { + $pdoMock = $this->getMockBuilder(PDO::class)->disableOriginalConstructor()->getMock(); + $attributes = []; + $pdoMock->method('setAttribute')->will($this->returnCallback(function ($attribute, $value) use (&$attributes) { + $attributes[$attribute] = $value; + + return true; + })); + $pdoMock->method('getAttribute')->will($this->returnCallback(function ($attribute) use (&$attributes) { + return $attributes[$attribute] ?? 'pdomock'; + })); + + return $pdoMock; + } + public function testGetAdapterWithExistingPdoInstance() { $adapter = $this->getMockForAbstractClass('\Phinx\Db\Adapter\PdoAdapter', [['foo' => 'bar']]); AdapterFactory::instance()->registerAdapter('pdomock', $adapter); - $this->environment->setOptions(['connection' => new PDOMock()]); + $this->environment->setOptions(['connection' => $this->getPdoMock()]); $options = $this->environment->getAdapter()->getOptions(); $this->assertEquals('pdomock', $options['adapter']); } public function testSetPdoAttributeToErrmodeException() { - $pdoMock = new PDOMock(); $adapter = $this->getMockForAbstractClass('\Phinx\Db\Adapter\PdoAdapter', [['foo' => 'bar']]); AdapterFactory::instance()->registerAdapter('pdomock', $adapter); - $this->environment->setOptions(['connection' => $pdoMock]); + $this->environment->setOptions(['connection' => $this->getPdoMock()]); $options = $this->environment->getAdapter()->getOptions(); $this->assertEquals(\PDO::ERRMODE_EXCEPTION, $options['connection']->getAttribute(\PDO::ATTR_ERRMODE)); } diff --git a/tests/Phinx/Migration/Manager/Mock/PDOMock.php b/tests/Phinx/Migration/Manager/Mock/PDOMock.php deleted file mode 100644 index 7b83e4481..000000000 --- a/tests/Phinx/Migration/Manager/Mock/PDOMock.php +++ /dev/null @@ -1,36 +0,0 @@ -attributes[$attribute] ?? 'pdomock'; - } - - /** - * @param int $attribute Attribute - * @param mixed $value Value - * @return bool - */ - public function setAttribute($attribute, $value) - { - $this->attributes[$attribute] = $value; - - return true; - } -}