AuditManagerTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Tests\Model;
  11. use Sonata\AdminBundle\Model\AuditManager;
  12. /**
  13. * Test for AuditManager.
  14. *
  15. * @author Andrej Hudec <pulzarraider@gmail.com>
  16. */
  17. class AuditManagerTest extends \PHPUnit_Framework_TestCase
  18. {
  19. public function testGetReader()
  20. {
  21. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  22. $fooReader = $this->getMock('Sonata\AdminBundle\Model\AuditReaderInterface');
  23. $barReader = $this->getMock('Sonata\AdminBundle\Model\AuditReaderInterface');
  24. $container->expects($this->any())
  25. ->method('get')
  26. ->will($this->returnCallback(function ($id) use ($fooReader, $barReader) {
  27. switch ($id) {
  28. case 'foo_reader':
  29. return $fooReader;
  30. case 'bar_reader':
  31. return $barReader;
  32. }
  33. return;
  34. }));
  35. $auditManager = new AuditManager($container);
  36. $this->assertFalse($auditManager->hasReader('Foo\Foo1'));
  37. $auditManager->setReader('foo_reader', array('Foo\Foo1', 'Foo\Foo2'));
  38. $this->assertTrue($auditManager->hasReader('Foo\Foo1'));
  39. $this->assertSame($fooReader, $auditManager->getReader('Foo\Foo1'));
  40. }
  41. public function testGetReaderWithException()
  42. {
  43. $this->setExpectedException('\RuntimeException', 'The class "Foo\Foo" does not have any reader manager');
  44. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  45. $auditManager = new AuditManager($container);
  46. $auditManager->getReader('Foo\Foo');
  47. }
  48. }