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\Model;
  11. /**
  12. * Test for AuditManager.
  13. *
  14. * @author Andrej Hudec <pulzarraider@gmail.com>
  15. */
  16. class AuditManagerTest extends \PHPUnit_Framework_TestCase
  17. {
  18. public function testGetReader()
  19. {
  20. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  21. $fooReader = $this->getMock('Sonata\AdminBundle\Model\AuditReaderInterface');
  22. $barReader = $this->getMock('Sonata\AdminBundle\Model\AuditReaderInterface');
  23. $container->expects($this->any())
  24. ->method('get')
  25. ->will($this->returnCallback(function ($id) use ($fooReader, $barReader) {
  26. switch ($id) {
  27. case 'foo_reader':
  28. return $fooReader;
  29. break;
  30. case 'bar_reader':
  31. return $barReader;
  32. break;
  33. }
  34. return;
  35. }));
  36. $auditManager = new AuditManager($container);
  37. $this->assertFalse($auditManager->hasReader('Foo\Foo1'));
  38. $auditManager->setReader('foo_reader', array('Foo\Foo1', 'Foo\Foo2'));
  39. $this->assertTrue($auditManager->hasReader('Foo\Foo1'));
  40. $this->assertSame($fooReader, $auditManager->getReader('Foo\Foo1'));
  41. }
  42. public function testGetReaderWithException()
  43. {
  44. $this->setExpectedException('\RuntimeException', 'The class "Foo\Foo" does not have any reader manager');
  45. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  46. $auditManager = new AuditManager($container);
  47. $auditManager->getReader('Foo\Foo');
  48. }
  49. }