From b6db740d85d1b93b55c92915958a4a3319985b20 Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Wed, 16 Sep 2015 17:58:11 +0200 Subject: [PATCH 1/3] First major refacotring for running the tasks in different contexts --- .../Collection/TasksCollectionSpec.php | 40 +++++++ .../Console/Helper/TaskRunnerHelperSpec.php | 38 +++++++ spec/GrumPHP/Runner/TaskRunnerSpec.php | 56 +++++---- spec/GrumPHP/Task/BehatSpec.php | 28 +++-- spec/GrumPHP/Task/BlacklistSpec.php | 45 +++++--- .../Task/Context/GitPreCommitContextSpec.php | 30 +++++ spec/GrumPHP/Task/PhpcsSpec.php | 28 +++-- spec/GrumPHP/Task/PhpcsfixerSpec.php | 28 +++-- spec/GrumPHP/Task/PhpspecSpec.php | 17 +-- spec/GrumPHP/Task/PhpunitSpec.php | 17 +-- src/GrumPHP/Collection/TasksCollection.php | 28 +++++ src/GrumPHP/Console/Application.php | 3 + .../Console/Command/Git/PreCommitCommand.php | 35 +++--- src/GrumPHP/Console/Helper/PathsHelper.php | 6 +- .../Console/Helper/TaskRunnerHelper.php | 106 ++++++++++++++++++ src/GrumPHP/Runner/TaskRunner.php | 35 +++--- src/GrumPHP/Task/Behat.php | 14 ++- src/GrumPHP/Task/Blacklist.php | 14 ++- src/GrumPHP/Task/Context/ContextInterface.php | 19 ++++ .../Task/Context/GitPreCommitContext.php | 35 ++++++ src/GrumPHP/Task/Phpcs.php | 14 ++- src/GrumPHP/Task/Phpcsfixer.php | 14 ++- src/GrumPHP/Task/Phpspec.php | 14 ++- src/GrumPHP/Task/Phpunit.php | 14 ++- src/GrumPHP/Task/TaskInterface.php | 15 ++- 25 files changed, 537 insertions(+), 156 deletions(-) create mode 100644 spec/GrumPHP/Collection/TasksCollectionSpec.php create mode 100644 spec/GrumPHP/Console/Helper/TaskRunnerHelperSpec.php create mode 100644 spec/GrumPHP/Task/Context/GitPreCommitContextSpec.php create mode 100644 src/GrumPHP/Collection/TasksCollection.php create mode 100644 src/GrumPHP/Console/Helper/TaskRunnerHelper.php create mode 100644 src/GrumPHP/Task/Context/ContextInterface.php create mode 100644 src/GrumPHP/Task/Context/GitPreCommitContext.php diff --git a/spec/GrumPHP/Collection/TasksCollectionSpec.php b/spec/GrumPHP/Collection/TasksCollectionSpec.php new file mode 100644 index 000000000..3f071fd6a --- /dev/null +++ b/spec/GrumPHP/Collection/TasksCollectionSpec.php @@ -0,0 +1,40 @@ +beConstructedWith(array($task1, $task2)); + } + + function it_is_initializable() + { + $this->shouldHaveType('GrumPHP\Collection\TasksCollection'); + } + + function it_is_an_array_collection() + { + $this->shouldHaveType('Doctrine\Common\Collections\ArrayCollection'); + } + + function it_should_filter_by_context(TaskInterface $task1, TaskInterface $task2, ContextInterface $context) + { + $task1->canRunInContext($context)->willReturn(true); + $task2->canRunInContext($context)->willReturn(false); + + $result = $this->filterByContext($context); + $result->shouldBeAnInstanceOf('GrumPHP\Collection\TasksCollection'); + $result->count()->shouldBe(1); + $tasks = $result->toArray(); + $tasks[0]->shouldBe($task1); + } + +} diff --git a/spec/GrumPHP/Console/Helper/TaskRunnerHelperSpec.php b/spec/GrumPHP/Console/Helper/TaskRunnerHelperSpec.php new file mode 100644 index 000000000..396300bff --- /dev/null +++ b/spec/GrumPHP/Console/Helper/TaskRunnerHelperSpec.php @@ -0,0 +1,38 @@ +beConstructedWith($taskRunner); + + $helperSet->get(PathsHelper::HELPER_NAME)->willreturn($pathsHelper); + $this->setHelperSet($helperSet); + } + + function it_should_return_error_code_during_exceptions(OutputInterface $output, TaskRunner $taskRunner, ContextInterface $context) + { + $taskRunner->run($context)->willThrow(new FailureException()); + $this->run($output, $context)->shouldReturn(TaskRunnerHelper::CODE_ERROR); + } + + function it_should_return_success_code_during_exceptions(OutputInterface $output, TaskRunner $taskRunner, ContextInterface $context) + { + $taskRunner->run($context)->shouldBeCalled(); + $this->run($output, $context)->shouldReturn(TaskRunnerHelper::CODE_SUCCESS); + } +} diff --git a/spec/GrumPHP/Runner/TaskRunnerSpec.php b/spec/GrumPHP/Runner/TaskRunnerSpec.php index 5c67a2032..9470daf04 100644 --- a/spec/GrumPHP/Runner/TaskRunnerSpec.php +++ b/spec/GrumPHP/Runner/TaskRunnerSpec.php @@ -3,6 +3,7 @@ namespace spec\GrumPHP\Runner; use GrumPHP\Collection\FilesCollection; +use GrumPHP\Task\Context\ContextInterface; use GrumPHP\Task\TaskInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; @@ -10,11 +11,13 @@ class TaskRunnerSpec extends ObjectBehavior { - protected $files; - - public function let() + public function let(TaskInterface $task1, TaskInterface $task2, ContextInterface $context) { - $this->files = new FilesCollection(); + $task1->canRunInContext($context)->willReturn(true); + $task2->canRunInContext($context)->willReturn(true); + + $this->addTask($task1); + $this->addTask($task2); } function it_is_initializable() @@ -24,49 +27,40 @@ function it_is_initializable() function it_holds_tasks(TaskInterface $task1, TaskInterface $task2) { - $this->addTask($task1); - $this->addTask($task2); - - $this->getTasks()->shouldEqual(array($task1, $task2)); + $this->getTasks()->toArray()->shouldEqual(array($task1, $task2)); } function it_does_not_add_the_same_task_twice(TaskInterface $task1, TaskInterface $task2) { $this->addTask($task1); - $this->addTask($task1); - $this->addTask($task2); - $this->getTasks()->shouldEqual(array($task1, $task2)); + $this->getTasks()->toArray()->shouldEqual(array($task1, $task2)); } - function it_runs_all_tasks(TaskInterface $task1, TaskInterface $task2) + function it_runs_all_tasks(TaskInterface $task1, TaskInterface $task2, ContextInterface $context) { - $this->addTask($task1); - $this->addTask($task2); - - $task1->run($this->files)->shouldBeCalled(); - $task2->run($this->files)->shouldBeCalled(); + $task1->run($context)->shouldBeCalled(); + $task2->run($context)->shouldBeCalled(); - $this->run($this->files); + $this->run($context); } - function it_throws_exception_if_task_fails(TaskInterface $task1) + function it_throws_exception_if_task_fails(TaskInterface $task1, TaskInterface $task2, ContextInterface $context) { - $this->addTask($task1); - - $task1->run($this->files)->willThrow('GrumPHP\Exception\RuntimeException'); + $task1->run($context)->willThrow('GrumPHP\Exception\RuntimeException'); + $task2->run($context)->shouldBeCalled(); - $this->shouldThrow('GrumPHP\Exception\FailureException')->duringRun($this->files); + $this->shouldThrow('GrumPHP\Exception\FailureException')->duringRun($context); } - function it_runs_subsequent_tasks_if_one_fails(TaskInterface $task1, TaskInterface $task2) - { - $this->addTask($task1); - $this->addTask($task2); - - $task1->run($this->files)->willThrow('GrumPHP\Exception\RuntimeException'); - $task2->run($this->files)->shouldBeCalled(); + function it_runs_subsequent_tasks_if_one_fails( + TaskInterface $task1, + TaskInterface $task2, + ContextInterface $context + ) { + $task1->run($context)->willThrow('GrumPHP\Exception\RuntimeException'); + $task2->run($context)->shouldBeCalled(); - $this->shouldThrow('GrumPHP\Exception\FailureException')->duringRun($this->files); + $this->shouldThrow('GrumPHP\Exception\FailureException')->duringRun($context); } } diff --git a/spec/GrumPHP/Task/BehatSpec.php b/spec/GrumPHP/Task/BehatSpec.php index 1d94302a8..8deded50b 100644 --- a/spec/GrumPHP/Task/BehatSpec.php +++ b/spec/GrumPHP/Task/BehatSpec.php @@ -5,6 +5,7 @@ use GrumPHP\Collection\FilesCollection; use GrumPHP\Configuration\GrumPHP; use GrumPHP\Locator\LocatorInterface; +use GrumPHP\Task\Context\ContextInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Symfony\Component\Process\Process; @@ -34,17 +35,17 @@ function it_uses_its_external_command_locator_to_find_correct_command(LocatorInt $this->getCommandLocation(); } - function it_does_not_do_anything_if_there_are_no_files(ProcessBuilder $processBuilder) + function it_does_not_do_anything_if_there_are_no_files(ProcessBuilder $processBuilder, ContextInterface $context) { $processBuilder->add(Argument::any())->shouldNotBeCalled(); $processBuilder->setArguments(Argument::any())->shouldNotBeCalled(); $processBuilder->getProcess()->shouldNotBeCalled(); - $files = new FilesCollection(); - $this->run($files)->shouldBeNull(); + $context->getFiles()->willReturn(new FilesCollection()); + $this->run($context)->shouldBeNull(); } - function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process) + function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process, ContextInterface $context) { $processBuilder->setArguments(Argument::type('array'))->shouldBeCalled(); $processBuilder->getProcess()->willReturn($process); @@ -52,14 +53,17 @@ function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process) $process->run()->shouldBeCalled(); $process->isSuccessful()->willReturn(true); - $files = new FilesCollection(array( + $context->getFiles()->willReturn(new FilesCollection(array( new SplFileInfo('test.php') - )); - $this->run($files); + ))); + $this->run($context); } - function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder, Process $process) - { + function it_throws_exception_if_the_process_fails( + ProcessBuilder $processBuilder, + Process $process, + ContextInterface $context + ) { $processBuilder->setArguments(Argument::type('array'))->shouldBeCalled(); $processBuilder->getProcess()->willReturn($process); @@ -67,9 +71,9 @@ function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder $process->isSuccessful()->willReturn(false); $process->getOutput()->shouldBeCalled(); - $files = new FilesCollection(array( + $context->getFiles()->willReturn(new FilesCollection(array( new SplFileInfo('test.php') - )); - $this->shouldThrow('GrumPHP\Exception\RuntimeException')->duringRun($files); + ))); + $this->shouldThrow('GrumPHP\Exception\RuntimeException')->duringRun($context); } } diff --git a/spec/GrumPHP/Task/BlacklistSpec.php b/spec/GrumPHP/Task/BlacklistSpec.php index e6b40a7d5..bc2ca64b7 100644 --- a/spec/GrumPHP/Task/BlacklistSpec.php +++ b/spec/GrumPHP/Task/BlacklistSpec.php @@ -5,6 +5,7 @@ use GrumPHP\Collection\FilesCollection; use GrumPHP\Configuration\GrumPHP; use GrumPHP\Locator\LocatorInterface; +use GrumPHP\Task\Context\ContextInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Symfony\Component\Process\Process; @@ -35,31 +36,36 @@ function it_uses_its_external_command_locator_to_find_correct_command(LocatorInt $this->getCommandLocation(); } - function it_does_not_do_anything_if_there_are_no_files(ProcessBuilder $processBuilder) + function it_does_not_do_anything_if_there_are_no_files(ProcessBuilder $processBuilder, ContextInterface $context) { $processBuilder->add(Argument::any())->shouldNotBeCalled(); $processBuilder->setArguments(Argument::any())->shouldNotBeCalled(); $processBuilder->getProcess()->shouldNotBeCalled(); - $files = new FilesCollection(); - $this->run($files)->shouldBeNull(); + $context->getFiles()->willReturn(new FilesCollection()); + $this->run($context)->shouldBeNull(); } - function it_does_not_do_anything_if_there_are_no_keywords(ProcessBuilder $processBuilder) + function it_does_not_do_anything_if_there_are_no_keywords(ProcessBuilder $processBuilder, ContextInterface $context) { $processBuilder->add(Argument::any())->shouldNotBeCalled(); $processBuilder->setArguments(Argument::any())->shouldNotBeCalled(); $processBuilder->getProcess()->shouldNotBeCalled(); - $files = new FilesCollection(array( + $context->getFiles()->willReturn(new FilesCollection(array( new SplFileInfo('file1.php'), - )); + ))); - $this->run($files)->shouldBeNull(); + $this->run($context)->shouldBeNull(); } - function it_runs_the_suite(GrumPHP $grumPHP, LocatorInterface $externalCommandLocator, ProcessBuilder $processBuilder, Process $process) - { + function it_runs_the_suite( + GrumPHP $grumPHP, + LocatorInterface $externalCommandLocator, + ProcessBuilder $processBuilder, + Process $process, + ContextInterface $context + ) { $this->beConstructedWith($grumPHP, array('keywords'=>array('var_dump(', 'die(')), $externalCommandLocator, $processBuilder); $processBuilder->setArguments(Argument::type('array'))->shouldBeCalled(); @@ -73,14 +79,19 @@ function it_runs_the_suite(GrumPHP $grumPHP, LocatorInterface $externalCommandLo // Assume that blacklisted keywords was not found by `git grep` process $process->isSuccessful()->willReturn(false); - $files = new FilesCollection(array( + $context->getFiles()->willReturn(new FilesCollection(array( new SplFileInfo('file1.php'), - )); - $this->run($files); + ))); + $this->run($context); } - function it_throws_exception_if_the_process_is_successfull(GrumPHP $grumPHP, LocatorInterface $externalCommandLocator, ProcessBuilder $processBuilder, Process $process) - { + function it_throws_exception_if_the_process_is_successfull( + GrumPHP $grumPHP, + LocatorInterface $externalCommandLocator, + ProcessBuilder $processBuilder, + Process $process, + ContextInterface $context + ) { $this->beConstructedWith($grumPHP, array('keywords'=>array('var_dump(')), $externalCommandLocator, $processBuilder); $processBuilder->setArguments(Argument::type('array'))->shouldBeCalled(); @@ -92,9 +103,9 @@ function it_throws_exception_if_the_process_is_successfull(GrumPHP $grumPHP, Loc $process->isSuccessful()->willReturn(true); $process->getOutput()->shouldBeCalled(); - $files = new FilesCollection(array( + $context->getFiles()->willReturn(new FilesCollection(array( new SplFileInfo('file1.php'), - )); - $this->shouldThrow('GrumPHP\Exception\RuntimeException')->duringRun($files); + ))); + $this->shouldThrow('GrumPHP\Exception\RuntimeException')->duringRun($context); } } diff --git a/spec/GrumPHP/Task/Context/GitPreCommitContextSpec.php b/spec/GrumPHP/Task/Context/GitPreCommitContextSpec.php new file mode 100644 index 000000000..1b7a27118 --- /dev/null +++ b/spec/GrumPHP/Task/Context/GitPreCommitContextSpec.php @@ -0,0 +1,30 @@ +beConstructedWith($files); + } + + function it_is_initializable() + { + $this->shouldHaveType('GrumPHP\Task\Context\GitPreCommitContext'); + } + + function it_should_be_a_task_context() + { + $this->shouldImplement('GrumPHP\Task\Context\ContextInterface'); + } + + function it_should_have_files(FilesCollection $files) + { + $this->getFiles()->shouldBe($files); + } +} diff --git a/spec/GrumPHP/Task/PhpcsSpec.php b/spec/GrumPHP/Task/PhpcsSpec.php index 14cca4dd4..5b14960cb 100644 --- a/spec/GrumPHP/Task/PhpcsSpec.php +++ b/spec/GrumPHP/Task/PhpcsSpec.php @@ -5,6 +5,7 @@ use GrumPHP\Collection\FilesCollection; use GrumPHP\Configuration\GrumPHP; use GrumPHP\Locator\LocatorInterface; +use GrumPHP\Task\Context\ContextInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Symfony\Component\Process\Process; @@ -35,17 +36,17 @@ function it_uses_its_external_command_locator_to_find_correct_command(LocatorInt $this->getCommandLocation(); } - function it_does_not_do_anything_if_there_are_no_files(ProcessBuilder $processBuilder) + function it_does_not_do_anything_if_there_are_no_files(ProcessBuilder $processBuilder, ContextInterface $context) { $processBuilder->add(Argument::any())->shouldNotBeCalled(); $processBuilder->setArguments(Argument::any())->shouldNotBeCalled(); $processBuilder->getProcess()->shouldNotBeCalled(); - $files = new FilesCollection(); - $this->run($files)->shouldBeNull(); + $context->getFiles()->willReturn(new FilesCollection()); + $this->run($context)->shouldBeNull(); } - function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process) + function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process, ContextInterface $context) { $processBuilder->add('file1.php')->shouldBeCalled(); $processBuilder->add('file2.php')->shouldBeCalled(); @@ -55,15 +56,18 @@ function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process) $process->run()->shouldBeCalled(); $process->isSuccessful()->willReturn(true); - $files = new FilesCollection(array( + $context->getFiles()->willReturn(new FilesCollection(array( new SplFileInfo('file1.php'), new SplFileInfo('file2.php'), - )); - $this->run($files); + ))); + $this->run($context); } - function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder, Process $process) - { + function it_throws_exception_if_the_process_fails( + ProcessBuilder $processBuilder, + Process $process, + ContextInterface $context + ) { $processBuilder->add('file1.php')->shouldBeCalled(); $processBuilder->setArguments(Argument::type('array'))->shouldBeCalled(); $processBuilder->getProcess()->willReturn($process); @@ -72,9 +76,9 @@ function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder $process->isSuccessful()->willReturn(false); $process->getOutput()->shouldBeCalled(); - $files = new FilesCollection(array( + $context->getFiles()->willReturn(new FilesCollection(array( new SplFileInfo('file1.php'), - )); - $this->shouldThrow('GrumPHP\Exception\RuntimeException')->duringRun($files); + ))); + $this->shouldThrow('GrumPHP\Exception\RuntimeException')->duringRun($context); } } diff --git a/spec/GrumPHP/Task/PhpcsfixerSpec.php b/spec/GrumPHP/Task/PhpcsfixerSpec.php index d86785ab7..3ae2653a3 100644 --- a/spec/GrumPHP/Task/PhpcsfixerSpec.php +++ b/spec/GrumPHP/Task/PhpcsfixerSpec.php @@ -5,6 +5,7 @@ use GrumPHP\Collection\FilesCollection; use GrumPHP\Configuration\GrumPHP; use GrumPHP\Locator\LocatorInterface; +use GrumPHP\Task\Context\ContextInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Symfony\Component\Process\Process; @@ -35,17 +36,17 @@ function it_uses_its_external_command_locator_to_find_correct_command(LocatorInt $this->getCommandLocation(); } - function it_does_not_do_anything_if_there_are_no_files(ProcessBuilder $processBuilder) + function it_does_not_do_anything_if_there_are_no_files(ProcessBuilder $processBuilder, ContextInterface $context) { $processBuilder->add(Argument::any())->shouldNotBeCalled(); $processBuilder->setArguments(Argument::any())->shouldNotBeCalled(); $processBuilder->getProcess()->shouldNotBeCalled(); - $files = new FilesCollection(); - $this->run($files)->shouldBeNull(); + $context->getFiles()->willReturn(new FilesCollection()); + $this->run($context)->shouldBeNull(); } - function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process) + function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process, ContextInterface $context) { $processBuilder->add('--config=default')->shouldBeCalled(); $processBuilder->add('--verbose')->shouldBeCalled(); @@ -58,15 +59,18 @@ function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process) $process->run()->shouldBeCalled(); $process->isSuccessful()->willReturn(true); - $files = new FilesCollection(array( + $context->getFiles()->willReturn(new FilesCollection(array( new SplFileInfo('file1.php'), new SplFileInfo('file2.php'), - )); - $this->run($files); + ))); + $this->run($context); } - function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder, Process $process) - { + function it_throws_exception_if_the_process_fails( + ProcessBuilder $processBuilder, + Process $process, + ContextInterface $context + ) { $processBuilder->add('--config=default')->shouldBeCalled(); $processBuilder->add('--verbose')->shouldBeCalled(); $processBuilder->add('fix')->shouldBeCalled(); @@ -78,9 +82,9 @@ function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder $process->run()->shouldBeCalled(); $process->isSuccessful()->willReturn(false); - $files = new FilesCollection(array( + $context->getFiles()->willReturn(new FilesCollection(array( new SplFileInfo('file1.php'), - )); - $this->shouldThrow('GrumPHP\Exception\RuntimeException')->duringRun($files); + ))); + $this->shouldThrow('GrumPHP\Exception\RuntimeException')->duringRun($context); } } diff --git a/spec/GrumPHP/Task/PhpspecSpec.php b/spec/GrumPHP/Task/PhpspecSpec.php index 627fa5550..6c8afd24e 100644 --- a/spec/GrumPHP/Task/PhpspecSpec.php +++ b/spec/GrumPHP/Task/PhpspecSpec.php @@ -5,6 +5,7 @@ use GrumPHP\Collection\FilesCollection; use GrumPHP\Configuration\GrumPHP; use GrumPHP\Locator\LocatorInterface; +use GrumPHP\Task\Context\ContextInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Symfony\Component\Process\Process; @@ -35,7 +36,7 @@ function it_uses_its_external_command_locator_to_find_correct_command(LocatorInt $this->getCommandLocation(); } - function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process) + function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process, ContextInterface $context) { $processBuilder->setArguments(Argument::type('array'))->shouldBeCalled(); $processBuilder->getProcess()->willReturn($process); @@ -43,13 +44,13 @@ function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process) $process->run()->shouldBeCalled(); $process->isSuccessful()->willReturn(true); - $files = new FilesCollection(array( + $context->getFiles()->willReturn(new FilesCollection(array( new SplFileInfo('test.php') - )); - $this->run($files); + ))); + $this->run($context); } - function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder, Process $process) + function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder, Process $process, ContextInterface $context) { $processBuilder->setArguments(Argument::type('array'))->shouldBeCalled(); $processBuilder->getProcess()->willReturn($process); @@ -58,9 +59,9 @@ function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder $process->isSuccessful()->willReturn(false); $process->getOutput()->shouldBeCalled(); - $files = new FilesCollection(array( + $context->getFiles()->willReturn(new FilesCollection(array( new SplFileInfo('test.php') - )); - $this->shouldThrow('GrumPHP\Exception\RuntimeException')->duringRun($files); + ))); + $this->shouldThrow('GrumPHP\Exception\RuntimeException')->duringRun($context); } } diff --git a/spec/GrumPHP/Task/PhpunitSpec.php b/spec/GrumPHP/Task/PhpunitSpec.php index ac021af0a..1ecc364c3 100644 --- a/spec/GrumPHP/Task/PhpunitSpec.php +++ b/spec/GrumPHP/Task/PhpunitSpec.php @@ -5,6 +5,7 @@ use GrumPHP\Collection\FilesCollection; use GrumPHP\Configuration\GrumPHP; use GrumPHP\Locator\LocatorInterface; +use GrumPHP\Task\Context\ContextInterface; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Symfony\Component\Process\Process; @@ -34,7 +35,7 @@ function it_uses_its_external_command_locator_to_find_correct_command(LocatorInt $this->getCommandLocation(); } - function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process) + function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process, ContextInterface $context) { $processBuilder->setArguments(Argument::type('array'))->shouldBeCalled(); $processBuilder->getProcess()->willReturn($process); @@ -42,13 +43,13 @@ function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process) $process->run()->shouldBeCalled(); $process->isSuccessful()->willReturn(true); - $files = new FilesCollection(array( + $context->getFiles()->willReturn(new FilesCollection(array( new SplFileInfo('test.php') - )); - $this->run($files); + ))); + $this->run($context); } - function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder, Process $process) + function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder, Process $process, ContextInterface $context) { $processBuilder->setArguments(Argument::type('array'))->shouldBeCalled(); $processBuilder->getProcess()->willReturn($process); @@ -57,9 +58,9 @@ function it_throws_exception_if_the_process_fails(ProcessBuilder $processBuilder $process->isSuccessful()->willReturn(false); $process->getOutput()->shouldBeCalled(); - $files = new FilesCollection(array( + $context->getFiles()->willReturn(new FilesCollection(array( new SplFileInfo('test.php') - )); - $this->shouldThrow('GrumPHP\Exception\RuntimeException')->duringRun($files); + ))); + $this->shouldThrow('GrumPHP\Exception\RuntimeException')->duringRun($context); } } diff --git a/src/GrumPHP/Collection/TasksCollection.php b/src/GrumPHP/Collection/TasksCollection.php new file mode 100644 index 000000000..0e30b7e93 --- /dev/null +++ b/src/GrumPHP/Collection/TasksCollection.php @@ -0,0 +1,28 @@ +filter(function (TaskInterface $task) use ($context) { + return $task->canRunInContext($context); + }); + } +} diff --git a/src/GrumPHP/Console/Application.php b/src/GrumPHP/Console/Application.php index 8378d5f3d..ad5233232 100644 --- a/src/GrumPHP/Console/Application.php +++ b/src/GrumPHP/Console/Application.php @@ -116,6 +116,9 @@ protected function getDefaultHelperSet() $container->get('config'), $container->get('filesystem') )); + $helperSet->set(new Helper\TaskRunnerHelper( + $container->get('task_runner') + )); return $helperSet; } diff --git a/src/GrumPHP/Console/Command/Git/PreCommitCommand.php b/src/GrumPHP/Console/Command/Git/PreCommitCommand.php index b8c0e151a..58b0dca73 100644 --- a/src/GrumPHP/Console/Command/Git/PreCommitCommand.php +++ b/src/GrumPHP/Console/Command/Git/PreCommitCommand.php @@ -5,9 +5,10 @@ use GrumPHP\Collection\FilesCollection; use GrumPHP\Configuration\GrumPHP; use GrumPHP\Console\Helper\PathsHelper; -use GrumPHP\Exception\ExceptionInterface; +use GrumPHP\Console\Helper\TaskRunnerHelper; use GrumPHP\Locator\LocatorInterface; use GrumPHP\Runner\TaskRunner; +use GrumPHP\Task\Context\GitPreCommitContext; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -64,29 +65,11 @@ protected function configure() */ public function execute(InputInterface $input, OutputInterface $output) { - try { - $this->taskRunner->run($this->getCommittedFiles()); - } catch (ExceptionInterface $e) { - // We'll fail hard on any exception not generated in GrumPHP - $failed = $this->paths()->getAsciiContent('failed'); - if ($failed) { - $output->writeln('' . $failed . ''); - } - $output->writeln('' . $e->getMessage() . ''); - $output->writeln( - 'To skip commit checks, add -n or --no-verify flag to commit command' - ); + $files = $this->getCommittedFiles(); + $context = new GitPreCommitContext($files); - return 1; - } - - $succeeded = $this->paths()->getAsciiContent('succeeded'); - if ($succeeded) { - $output->write('' . $succeeded . ''); - } - - return 0; + $this->taskRunner()->run($output, $context); } /** @@ -97,6 +80,14 @@ protected function getCommittedFiles() return $this->changedFilesLocator->locate(); } + /** + * @return TaskRunnerHelper + */ + protected function taskRunner() + { + return $this->getHelper(TaskRunnerHelper::HELPER_NAME); + } + /** * @return PathsHelper */ diff --git a/src/GrumPHP/Console/Helper/PathsHelper.php b/src/GrumPHP/Console/Helper/PathsHelper.php index 8e8747d48..f8731026e 100644 --- a/src/GrumPHP/Console/Helper/PathsHelper.php +++ b/src/GrumPHP/Console/Helper/PathsHelper.php @@ -209,11 +209,7 @@ public function getRelativePath($path) } /** - * Returns the canonical name of this helper. - * - * @return string The canonical name - * - * @api + * {@inheritdoc} */ public function getName() { diff --git a/src/GrumPHP/Console/Helper/TaskRunnerHelper.php b/src/GrumPHP/Console/Helper/TaskRunnerHelper.php new file mode 100644 index 000000000..2bd701175 --- /dev/null +++ b/src/GrumPHP/Console/Helper/TaskRunnerHelper.php @@ -0,0 +1,106 @@ +taskRunner = $taskRunner; + } + + /** + * @return PathsHelper + */ + private function paths() + { + return $this->getHelperSet()->get(PathsHelper::HELPER_NAME); + } + + /** + * @param ContextInterface $context + * + * @return int + */ + public function run(OutputInterface $output, ContextInterface $context) + { + try { + $this->taskRunner->run($context); + } catch (ExceptionInterface $e) { + // We'll fail hard on any exception not generated in GrumPHP + + return $this->returnErrorMessage($output, $e->getMessage()); + } + + return $this->returnSuccessMessage($output); + + } + + /** + * @param OutputInterface $output + * @param string $errorMessage + * + * @return int + */ + private function returnErrorMessage(OutputInterface $output, $errorMessage) + { + $failed = $this->paths()->getAsciiContent('failed'); + if ($failed) { + $output->writeln('' . $failed . ''); + } + + $output->writeln('' . $errorMessage . ''); + $output->writeln( + 'To skip commit checks, add -n or --no-verify flag to commit command' + ); + + return self::CODE_ERROR; + } + + /** + * @param OutputInterface $output + * + * @return int + */ + private function returnSuccessMessage(OutputInterface $output) + { + $succeeded = $this->paths()->getAsciiContent('succeeded'); + if ($succeeded) { + $output->write('' . $succeeded . ''); + } + + return self::CODE_SUCCESS; + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return self::HELPER_NAME; + } +} diff --git a/src/GrumPHP/Runner/TaskRunner.php b/src/GrumPHP/Runner/TaskRunner.php index aef7895df..0d3845ae5 100644 --- a/src/GrumPHP/Runner/TaskRunner.php +++ b/src/GrumPHP/Runner/TaskRunner.php @@ -3,8 +3,10 @@ namespace GrumPHP\Runner; use GrumPHP\Collection\FilesCollection; +use GrumPHP\Collection\TasksCollection; use GrumPHP\Exception\FailureException; use GrumPHP\Exception\RuntimeException; +use GrumPHP\Task\Context\ContextInterface; use GrumPHP\Task\TaskInterface; /** @@ -15,28 +17,32 @@ class TaskRunner { /** - * @var TaskInterface[] + * @var TasksCollection|TaskInterface[] */ - protected $tasks = array(); + protected $tasks; + + /** + * @constructor + */ + public function __construct() + { + $this->tasks = new TasksCollection(); + } /** * @param TaskInterface $task - * - * @return $this */ public function addTask(TaskInterface $task) { - if (in_array($task, $this->tasks)) { - return $this; + if ($this->tasks->contains($task)) { + return; } - $this->tasks[] = $task; - - return $this; + $this->tasks->add($task); } /** - * @return TaskInterface[] + * @return TasksCollection|TaskInterface[] */ public function getTasks() { @@ -44,18 +50,19 @@ public function getTasks() } /** - * @param FilesCollection $files + * @param ContextInterface $context * * @throws FailureException if any of the tasks fail */ - public function run(FilesCollection $files) + public function run(ContextInterface $context) { $failures = false; $messages = array(); - foreach ($this->getTasks() as $task) { + $tasks = $this->tasks->filterByContext($context); + foreach ($tasks as $task) { try { - $task->run($files); + $task->run($context); } catch (RuntimeException $e) { $failures = true; $messages[] = $e->getMessage(); diff --git a/src/GrumPHP/Task/Behat.php b/src/GrumPHP/Task/Behat.php index 499e8ddc7..2997b3410 100644 --- a/src/GrumPHP/Task/Behat.php +++ b/src/GrumPHP/Task/Behat.php @@ -4,6 +4,8 @@ use GrumPHP\Collection\FilesCollection; use GrumPHP\Exception\RuntimeException; +use GrumPHP\Task\Context\ContextInterface; +use GrumPHP\Task\Context\GitPreCommitContext; /** * Behat task @@ -36,9 +38,17 @@ public function getDefaultConfiguration() /** * {@inheritdoc} */ - public function run(FilesCollection $files) + public function canRunInContext(ContextInterface $context) { - $files = $files->name('*.php'); + return ($context instanceof GitPreCommitContext); + } + + /** + * {@inheritdoc} + */ + public function run(ContextInterface $context) + { + $files = $context->getFiles()->name('*.php'); if (0 === count($files)) { return; } diff --git a/src/GrumPHP/Task/Blacklist.php b/src/GrumPHP/Task/Blacklist.php index fb2030b42..bce48447d 100644 --- a/src/GrumPHP/Task/Blacklist.php +++ b/src/GrumPHP/Task/Blacklist.php @@ -4,6 +4,8 @@ use GrumPHP\Collection\FilesCollection; use GrumPHP\Exception\RuntimeException; +use GrumPHP\Task\Context\ContextInterface; +use GrumPHP\Task\Context\GitPreCommitContext; /** * Blacklist task @@ -35,9 +37,17 @@ public function getCommandLocation() /** * {@inheritdoc} */ - public function run(FilesCollection $files) + public function canRunInContext(ContextInterface $context) { - $files = $files->name('*.php'); + return ($context instanceof GitPreCommitContext); + } + + /** + * {@inheritdoc} + */ + public function run(ContextInterface $context) + { + $files = $context->getFiles()->name('*.php'); if (0 === count($files)) { return; } diff --git a/src/GrumPHP/Task/Context/ContextInterface.php b/src/GrumPHP/Task/Context/ContextInterface.php new file mode 100644 index 000000000..4ab18ea4a --- /dev/null +++ b/src/GrumPHP/Task/Context/ContextInterface.php @@ -0,0 +1,19 @@ +files = $files; + } + + /** + * @return FilesCollection + */ + public function getFiles() + { + return $this->files; + } +} diff --git a/src/GrumPHP/Task/Phpcs.php b/src/GrumPHP/Task/Phpcs.php index 7b78d4bdb..38667028c 100644 --- a/src/GrumPHP/Task/Phpcs.php +++ b/src/GrumPHP/Task/Phpcs.php @@ -4,6 +4,8 @@ use GrumPHP\Collection\FilesCollection; use GrumPHP\Exception\RuntimeException; +use GrumPHP\Task\Context\ContextInterface; +use GrumPHP\Task\Context\GitPreCommitContext; /** * Phpcs task @@ -37,9 +39,17 @@ public function getCommandLocation() /** * {@inheritdoc} */ - public function run(FilesCollection $files) + public function canRunInContext(ContextInterface $context) { - $files = $files->name('*.php'); + return ($context instanceof GitPreCommitContext); + } + + /** + * {@inheritdoc} + */ + public function run(ContextInterface $context) + { + $files = $context->getFiles()->name('*.php'); if (0 === count($files)) { return; } diff --git a/src/GrumPHP/Task/Phpcsfixer.php b/src/GrumPHP/Task/Phpcsfixer.php index 7e3335676..51e1551aa 100644 --- a/src/GrumPHP/Task/Phpcsfixer.php +++ b/src/GrumPHP/Task/Phpcsfixer.php @@ -4,6 +4,8 @@ use GrumPHP\Collection\FilesCollection; use GrumPHP\Exception\RuntimeException; +use GrumPHP\Task\Context\ContextInterface; +use GrumPHP\Task\Context\GitPreCommitContext; /** * Php-cs-fixer task @@ -37,9 +39,17 @@ public function getCommandLocation() /** * {@inheritdoc} */ - public function run(FilesCollection $files) + public function canRunInContext(ContextInterface $context) { - $files = $files->name('*.php'); + return ($context instanceof GitPreCommitContext); + } + + /** + * {@inheritdoc} + */ + public function run(ContextInterface $context) + { + $files = $context->getFiles()->name('*.php'); if (0 === count($files)) { return; } diff --git a/src/GrumPHP/Task/Phpspec.php b/src/GrumPHP/Task/Phpspec.php index f336eff19..ee5cbf6e0 100644 --- a/src/GrumPHP/Task/Phpspec.php +++ b/src/GrumPHP/Task/Phpspec.php @@ -4,6 +4,8 @@ use GrumPHP\Collection\FilesCollection; use GrumPHP\Exception\RuntimeException; +use GrumPHP\Task\Context\ContextInterface; +use GrumPHP\Task\Context\GitPreCommitContext; /** * Phpspec task @@ -34,9 +36,17 @@ public function getDefaultConfiguration() /** * {@inheritdoc} */ - public function run(FilesCollection $files) + public function canRunInContext(ContextInterface $context) { - $files = $files->name('*.php'); + return ($context instanceof GitPreCommitContext); + } + + /** + * {@inheritdoc} + */ + public function run(ContextInterface $context) + { + $files = $context->getFiles()->name('*.php'); if (0 === count($files)) { return; } diff --git a/src/GrumPHP/Task/Phpunit.php b/src/GrumPHP/Task/Phpunit.php index c47408136..910e149d0 100644 --- a/src/GrumPHP/Task/Phpunit.php +++ b/src/GrumPHP/Task/Phpunit.php @@ -4,6 +4,8 @@ use GrumPHP\Collection\FilesCollection; use GrumPHP\Exception\RuntimeException; +use GrumPHP\Task\Context\ContextInterface; +use GrumPHP\Task\Context\GitPreCommitContext; /** * Phpunit task @@ -33,9 +35,17 @@ public function getDefaultConfiguration() /** * {@inheritdoc} */ - public function run(FilesCollection $files) + public function canRunInContext(ContextInterface $context) { - $files = $files->name('*.php'); + return ($context instanceof GitPreCommitContext); + } + + /** + * {@inheritdoc} + */ + public function run(ContextInterface $context) + { + $files = $context->getFiles()->name('*.php'); if (0 === count($files)) { return; } diff --git a/src/GrumPHP/Task/TaskInterface.php b/src/GrumPHP/Task/TaskInterface.php index 656231ca1..f11bb60b9 100644 --- a/src/GrumPHP/Task/TaskInterface.php +++ b/src/GrumPHP/Task/TaskInterface.php @@ -2,8 +2,8 @@ namespace GrumPHP\Task; -use GrumPHP\Collection\FilesCollection; use GrumPHP\Exception\RuntimeException; +use GrumPHP\Task\Context\ContextInterface; /** * Interface TaskInterface @@ -23,10 +23,19 @@ public function getConfiguration(); public function getDefaultConfiguration(); /** - * @param FilesCollection $files + * This methods specifies if a task can run in a specific context. + * + * @param ContextInterface $context + * + * @return bool + */ + public function canRunInContext(ContextInterface $context); + + /** + * @param ContextInterface $context * * @return void * @throws RuntimeException */ - public function run(FilesCollection $files); + public function run(ContextInterface $context); } From 345cf057d830c7e1d420c355ff98d10177bdac63 Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Wed, 16 Sep 2015 18:02:14 +0200 Subject: [PATCH 2/3] Check the contexts --- spec/GrumPHP/Task/BehatSpec.php | 6 ++++++ spec/GrumPHP/Task/BlacklistSpec.php | 6 ++++++ spec/GrumPHP/Task/PhpcsSpec.php | 6 ++++++ spec/GrumPHP/Task/PhpcsfixerSpec.php | 6 ++++++ spec/GrumPHP/Task/PhpspecSpec.php | 6 ++++++ spec/GrumPHP/Task/PhpunitSpec.php | 6 ++++++ 6 files changed, 36 insertions(+) diff --git a/spec/GrumPHP/Task/BehatSpec.php b/spec/GrumPHP/Task/BehatSpec.php index 8deded50b..c905f0d7e 100644 --- a/spec/GrumPHP/Task/BehatSpec.php +++ b/spec/GrumPHP/Task/BehatSpec.php @@ -6,6 +6,7 @@ use GrumPHP\Configuration\GrumPHP; use GrumPHP\Locator\LocatorInterface; use GrumPHP\Task\Context\ContextInterface; +use GrumPHP\Task\Context\GitPreCommitContext; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Symfony\Component\Process\Process; @@ -35,6 +36,11 @@ function it_uses_its_external_command_locator_to_find_correct_command(LocatorInt $this->getCommandLocation(); } + function it_should_run_in_git_pre_commit_context(GitPreCommitContext $context) + { + $this->canRunInContext($context)->shouldReturn(true); + } + function it_does_not_do_anything_if_there_are_no_files(ProcessBuilder $processBuilder, ContextInterface $context) { $processBuilder->add(Argument::any())->shouldNotBeCalled(); diff --git a/spec/GrumPHP/Task/BlacklistSpec.php b/spec/GrumPHP/Task/BlacklistSpec.php index bc2ca64b7..a94b7da58 100644 --- a/spec/GrumPHP/Task/BlacklistSpec.php +++ b/spec/GrumPHP/Task/BlacklistSpec.php @@ -6,6 +6,7 @@ use GrumPHP\Configuration\GrumPHP; use GrumPHP\Locator\LocatorInterface; use GrumPHP\Task\Context\ContextInterface; +use GrumPHP\Task\Context\GitPreCommitContext; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Symfony\Component\Process\Process; @@ -36,6 +37,11 @@ function it_uses_its_external_command_locator_to_find_correct_command(LocatorInt $this->getCommandLocation(); } + function it_should_run_in_git_pre_commit_context(GitPreCommitContext $context) + { + $this->canRunInContext($context)->shouldReturn(true); + } + function it_does_not_do_anything_if_there_are_no_files(ProcessBuilder $processBuilder, ContextInterface $context) { $processBuilder->add(Argument::any())->shouldNotBeCalled(); diff --git a/spec/GrumPHP/Task/PhpcsSpec.php b/spec/GrumPHP/Task/PhpcsSpec.php index 5b14960cb..3c618ed2c 100644 --- a/spec/GrumPHP/Task/PhpcsSpec.php +++ b/spec/GrumPHP/Task/PhpcsSpec.php @@ -6,6 +6,7 @@ use GrumPHP\Configuration\GrumPHP; use GrumPHP\Locator\LocatorInterface; use GrumPHP\Task\Context\ContextInterface; +use GrumPHP\Task\Context\GitPreCommitContext; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Symfony\Component\Process\Process; @@ -36,6 +37,11 @@ function it_uses_its_external_command_locator_to_find_correct_command(LocatorInt $this->getCommandLocation(); } + function it_should_run_in_git_pre_commit_context(GitPreCommitContext $context) + { + $this->canRunInContext($context)->shouldReturn(true); + } + function it_does_not_do_anything_if_there_are_no_files(ProcessBuilder $processBuilder, ContextInterface $context) { $processBuilder->add(Argument::any())->shouldNotBeCalled(); diff --git a/spec/GrumPHP/Task/PhpcsfixerSpec.php b/spec/GrumPHP/Task/PhpcsfixerSpec.php index 3ae2653a3..1561d5f5e 100644 --- a/spec/GrumPHP/Task/PhpcsfixerSpec.php +++ b/spec/GrumPHP/Task/PhpcsfixerSpec.php @@ -6,6 +6,7 @@ use GrumPHP\Configuration\GrumPHP; use GrumPHP\Locator\LocatorInterface; use GrumPHP\Task\Context\ContextInterface; +use GrumPHP\Task\Context\GitPreCommitContext; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Symfony\Component\Process\Process; @@ -46,6 +47,11 @@ function it_does_not_do_anything_if_there_are_no_files(ProcessBuilder $processBu $this->run($context)->shouldBeNull(); } + function it_should_run_in_git_pre_commit_context(GitPreCommitContext $context) + { + $this->canRunInContext($context)->shouldReturn(true); + } + function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process, ContextInterface $context) { $processBuilder->add('--config=default')->shouldBeCalled(); diff --git a/spec/GrumPHP/Task/PhpspecSpec.php b/spec/GrumPHP/Task/PhpspecSpec.php index 6c8afd24e..2a21e53e5 100644 --- a/spec/GrumPHP/Task/PhpspecSpec.php +++ b/spec/GrumPHP/Task/PhpspecSpec.php @@ -6,6 +6,7 @@ use GrumPHP\Configuration\GrumPHP; use GrumPHP\Locator\LocatorInterface; use GrumPHP\Task\Context\ContextInterface; +use GrumPHP\Task\Context\GitPreCommitContext; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Symfony\Component\Process\Process; @@ -36,6 +37,11 @@ function it_uses_its_external_command_locator_to_find_correct_command(LocatorInt $this->getCommandLocation(); } + function it_should_run_in_git_pre_commit_context(GitPreCommitContext $context) + { + $this->canRunInContext($context)->shouldReturn(true); + } + function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process, ContextInterface $context) { $processBuilder->setArguments(Argument::type('array'))->shouldBeCalled(); diff --git a/spec/GrumPHP/Task/PhpunitSpec.php b/spec/GrumPHP/Task/PhpunitSpec.php index 1ecc364c3..b05767140 100644 --- a/spec/GrumPHP/Task/PhpunitSpec.php +++ b/spec/GrumPHP/Task/PhpunitSpec.php @@ -6,6 +6,7 @@ use GrumPHP\Configuration\GrumPHP; use GrumPHP\Locator\LocatorInterface; use GrumPHP\Task\Context\ContextInterface; +use GrumPHP\Task\Context\GitPreCommitContext; use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Symfony\Component\Process\Process; @@ -35,6 +36,11 @@ function it_uses_its_external_command_locator_to_find_correct_command(LocatorInt $this->getCommandLocation(); } + function it_should_run_in_git_pre_commit_context(GitPreCommitContext $context) + { + $this->canRunInContext($context)->shouldReturn(true); + } + function it_runs_the_suite(ProcessBuilder $processBuilder, Process $process, ContextInterface $context) { $processBuilder->setArguments(Argument::type('array'))->shouldBeCalled(); From a9aa1ee660c3792223d402c0af6321115185bd3f Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Wed, 16 Sep 2015 18:09:35 +0200 Subject: [PATCH 3/3] The task runner doesn't need to be injected in the pre-commit command anymore. --- src/GrumPHP/Console/Application.php | 5 +---- .../Console/Command/Git/PreCommitCommand.php | 13 ++----------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/GrumPHP/Console/Application.php b/src/GrumPHP/Console/Application.php index ad5233232..cf3d3af7a 100644 --- a/src/GrumPHP/Console/Application.php +++ b/src/GrumPHP/Console/Application.php @@ -98,10 +98,7 @@ protected function getDefaultCommands() ); $commands[] = new Command\Git\PreCommitCommand( $container->get('config'), - $container->get('task_runner'), - $container->get('locator.changed_files'), - $container->get('locator.external_command'), - $container->get('process_builder') + $container->get('locator.changed_files') ); return $commands; diff --git a/src/GrumPHP/Console/Command/Git/PreCommitCommand.php b/src/GrumPHP/Console/Command/Git/PreCommitCommand.php index 58b0dca73..d56a3abd9 100644 --- a/src/GrumPHP/Console/Command/Git/PreCommitCommand.php +++ b/src/GrumPHP/Console/Command/Git/PreCommitCommand.php @@ -7,7 +7,6 @@ use GrumPHP\Console\Helper\PathsHelper; use GrumPHP\Console\Helper\TaskRunnerHelper; use GrumPHP\Locator\LocatorInterface; -use GrumPHP\Runner\TaskRunner; use GrumPHP\Task\Context\GitPreCommitContext; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -25,11 +24,6 @@ class PreCommitCommand extends Command */ protected $grumPHP; - /** - * @var TaskRunner - */ - protected $taskRunner; - /** * @var LocatorInterface */ @@ -37,15 +31,13 @@ class PreCommitCommand extends Command /** * @param GrumPHP $grumPHP - * @param TaskRunner $taskRunner * @param LocatorInterface $changedFilesLocator */ - public function __construct(GrumPHP $grumPHP, TaskRunner $taskRunner, LocatorInterface $changedFilesLocator) + public function __construct(GrumPHP $grumPHP, LocatorInterface $changedFilesLocator) { parent::__construct(); $this->grumPHP = $grumPHP; - $this->taskRunner = $taskRunner; $this->changedFilesLocator = $changedFilesLocator; } @@ -65,11 +57,10 @@ protected function configure() */ public function execute(InputInterface $input, OutputInterface $output) { - $files = $this->getCommittedFiles(); $context = new GitPreCommitContext($files); - $this->taskRunner()->run($output, $context); + return $this->taskRunner()->run($output, $context); } /**