-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
AuditManagerTest.php
79 lines (58 loc) · 2.4 KB
/
AuditManagerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\AdminBundle\Tests\Model;
use PHPUnit\Framework\TestCase;
use Sonata\AdminBundle\Model\AuditManager;
use Sonata\AdminBundle\Model\AuditReaderInterface;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\DependencyInjection\Container;
/**
* @author Andrej Hudec <pulzarraider@gmail.com>
*/
final class AuditManagerTest extends TestCase
{
// NEXT_MAJOR: Remove next line.
use ExpectDeprecationTrait;
public function testGetReader(): void
{
$container = new Container();
$fooReader = $this->createStub(AuditReaderInterface::class);
$barReader = $this->createStub(AuditReaderInterface::class);
$container->set('foo_reader', $fooReader);
$container->set('bar_reader', $barReader);
$auditManager = new AuditManager($container);
$this->assertFalse($auditManager->hasReader('Foo\Foo1'));
$auditManager->setReader('foo_reader', ['Foo\Foo1', 'Foo\Foo2']);
$this->assertTrue($auditManager->hasReader('Foo\Foo1'));
$this->assertSame($fooReader, $auditManager->getReader('Foo\Foo1'));
}
public function testGetReaderWithException(): void
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('The class "Foo\Foo" does not have any reader manager');
$auditManager = new AuditManager(new Container());
$auditManager->getReader('Foo\Foo');
}
/**
* NEXT_MAJOR: Remove this test.
*
* @group legacy
*/
public function testReaderShouldBeTagged(): void
{
$container = new Container();
$fooReader = $this->createStub(AuditReaderInterface::class);
$container->set('foo_reader', $fooReader);
$auditManager = new AuditManager($container, new Container());
$this->expectDeprecation('Not registering the audit reader "foo_reader" with tag "sonata.admin.audit_reader" is deprecated since sonata-project/admin-bundle 3.x and will not work in 4.0. You MUST add "sonata.admin.audit_reader" tag to the service "foo_reader".');
$auditManager->setReader('foo_reader', ['Foo\Foo1', 'Foo\Foo2']);
}
}