-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fixes #185 * PHP-CS-Fixer --------- Co-authored-by: Damien Harper <[email protected]>
- Loading branch information
1 parent
5a9dbc2
commit 07235c1
Showing
2 changed files
with
92 additions
and
18 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
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,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DH\Auditor\Tests\Provider\Doctrine\Event; | ||
|
||
use DH\Auditor\Provider\Doctrine\Auditing\Event\DoctrineSubscriber; | ||
use DH\Auditor\Provider\Doctrine\Auditing\Transaction\TransactionManager; | ||
use Doctrine\DBAL\Configuration; | ||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Driver; | ||
use Doctrine\DBAL\Logging\SQLLogger; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\ORM\Event\OnFlushEventArgs; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @small | ||
*/ | ||
final class DoctrineSubscriberTest extends TestCase | ||
{ | ||
public function testIssue185(): void | ||
{ | ||
$transactionManager = $this->createMock(TransactionManager::class); | ||
$objectManager = $this->createMock(EntityManagerInterface::class); | ||
|
||
$args = new OnFlushEventArgs($objectManager); | ||
|
||
$objectManager | ||
->method('getConnection') | ||
->willReturn($connection = $this->createMock(Connection::class)) | ||
; | ||
|
||
$connection | ||
->method('getDriver') | ||
->willReturn($driver = $this->createMock(Driver::class)) | ||
; | ||
|
||
$connection | ||
->method('getConfiguration') | ||
->willReturn($configuration = new Configuration()) | ||
; | ||
|
||
$configuration->setSQLLogger(new class() implements SQLLogger { | ||
public function startQuery($sql, ?array $params = null, ?array $types = null): void {} | ||
|
||
public function stopQuery(): void {} | ||
}); | ||
|
||
$target = new DoctrineSubscriber($transactionManager); | ||
$target->onFlush($args); | ||
$target->onFlush($args); | ||
$target->onFlush($args); | ||
$target->onFlush($args); | ||
$target->onFlush($args); | ||
|
||
$result = $configuration->getSQLLogger(); | ||
self::assertCount(2, $result->getLoggers()); | ||
} | ||
} |