Skip to content

Instantly share code, notes, and snippets.

@flug
Created April 3, 2020 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flug/b7cc8db60f70bb16c4d408c317062630 to your computer and use it in GitHub Desktop.
Save flug/b7cc8db60f70bb16c4d408c317062630 to your computer and use it in GitHub Desktop.
<?php
namespace spec\Clooder\Console;
use Clooder\Console\Application;
use Clooder\Kernel;
use PhpSpec\ObjectBehavior;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class ApplicationSpec extends ObjectBehavior
{
public function let(Kernel $kernel, ContainerInterface $container, EventDispatcherInterface $eventDispatcher)
{
$container->set('event_dispatcher', $eventDispatcher->getWrappedObject());
$kernel->getContainer()->willReturn($container);
$this->beConstructedWith($kernel);
}
function it_is_initializable()
{
$this->shouldHaveType(Application::class);
$this->beAnInstanceOf(\Symfony\Component\Console\Application::class);
}
function it_is_about_testing_the_addition_of_a_command(Kernel $kernel, ContainerInterface $container)
{
$kernel->boot()->shouldBeCalledOnce();
$command = new Command('example');
$this->add($command)->shouldReturn($command);
$this->get('example')->shouldReturn($command);
}
function it_is_about_having_all_the_commands_available(Kernel $kernel, ContainerInterface $container)
{
$kernel->boot()->shouldBeCalledOnce();
$command1 = new Command('example1');
$command2 = new Command('example2');
$command3 = new Command('example3');
$this->add($command1);
$this->add($command2);
$this->add($command3);
$this->all()->shouldReturn([
'help' => $this->get('help'),
'list' => $this->get('list'),
'example1' => $command1,
'example2' => $command2,
'example3' => $command3,
])
;
}
function it_is_a_question_of_whether_a_command_exists(Kernel $kernel, ContainerInterface $container)
{
$kernel->boot()->shouldBeCalledOnce();
$command = new Command('example');
$this->add($command);
$this->has('example')->shouldReturn(true);
}
function it_is_a_question_of_whether_a_command_does_not_exist(Kernel $kernel, ContainerInterface $container)
{
$kernel->boot()->shouldBeCalledOnce();
$command = new Command('example');
$this->has('example')->shouldReturn(false);
}
function it_is_about_testing_a_registered_command(
Kernel $kernel,
ContainerInterface $container,
EventDispatcherInterface $dispatcher
) {
///$container->get('event_dispatcher')->willReturn($dispatcher->getWrappedObject());
//$container->get('event_dispatcher')->willReturn($dispatcher->getWrappedObject());
/**$kernel->boot()->shouldBeCalledOnce();
* $kernel->getContainer()->willReturn($container);
* $this->setDispatcher($container->get('event_dispatcher'));
*/
$container->set('event_dispatcher', $dispatcher->getWrappedObject());
$this->setDispatcher($container->get('event_dispatcher'));
$this->doRun(new ArrayInput(['list']), new NullOutput());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment