AuditManagerTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. use Sonata\AdminBundle\Tests\Helpers\PHPUnit_Framework_TestCase;
  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->getMockForAbstractClass('Symfony\Component\DependencyInjection\ContainerInterface');
  23. $fooReader = $this->getMockForAbstractClass('Sonata\AdminBundle\Model\AuditReaderInterface');
  24. $barReader = $this->getMockForAbstractClass('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. case 'bar_reader':
  32. return $barReader;
  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->expectException('\RuntimeException', 'The class "Foo\Foo" does not have any reader manager');
  45. $container = $this->getMockForAbstractClass('Symfony\Component\DependencyInjection\ContainerInterface');
  46. $auditManager = new AuditManager($container);
  47. $auditManager->getReader('Foo\Foo');
  48. }
  49. }