Skip to content

Commit

Permalink
Adjusted middleware registration priority (fixed failing tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienHarper committed Dec 14, 2022
1 parent f8a3014 commit e584374
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
10 changes: 5 additions & 5 deletions composer.json
Expand Up @@ -41,11 +41,11 @@
"gedmo/doctrine-extensions": "^2.4|^3.0",
"matthiasnoback/symfony-dependency-injection-test": "^3.1|^4.0",
"nyholm/symfony-bundle-test": "1.x-dev",
"phpunit/phpunit": "^8.0|^9.0",
"symfony/browser-kit": "^4.0|^5.1|^6.0",
"symfony/css-selector": "^5.1|^6.0",
"symfony/framework-bundle": "^4.4|^5.0|^6.0",
"symfony/var-dumper": "^4.0|^5.0|^6.0",
"phpunit/phpunit": "^9.0",
"symfony/browser-kit": "^5.4|^6.0",
"symfony/css-selector": "^5.4|^6.0",
"symfony/framework-bundle": "^5.4|^6.0",
"symfony/var-dumper": "^5.4|^6.0",
"symfony/webpack-encore-bundle": "^1.12",
"twig/extensions": "^1.5",
"doctrine/data-fixtures": "^1.4"
Expand Down
3 changes: 2 additions & 1 deletion src/DHAuditorBundle.php
Expand Up @@ -7,6 +7,7 @@
use DH\AuditorBundle\DependencyInjection\Compiler\AddProviderCompilerPass;
use DH\AuditorBundle\DependencyInjection\Compiler\CustomConfigurationCompilerPass;
use DH\AuditorBundle\DependencyInjection\Compiler\DoctrineProviderConfigurationCompilerPass;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;

Expand All @@ -20,7 +21,7 @@ public function build(ContainerBuilder $container): void
parent::build($container);

$container->addCompilerPass(new AddProviderCompilerPass());
$container->addCompilerPass(new DoctrineProviderConfigurationCompilerPass());
$container->addCompilerPass(new DoctrineProviderConfigurationCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1);
$container->addCompilerPass(new CustomConfigurationCompilerPass());
}
}
14 changes: 4 additions & 10 deletions tests/App/Command/CreatePostCommand.php
Expand Up @@ -11,7 +11,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\HttpKernel\Kernel;

class CreatePostCommand extends Command
{
Expand All @@ -32,7 +31,6 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

$io->write('Creating a new post');

$post = new Post();
Expand All @@ -42,14 +40,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
->setCreatedAt(new DateTimeImmutable('2020-01-17 22:17:34'))
;

$this->doctrineProvider->getAuditingServiceForEntity(Post::class)->getEntityManager()->persist($post);
$this->doctrineProvider->getAuditingServiceForEntity(Post::class)->getEntityManager()->flush();

// Symfony 4 compatibility
if (Kernel::MAJOR_VERSION >= 5) {
return self::SUCCESS;
}
$entityManager = $this->doctrineProvider->getAuditingServiceForEntity(Post::class)->getEntityManager();
$entityManager->persist($post);
$entityManager->flush();

return 0;
return self::SUCCESS;
}
}
6 changes: 4 additions & 2 deletions tests/Console/ConsoleUserProviderTest.php
Expand Up @@ -57,10 +57,12 @@ public function testBlameUser(): void
$tester->assertCommandIsSuccessful('Expect it to run');

$this->flushAll($auditingServices);

// get history
$entries = $this->createReader()->createQuery(Post::class)->execute();
self::assertSame('app:post:create', $entries[0]->getUsername());
self::assertSame('command', $entries[0]->getUserId());
self::assertNotEmpty($entries, 'There are audit entries');
self::assertSame('app:post:create', $entries[0]->getUsername(), 'Username is OK');
self::assertSame('command', $entries[0]->getUserId(), 'User ID is OK');
}

protected function getBundleClass()
Expand Down
4 changes: 4 additions & 0 deletions tests/User/UserProviderTest.php
Expand Up @@ -11,6 +11,7 @@
use DH\Auditor\Tests\Provider\Doctrine\Traits\Schema\BlogSchemaSetupTrait;
use DH\AuditorBundle\DHAuditorBundle;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpKernel\HttpKernelBrowser;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
Expand All @@ -29,6 +30,7 @@ final class UserProviderTest extends WebTestCase
use ReaderTrait;

private DoctrineProvider $provider;
private HttpKernelBrowser $client;

protected function setUp(): void
{
Expand Down Expand Up @@ -73,6 +75,7 @@ public function testBlameUser(): void
;
$auditingServices[Post::class]->getEntityManager()->persist($post);
$this->flushAll($auditingServices);

// get history
$entries = $this->createReader()->createQuery(Post::class)->execute();
self::assertSame('dark.vador', $entries[0]->getUsername());
Expand Down Expand Up @@ -107,6 +110,7 @@ public function testBlameImpersonator(): void
;
$auditingServices[Post::class]->getEntityManager()->persist($post);
$this->flushAll($auditingServices);

// get history
$entries = $this->createReader()->createQuery(Post::class)->execute();
self::assertSame('second_user[impersonator dark.vador]', $entries[0]->getUsername());
Expand Down

0 comments on commit e584374

Please sign in to comment.