-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reverted and adjusted middleware test
- Loading branch information
1 parent
4af969b
commit 4b5c079
Showing
1 changed file
with
108 additions
and
0 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
tests/DependencyInjection/Compiler/DoctrineMiddlewareCompilerPassTest.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,108 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DH\AuditorBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use DH\Auditor\Configuration; | ||
use DH\Auditor\Provider\Doctrine\Auditing\Logger\Middleware\DHMiddleware; | ||
use DH\Auditor\Tests\Provider\Doctrine\Fixtures\Entity\Standard\Blog\Author; | ||
use DH\Auditor\Tests\Provider\Doctrine\Fixtures\Entity\Standard\Blog\Comment; | ||
use DH\Auditor\Tests\Provider\Doctrine\Fixtures\Entity\Standard\Blog\Post; | ||
use DH\Auditor\Tests\Provider\Doctrine\Fixtures\Entity\Standard\Blog\Tag; | ||
use DH\AuditorBundle\DependencyInjection\Compiler\DoctrineProviderConfigurationCompilerPass; | ||
use DH\AuditorBundle\DependencyInjection\DHAuditorExtension; | ||
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension; | ||
use Doctrine\DBAL\Driver\Middleware; | ||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @small | ||
*/ | ||
final class DoctrineMiddlewareCompilerPassTest extends AbstractCompilerPassTestCase | ||
{ | ||
public function testCompilerPass(): void | ||
{ | ||
if (!interface_exists(Middleware::class) || !class_exists(DHMiddleware::class)) { | ||
self::markTestSkipped('DHMiddleware isn\'t supported'); | ||
} | ||
$this->container->setParameter('kernel.cache_dir', sys_get_temp_dir()); | ||
$this->container->setParameter('kernel.debug', false); | ||
$this->container->setParameter('kernel.bundles', []); | ||
$doctrineConfig = [ | ||
'dbal' => [ | ||
'default_connection' => 'default', | ||
'connections' => [ | ||
'default' => [], | ||
], | ||
], | ||
'orm' => [ | ||
'auto_mapping' => true, | ||
], | ||
]; | ||
$this->setParameter('doctrine', $doctrineConfig); | ||
|
||
$DHConfig = [ | ||
'enabled' => true, | ||
'timezone' => 'UTC', | ||
'user_provider' => 'dh_auditor.user_provider', | ||
'security_provider' => 'dh_auditor.security_provider', | ||
'role_checker' => 'dh_auditor.role_checker', | ||
'providers' => [ | ||
'doctrine' => [ | ||
'table_prefix' => '', | ||
'table_suffix' => '_audit', | ||
'ignored_columns' => [ | ||
0 => 'createdAt', | ||
1 => 'updatedAt', | ||
], | ||
'entities' => [ | ||
Author::class => [ | ||
'enabled' => true, | ||
], | ||
Post::class => [ | ||
'enabled' => true, | ||
], | ||
Comment::class => [ | ||
'enabled' => true, | ||
], | ||
Tag::class => [ | ||
'enabled' => true, | ||
], | ||
], | ||
'storage_services' => [ | ||
0 => '@doctrine.orm.default_entity_manager', | ||
], | ||
'auditing_services' => [ | ||
0 => '@doctrine.orm.default_entity_manager', | ||
], | ||
'viewer' => true, | ||
'storage_mapper' => null, | ||
], | ||
], | ||
]; | ||
$this->setParameter('dh_auditor.configuration', $DHConfig); | ||
|
||
$auditorService = new Definition(); | ||
$this->setDefinition(Configuration::class, $auditorService); | ||
$this->container->loadFromExtension('doctrine', $doctrineConfig); | ||
$this->container->loadFromExtension('dh_auditor', $DHConfig); | ||
$this->compile(); | ||
|
||
$this->assertContainerBuilderHasServiceDefinitionWithTag( | ||
'doctrine.dbal.default_connection.dh_middleware', | ||
'doctrine.middleware' | ||
); | ||
} | ||
|
||
protected function registerCompilerPass(ContainerBuilder $container): void | ||
{ | ||
$this->container->registerExtension(new DoctrineExtension()); | ||
$this->container->registerExtension(new DHAuditorExtension()); | ||
$container->addCompilerPass(new DoctrineProviderConfigurationCompilerPass()); | ||
} | ||
} |