From 59aa258ec20379fa8a4b6607b169d791d8e737c8 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 16 Apr 2020 20:39:10 -0700 Subject: [PATCH] Reworked LoggingTest to be able to test Statement::executeUpdate() --- .../Tests/DBAL/Connection/LoggingTest.php | 65 +++++++++++++++++++ .../Tests/DBAL/Functional/LoggingTest.php | 55 ---------------- 2 files changed, 65 insertions(+), 55 deletions(-) create mode 100644 tests/Doctrine/Tests/DBAL/Connection/LoggingTest.php delete mode 100644 tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php diff --git a/tests/Doctrine/Tests/DBAL/Connection/LoggingTest.php b/tests/Doctrine/Tests/DBAL/Connection/LoggingTest.php new file mode 100644 index 00000000000..a7b04f94994 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Connection/LoggingTest.php @@ -0,0 +1,65 @@ +createStub(DriverConnection::class); + $driverConnection->method('query') + ->willReturn($this->createStub(Statement::class)); + + $this->createConnection($driverConnection, 'SELECT * FROM table') + ->executeQuery('SELECT * FROM table'); + } + + public function testLogExecuteUpdate() : void + { + $this->createConnection( + $this->createStub(DriverConnection::class), + 'UPDATE table SET foo = ?' + ) + ->executeUpdate('UPDATE table SET foo = ?'); + } + + public function testLogPrepareExecute() : void + { + $driverConnection = $this->createStub(DriverConnection::class); + $driverConnection->method('prepare') + ->willReturn($this->createStub(Statement::class)); + + $this->createConnection($driverConnection, 'UPDATE table SET foo = ?') + ->prepare('UPDATE table SET foo = ?') + ->execute(); + } + + private function createConnection(DriverConnection $driverConnection, string $expectedSQL) : Connection + { + $driver = $this->createStub(Driver::class); + $driver->method('connect') + ->willReturn($driverConnection); + $driver->method('getDatabasePlatform') + ->willReturn($this->createMock(AbstractPlatform::class)); + + $logger = $this->createMock(SQLLogger::class); + $logger->expects($this->once()) + ->method('startQuery') + ->with($this->equalTo($expectedSQL), $this->equalTo([])); + $logger->expects($this->at(1)) + ->method('stopQuery'); + + $connection = new Connection([], $driver); + $connection->getConfiguration()->setSQLLogger($logger); + + return $connection; + } +} diff --git a/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php b/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php deleted file mode 100644 index aa63af708df..00000000000 --- a/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php +++ /dev/null @@ -1,55 +0,0 @@ -connection->getDatabasePlatform()->getDummySelectSQL(); - - $logMock = $this->createMock(SQLLogger::class); - $logMock->expects($this->at(0)) - ->method('startQuery') - ->with($this->equalTo($sql), $this->equalTo([]), $this->equalTo([])); - $logMock->expects($this->at(1)) - ->method('stopQuery'); - $this->connection->getConfiguration()->setSQLLogger($logMock); - $this->connection->executeQuery($sql, []); - } - - public function testLogExecuteUpdate() : void - { - $this->markTestSkipped('Test breaks MySQL but works on all other platforms (Unbuffered Queries stuff).'); - - $sql = $this->connection->getDatabasePlatform()->getDummySelectSQL(); - - $logMock = $this->createMock(SQLLogger::class); - $logMock->expects($this->at(0)) - ->method('startQuery') - ->with($this->equalTo($sql), $this->equalTo([]), $this->equalTo([])); - $logMock->expects($this->at(1)) - ->method('stopQuery'); - $this->connection->getConfiguration()->setSQLLogger($logMock); - $this->connection->executeUpdate($sql, []); - } - - public function testLogPrepareExecute() : void - { - $sql = $this->connection->getDatabasePlatform()->getDummySelectSQL(); - - $logMock = $this->createMock(SQLLogger::class); - $logMock->expects($this->once()) - ->method('startQuery') - ->with($this->equalTo($sql), $this->equalTo([])); - $logMock->expects($this->at(1)) - ->method('stopQuery'); - $this->connection->getConfiguration()->setSQLLogger($logMock); - - $stmt = $this->connection->prepare($sql); - $stmt->execute(); - } -}