ListAdminCommandTest.php 2.3 KB

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