Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked LoggingTest to be able to test Statement::executeUpdate() #3957

Merged
merged 1 commit into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions tests/Doctrine/Tests/DBAL/Connection/LoggingTest.php
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;
}
}
55 changes: 0 additions & 55 deletions tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php

This file was deleted.