SonataAdminBundleTest.php 2.3 KB

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