diff --git a/tests/Phinx/Db/Adapter/PdoAdapterTest.php b/tests/Phinx/Db/Adapter/PdoAdapterTest.php index fad2b1d07..623201b04 100644 --- a/tests/Phinx/Db/Adapter/PdoAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PdoAdapterTest.php @@ -2,11 +2,10 @@ namespace Test\Phinx\Db\Adapter; +use PDO; use PDOException; use PHPUnit\Framework\TestCase; use RuntimeException; -use Test\Phinx\Db\Mock\PdoAdapterTestPDOMock; -use Test\Phinx\Db\Mock\PdoAdapterTestPDOMockWithExecChecks; class PdoAdapterTest extends TestCase { @@ -34,7 +33,7 @@ public function testOptions() public function testOptionsSetConnection() { - $connection = new PdoAdapterTestPDOMock(); + $connection = $this->getMockBuilder(PDO::class)->disableOriginalConstructor()->getMock(); $this->adapter->setOptions(['connection' => $connection]); $this->assertSame($connection, $this->adapter->getConnection()); @@ -181,23 +180,21 @@ public function testGetVersionLongDryRun() */ public function testExecuteCanBeCalled() { - $pdo = new PdoAdapterTestPDOMockWithExecChecks(); + /** @var \PDO&\PHPUnit\Framework\MockObject\MockObject $pdo */ + $pdo = $this->getMockBuilder(PDO::class)->disableOriginalConstructor()->onlyMethods(['exec'])->getMock(); + $pdo->expects($this->once())->method('exec')->with('SELECT 1;')->will($this->returnValue(1)); $this->adapter->setConnection($pdo); - $this->adapter->execute('SELECT 1'); - - $this->assertSame('SELECT 1;', $pdo->getExecutedSqlForTest()); } public function testExecuteRightTrimsSemiColons() { - $pdo = new PdoAdapterTestPDOMockWithExecChecks(); + /** @var \PDO&\PHPUnit\Framework\MockObject\MockObject $pdo */ + $pdo = $this->getMockBuilder(PDO::class)->disableOriginalConstructor()->onlyMethods(['exec'])->getMock(); + $pdo->expects($this->once())->method('exec')->with('SELECT 1;')->will($this->returnValue(1)); $this->adapter->setConnection($pdo); - $this->adapter->execute('SELECT 1;;'); - - $this->assertSame('SELECT 1;', $pdo->getExecutedSqlForTest()); } } diff --git a/tests/Phinx/Db/Mock/PdoAdapterTestPDOMock.php b/tests/Phinx/Db/Mock/PdoAdapterTestPDOMock.php deleted file mode 100644 index f2955fb87..000000000 --- a/tests/Phinx/Db/Mock/PdoAdapterTestPDOMock.php +++ /dev/null @@ -1,10 +0,0 @@ -getMockForAbstractClass('\PDO') fails under PHP5.4 and - * an older PHPUnit; a PDO instance cannot be serialised. - */ -class PdoAdapterTestPDOMockWithExecChecks extends PdoAdapterTestPDOMock -{ - private $sql; - - public function exec($sql) - { - $this->sql = $sql; - - return 1; - } - - public function prepare($sql, $options = []) - { - $this->sql = $sql; - - return new PdoStatementMock(); - } - - public function getExecutedSqlForTest() - { - return $this->sql; - } -} diff --git a/tests/Phinx/Db/Mock/PdoStatementMock.php b/tests/Phinx/Db/Mock/PdoStatementMock.php deleted file mode 100644 index e6051a7b3..000000000 --- a/tests/Phinx/Db/Mock/PdoStatementMock.php +++ /dev/null @@ -1,16 +0,0 @@ -