FilterFactoryTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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\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 testUnknownType()
  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 testUnknownClassType()
  36. {
  37. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  38. $filter = new FilterFactory($container, array());
  39. $filter->create('test', 'Sonata\AdminBundle\Form\Type\Filter\FooType');
  40. }
  41. /**
  42. * @expectedException RuntimeException
  43. */
  44. public function testClassType()
  45. {
  46. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  47. $filter = new FilterFactory($container, array());
  48. $filter->create('test', 'Sonata\AdminBundle\Form\Type\Filter\DefaultType');
  49. }
  50. /**
  51. * @expectedException RuntimeException
  52. */
  53. public function testInvalidTypeInstance()
  54. {
  55. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  56. $container->expects($this->once())
  57. ->method('get')
  58. ->will($this->returnValue(false));
  59. $filter = new FilterFactory($container, array('mytype' => 'mytype'));
  60. $filter->create('test', 'mytype');
  61. }
  62. public function testCreateFilter()
  63. {
  64. $filter = $this->getMock('Sonata\AdminBundle\Filter\FilterInterface');
  65. $filter->expects($this->once())
  66. ->method('initialize');
  67. $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
  68. $container->expects($this->once())
  69. ->method('get')
  70. ->will($this->returnValue($filter));
  71. $filter = new FilterFactory($container, array('mytype' => 'mytype'));
  72. $filter->create('test', 'mytype');
  73. }
  74. }