FilterFactoryTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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\Tests\Filter;
  11. use Sonata\AdminBundle\Filter\FilterFactory;
  12. class FilterFactoryTest extends \PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * @expectedException RuntimeException
  16. */
  17. public function testEmptyType()
  18. {
  19. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  20. $filter = new FilterFactory($container, array());
  21. $filter->create('test', null);
  22. }
  23. /**
  24. * @expectedException RuntimeException
  25. */
  26. public function testUnknowType()
  27. {
  28. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  29. $filter = new FilterFactory($container, array());
  30. $filter->create('test', 'mytype');
  31. }
  32. /**
  33. * @expectedException RuntimeException
  34. */
  35. public function testInvalidTypeInstance()
  36. {
  37. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  38. $container->expects($this->once())
  39. ->method('get')
  40. ->will($this->returnValue(false));
  41. $filter = new FilterFactory($container, array('mytype' => 'mytype'));
  42. $filter->create('test', 'mytype');
  43. }
  44. public function testCreateFilter()
  45. {
  46. $filter = $this->getMock('Sonata\AdminBundle\Filter\FilterInterface');
  47. $filter->expects($this->once())
  48. ->method('initialize');
  49. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  50. $container->expects($this->once())
  51. ->method('get')
  52. ->will($this->returnValue($filter));
  53. $filter = new FilterFactory($container, array('mytype' => 'mytype'));
  54. $filter->create('test', 'mytype');
  55. }
  56. }