Skip to content

Commit

Permalink
Merge pull request #98 from indjeto/v1.0
Browse files Browse the repository at this point in the history
Make tests pass
  • Loading branch information
indjeto authored Feb 2, 2024
2 parents b5d2082 + 11adac0 commit a67af1f
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 23 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ defaults:

jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1']
php: ['8.0', '8.1', '8.2', '8.3']

steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.phpunit.result.cache
/composer.lock
/phpunit.xml
/.idea
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"require": {
"php": ">=7.4",
"php": ">=8.0",
"doctrine/dbal": "^2.9|^3.1.4",
"doctrine/doctrine-bundle": "^2.2",
"doctrine/orm": "^2.6",
Expand Down
6 changes: 3 additions & 3 deletions docs/labeler.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class AuditLabler
}
```

Re-define the audit subscriber service to call the `setLabler` method of the `AuditSubscriber` with the [callable](https://www.php.net/manual/en/language.types.callable.php).
Re-define the audit listener service to call the `setLabler` method of the `AuditListener` with the [callable](https://www.php.net/manual/en/language.types.callable.php).

`app/config/services.yml`

```yaml
services:
datadog.event_subscriber.audit:
class: 'DataDog\AuditBundle\EventSubscriber\AuditSubscriber'
datadog.event_listener.audit:
class: 'DataDog\AuditBundle\EventListener\AuditListener'
arguments: ['@security.token_storage']
tags:
- { name: doctrine.event_subscriber, connection: default }
Expand Down
8 changes: 4 additions & 4 deletions src/DependencyInjection/DataDogAuditExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ public function load(array $configs, ContainerBuilder $container): void
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$auditSubscriber = $container->getDefinition('datadog.event_subscriber.audit');
$auditListener = $container->getDefinition('datadog.event_listener.audit');

if (isset($config['audited_entities']) && !empty($config['audited_entities'])) {
$auditSubscriber->addMethodCall('addAuditedEntities', array($config['audited_entities']));
$auditListener->addMethodCall('addAuditedEntities', array($config['audited_entities']));
} else if (isset($config['unaudited_entities'])) {
$auditSubscriber->addMethodCall('addUnauditedEntities', array($config['unaudited_entities']));
$auditListener->addMethodCall('addUnauditedEntities', array($config['unaudited_entities']));
}

if (isset($config['blame_impersonator'])) {
$auditSubscriber->addMethodCall('setBlameImpersonator', array($config['blame_impersonator']));
$auditListener->addMethodCall('setBlameImpersonator', array($config['blame_impersonator']));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace DataDog\AuditBundle\EventSubscriber;
namespace DataDog\AuditBundle\EventListener;

use DataDog\AuditBundle\DBAL\AuditLogger;
use DataDog\AuditBundle\Entity\Association;
Expand All @@ -19,7 +19,7 @@
use Symfony\Component\Security\Core\Role\SwitchUserRole;
use Symfony\Component\Security\Core\User\UserInterface;

class AuditSubscriber implements EventSubscriber
class AuditListener
{
/**
* @var callable|null
Expand Down Expand Up @@ -120,7 +120,7 @@ protected function isEntityUnaudited($entity)
return $isEntityUnaudited;
}

public function onFlush(OnFlushEventArgs $args)
public function onFlush(OnFlushEventArgs $args): void
{
$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();
Expand Down Expand Up @@ -525,11 +525,6 @@ private function getRoles(TokenInterface $token)
return $token->getRoles();
}

public function getSubscribedEvents(): array
{
return [Events::onFlush];
}

public function setBlameUser(UserInterface $user)
{
$this->blameUser = $user;
Expand Down
7 changes: 4 additions & 3 deletions src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use DataDog\AuditBundle\EventSubscriber\AuditSubscriber;
use DataDog\AuditBundle\EventListener\AuditListener;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

return static function (ContainerConfigurator $container) {
// @formatter:off
$services = $container->services();
$services
->set('datadog.event_subscriber.audit', AuditSubscriber::class)->private()
->set('datadog.event_listener.audit', AuditListener::class)->private()
->arg(0, new Reference(TokenStorageInterface::class))
->tag('doctrine.event_subscriber')
//->tag('doctrine.event_subscriber')
->tag('doctrine.event_listener', ['event' => 'onFlush',])
;
// @formatter:on
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

declare(strict_types=1);

namespace DataDog\AuditBundle\Tests\EventSubscriber;
namespace DataDog\AuditBundle\Tests\EventListener;

use DataDog\AuditBundle\Entity\AuditLog;
use DataDog\AuditBundle\Tests\Entity\Post;
use DataDog\AuditBundle\Tests\Entity\Tag;
use DataDog\AuditBundle\Tests\OrmTestCase;

final class AuditSubscriberTest extends OrmTestCase
final class AuditListenerTest extends OrmTestCase
{
protected function setUp(): void
{
Expand Down

0 comments on commit a67af1f

Please sign in to comment.