-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3957 from morozov/logging-test
Reworked LoggingTest to be able to test Statement::executeUpdate()
- Loading branch information
Showing
2 changed files
with
65 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\DBAL\Connection; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Driver; | ||
use Doctrine\DBAL\Driver\Connection as DriverConnection; | ||
use Doctrine\DBAL\Driver\Statement; | ||
use Doctrine\DBAL\Logging\SQLLogger; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class LoggingTest extends TestCase | ||
{ | ||
public function testLogExecuteQuery() : void | ||
{ | ||
$driverConnection = $this->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; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.