-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix bug: exception while creating audit table schema when using single table inheritance (#133) * fix #132 * entity Co-authored-by: a.dmitryuk <[email protected]> * Updated README.md * Updated CI * Fixed annotations in tests * Regression fix. Fixes DamienHarper/auditor-bundle#334 * Updated CI * Performance issues with metadatas (#137) * Cache DH Annotations * speed * remove getOwner call Co-authored-by: a.dmitryuk <[email protected]> * CreateSchemaListener not updating inheritance tables (#139) * Fix: Attempted to call an undefined method named "getMetadataCache" of class "Doctrine\ORM\Configuration". (#144) * Fix: Attempted to call an undefined method named "introspectSchema" of class "Doctrine\DBAL\Schema\PostgreSQLSchemaManager" (#143) * Fixed invokable storage mapper (see #146) (#148) * Fixed broken annotation registration since doctrine/orm 2.14 * improved the TransactionProcessor to convert encoding of diff properly (#152) * improved the TransactionProcessor to convert encoding of diff properly * adapted quotes in TransactionProcessor to single quotes * Fixed compatibility issue with doctrine/event-manager ^2.0 (#157) * PHP-CS-Fixer * Validate that diff is a string before passing to mb_convert_encoding (#156) * PHP-CS-Fixer * Support doctrine annotations 2.0 (#158) * topic 344 doctrine annotations 2.0 --------- Co-authored-by: a.dmitryuk <[email protected]> * PHP-CS-Fixer * Fix failing CI (lock related) * PHP-CS-Fixer * Fixes `diffs` column type when JSON type is supported * Fixed CI (2.x) * Fixed CI (2.x) * Fixed CI (2.x) * Fixed CI (2.x) * Fixed CI (2.x) * Fix 185 (#186) * fixes #185 * PHP-CS-Fixer --------- Co-authored-by: Damien Harper <[email protected]> * skip embedded class from schema listener (#189) Co-authored-by: Guillaume Sainthillier <[email protected]> * Fixed CI (2.x) * Typo * PHP-CS-Fixer * Update deps + PHP-CS-Fixer * PHP-CS-Fixer * PHP-CS-Fixer (3.48.0) * Detected wrapped driver (#195) * - updated DHDriver and use parent::connect instead of dedicated field - added getWrappedDriver to extract wrapped driver. - tests Signed-off-by: Oleg Andreyev <[email protected]> * Fixed PHPStan error --------- Signed-off-by: Oleg Andreyev <[email protected]> Co-authored-by: Damien Harper <[email protected]> * fix Signed-off-by: Oleg Andreyev <[email protected]> * php-cs-fixer Signed-off-by: Oleg Andreyev <[email protected]> * removed getSubscribedEvents from CreateSchemaListener Signed-off-by: Oleg Andreyev <[email protected]> * phpstan Signed-off-by: Oleg Andreyev <[email protected]> * fix DoctrineSubscriber + tests Signed-off-by: Oleg Andreyev <[email protected]> * fix Issue174Test Signed-off-by: Oleg Andreyev <[email protected]> * removed duplicate code, fixed test Signed-off-by: Oleg Andreyev <[email protected]> --------- Signed-off-by: Oleg Andreyev <[email protected]> Co-authored-by: Alexander Dmitryuk <[email protected]> Co-authored-by: a.dmitryuk <[email protected]> Co-authored-by: damienharper <[email protected]> Co-authored-by: Jörn Dyherrn <[email protected]> Co-authored-by: Martijn Boers <[email protected]> Co-authored-by: Guillaume Sainthillier <[email protected]>
- Loading branch information
1 parent
0a35944
commit aa0f9ee
Showing
6 changed files
with
240 additions
and
24 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
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
183 changes: 183 additions & 0 deletions
183
tests/Provider/Doctrine/Event/DoctrineSubscriberTest.php
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,183 @@ | ||
<?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\Logger\Middleware\DHDriver; | ||
use DH\Auditor\Transaction\TransactionManagerInterface; | ||
use Doctrine\DBAL\Configuration; | ||
use Doctrine\DBAL\Connection as ConnectionDbal; | ||
use Doctrine\DBAL\Driver; | ||
use Doctrine\DBAL\Driver\API\MySQL\ExceptionConverter; | ||
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\VersionAwarePlatformDriver; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\ORM\Event\OnFlushEventArgs; | ||
use PHPUnit\Framework\TestCase; | ||
use RuntimeException; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @small | ||
*/ | ||
final class DoctrineSubscriberTest extends TestCase | ||
{ | ||
public function testIssue184IfAbstractDriverMiddleware(): void | ||
{ | ||
$transactionManager = new class() implements TransactionManagerInterface { | ||
public function populate($transaction): void {} | ||
|
||
public function process($transaction): void | ||
{ | ||
static $i = 0; | ||
++$i; | ||
if ($i > 1) { | ||
throw new RuntimeException('Expected only once'); | ||
} | ||
} | ||
}; | ||
$objectManager = $this->createMock(EntityManagerInterface::class); | ||
|
||
$args = new OnFlushEventArgs($objectManager); | ||
|
||
$nativeDriver = $this->createMock(Driver::class); | ||
$dhDriver = new DHDriver($nativeDriver); | ||
$driver = new class($dhDriver) extends AbstractDriverMiddleware {}; | ||
|
||
$objectManager | ||
->method('getConnection') | ||
->willReturn($connection = $this->createMock(ConnectionDbal::class)) | ||
; | ||
|
||
$connection | ||
->method('getDriver') | ||
->willReturn($driver) | ||
; | ||
|
||
$target = new DoctrineSubscriber($transactionManager); | ||
$target->onFlush($args); | ||
|
||
foreach ($dhDriver->getFlusherList() as $item) { | ||
($item)(); | ||
} | ||
|
||
self::assertTrue(true); | ||
} | ||
|
||
public function testIssue184IfNotAbstractDriverMiddleware(): void | ||
{ | ||
$transactionManager = new class() implements TransactionManagerInterface { | ||
public function populate($transaction): void {} | ||
|
||
public function process($transaction): void | ||
{ | ||
static $i = 0; | ||
++$i; | ||
if ($i > 1) { | ||
throw new RuntimeException('Expected only once'); | ||
} | ||
} | ||
}; | ||
$objectManager = $this->createMock(EntityManagerInterface::class); | ||
|
||
$args = new OnFlushEventArgs($objectManager); | ||
|
||
$nativeDriver = $this->createMock(Driver::class); | ||
$dhDriver = new DHDriver($nativeDriver); | ||
$driver = new class($dhDriver) implements VersionAwarePlatformDriver { | ||
/** @noinspection PhpPropertyOnlyWrittenInspection */ | ||
private Driver $wrappedDriver; | ||
|
||
public function __construct(Driver $wrappedDriver) | ||
{ | ||
$this->wrappedDriver = $wrappedDriver; | ||
} | ||
|
||
public function connect(array $params): void {} | ||
|
||
public function getDatabasePlatform(): void {} | ||
|
||
public function getSchemaManager(ConnectionDbal $conn, AbstractPlatform $platform): void {} | ||
|
||
public function getExceptionConverter(): Driver\API\ExceptionConverter | ||
{ | ||
return new ExceptionConverter(); | ||
} | ||
|
||
public function createDatabasePlatformForVersion($version): void {} | ||
}; | ||
|
||
$objectManager | ||
->method('getConnection') | ||
->willReturn($connection = $this->createMock(ConnectionDbal::class)) | ||
; | ||
|
||
$connection | ||
->method('getDriver') | ||
->willReturn($driver) | ||
; | ||
|
||
$target = new DoctrineSubscriber($transactionManager); | ||
$target->onFlush($args); | ||
|
||
foreach ($dhDriver->getFlusherList() as $item) { | ||
($item)(); | ||
} | ||
|
||
self::assertTrue(true); | ||
} | ||
|
||
public function testIssue184Unexpected(): void | ||
{ | ||
$transactionManager = new class() implements TransactionManagerInterface { | ||
public function populate($transaction): void {} | ||
|
||
public function process($transaction): void | ||
{ | ||
throw new RuntimeException('Unexpected call'); | ||
} | ||
}; | ||
$objectManager = $this->createMock(EntityManagerInterface::class); | ||
|
||
$args = new OnFlushEventArgs($objectManager); | ||
|
||
$driver = new class() implements VersionAwarePlatformDriver { | ||
public function connect(array $params): void {} | ||
|
||
public function getDatabasePlatform(): void {} | ||
|
||
public function getSchemaManager(ConnectionDbal $conn, AbstractPlatform $platform): void {} | ||
|
||
public function getExceptionConverter(): Driver\API\ExceptionConverter | ||
{ | ||
return new ExceptionConverter(); | ||
} | ||
|
||
public function createDatabasePlatformForVersion($version): void {} | ||
}; | ||
|
||
$objectManager | ||
->method('getConnection') | ||
->willReturn($connection = $this->createMock(ConnectionDbal::class)) | ||
; | ||
|
||
$connection | ||
->method('getDriver') | ||
->willReturn($driver) | ||
; | ||
|
||
$connection | ||
->method('getConfiguration') | ||
->willReturn($configuration = $this->createMock(Configuration::class)) | ||
; | ||
|
||
$target = new DoctrineSubscriber($transactionManager); | ||
$target->onFlush($args); | ||
|
||
self::assertTrue(true); | ||
} | ||
} |
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