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 Feb 22, 2023
1 parent 4b5c079 commit 3f31c91
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ public function testBlameUser(): void
}

$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
Original file line number Diff line number Diff line change
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 @@ -78,6 +80,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 @@ -117,6 +120,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 3f31c91

Please sign in to comment.