SonataAdminBundleTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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;
  11. use Sonata\AdminBundle\DependencyInjection\Compiler\AddDependencyCallsCompilerPass;
  12. use Sonata\AdminBundle\DependencyInjection\Compiler\AddFilterTypeCompilerPass;
  13. use Sonata\AdminBundle\DependencyInjection\Compiler\ExtensionCompilerPass;
  14. use Sonata\AdminBundle\DependencyInjection\Compiler\GlobalVariablesCompilerPass;
  15. use Sonata\AdminBundle\SonataAdminBundle;
  16. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  17. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  18. /**
  19. * Test for SonataAdminBundle.
  20. *
  21. * @author Andrej Hudec <pulzarraider@gmail.com>
  22. */
  23. class SonataAdminBundleTest extends \PHPUnit_Framework_TestCase
  24. {
  25. public function testBuild()
  26. {
  27. $containerBuilder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder', array('addCompilerPass'));
  28. $containerBuilder->expects($this->exactly(4))
  29. ->method('addCompilerPass')
  30. ->will($this->returnCallback(function (CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION) {
  31. if ($pass instanceof AddDependencyCallsCompilerPass) {
  32. return;
  33. }
  34. if ($pass instanceof AddFilterTypeCompilerPass) {
  35. return;
  36. }
  37. if ($pass instanceof ExtensionCompilerPass) {
  38. return;
  39. }
  40. if ($pass instanceof GlobalVariablesCompilerPass) {
  41. return;
  42. }
  43. $this->fail(sprintf('Compiler pass is not one of the expected types. Expects "Sonata\AdminBundle\DependencyInjection\Compiler\AddDependencyCallsCompilerPass", "Sonata\AdminBundle\DependencyInjection\Compiler\AddFilterTypeCompilerPass" or "Sonata\AdminBundle\DependencyInjection\Compiler\ExtensionCompilerPass", but got "%s".', get_class($pass)));
  44. }));
  45. $bundle = new SonataAdminBundle();
  46. $bundle->build($containerBuilder);
  47. }
  48. }