Skip to content
This repository has been archived by the owner on Jul 17, 2021. It is now read-only.

Commit

Permalink
fixes #31
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-feek committed Mar 30, 2018
1 parent bdd5105 commit 0e2e063
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
- Nothing

### Fixed
- Nothing
- Proxy Phpunit arguments #31

### Removed
- Nothing
Expand Down
32 changes: 17 additions & 15 deletions src/Commands/PhpUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace Feek\LaravelGitHooks\Commands;

use Feek\LaravelGitHooks\CommandOutputFormatter;
use PHPUnit\TextUI\Command;
use PHPUnit\TextUI\TestRunner;
use Feek\LaravelGitHooks\ProgramExecutor;

class PhpUnit extends BaseCommand
{
Expand All @@ -27,15 +26,21 @@ class PhpUnit extends BaseCommand
*/
protected $commandOutputFormatter;

/**
* @var ProgramExecutor
*/
protected $programExecutor;

/**
* Create a new command instance.
*
* @param CommandOutputFormatter $commandOutputFormatter
*/
public function __construct(CommandOutputFormatter $commandOutputFormatter)
public function __construct(ProgramExecutor $programExecutor, CommandOutputFormatter $commandOutputFormatter)
{
parent::__construct();
$this->commandOutputFormatter = $commandOutputFormatter;
$this->programExecutor = $programExecutor;
}

/**
Expand All @@ -45,23 +50,20 @@ public function __construct(CommandOutputFormatter $commandOutputFormatter)
*/
public function handle()
{
ob_start();

$result = (new Command())->run([
'--disallow-test-output',
'--stop-on-failure'
], false);
$arguments = $this->option('proxiedArguments');

ob_end_clean();
$this->programExecutor->exec("./vendor/bin/phpunit $arguments", $output, $statusCode);

$success = ($result === TestRunner::SUCCESS_EXIT);
if ($statusCode !== 0) {
foreach ($output as $line) {
$this->line($line);
}

if ($success) {
$this->info($this->commandOutputFormatter->success('Running PHPUnit'));
} else {
$this->error($this->commandOutputFormatter->error('Running PHPUnit'));
} else {
$this->info($this->commandOutputFormatter->success('Running PHPUnit'));
}

return $success ? 0 : 1;
return $statusCode;
}
}

0 comments on commit 0e2e063

Please # to comment.