ListAdminCommandTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\Command;
  11. use Sonata\AdminBundle\Admin\Pool;
  12. use Sonata\AdminBundle\Command\ListAdminCommand;
  13. use Sonata\AdminBundle\Tests\Helpers\PHPUnit_Framework_TestCase;
  14. use Symfony\Component\Console\Application;
  15. use Symfony\Component\Console\Tester\CommandTester;
  16. /**
  17. * @author Andrej Hudec <pulzarraider@gmail.com>
  18. */
  19. class ListAdminCommandTest extends PHPUnit_Framework_TestCase
  20. {
  21. public function testExecute()
  22. {
  23. $application = new Application();
  24. $command = new ListAdminCommand();
  25. $container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface');
  26. $admin1 = $this->createMock('Sonata\AdminBundle\Admin\AdminInterface');
  27. $admin1->expects($this->any())
  28. ->method('getClass')
  29. ->will($this->returnValue('Acme\Entity\Foo'));
  30. $admin2 = $this->createMock('Sonata\AdminBundle\Admin\AdminInterface');
  31. $admin2->expects($this->any())
  32. ->method('getClass')
  33. ->will($this->returnValue('Acme\Entity\Bar'));
  34. $container->expects($this->any())
  35. ->method('get')
  36. ->will($this->returnCallback(function ($id) use ($container, $admin1, $admin2) {
  37. switch ($id) {
  38. case 'sonata.admin.pool':
  39. $pool = new Pool($container, '', '');
  40. $pool->setAdminServiceIds(array('acme.admin.foo', 'acme.admin.bar'));
  41. return $pool;
  42. case 'acme.admin.foo':
  43. return $admin1;
  44. case 'acme.admin.bar':
  45. return $admin2;
  46. }
  47. return;
  48. }));
  49. $command->setContainer($container);
  50. $application->add($command);
  51. $command = $application->find('sonata:admin:list');
  52. $commandTester = new CommandTester($command);
  53. $commandTester->execute(array('command' => $command->getName()));
  54. $this->assertRegExp('@Admin services:\s+acme.admin.foo\s+Acme\\\Entity\\\Foo\s+acme.admin.bar\s+Acme\\\Entity\\\Bar@', $commandTester->getDisplay());
  55. }
  56. }