AuditManagerTest.php 2.0 KB

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