Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to control timeout for PHPUnit process #104

Merged
merged 1 commit into from
Jan 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ notifications:
phpunit:
binaryPath: vendor/bin/phpunit
arguments: '--stop-on-failure'
timeout: 180
```

### Customize watched directories and files
Expand Down
8 changes: 6 additions & 2 deletions src/Screens/Phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Spatie\PhpUnitWatcher\Screens;

use Symfony\Component\Process\Process;
use Spatie\PhpUnitWatcher\Notification;
use Symfony\Component\Process\Process;

class Phpunit extends Screen
{
Expand All @@ -18,13 +18,16 @@ class Phpunit extends Screen
/** @var string */
private $phpunitBinaryPath;

/** @var int */
private $phpunitTimeout;

public function __construct(array $options)
{
$this->options = $options;

$this->phpunitArguments = $options['phpunit']['arguments'] ?? '';

$this->phpunitBinaryPath = $options['phpunit']['binaryPath'] ?? self::DEFAULT_BINARY_PATH;
$this->phpunitTimeout = $options['phpunit']['timeout'] ?? 60;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 60 the default being used if setTimeout is not called on Process?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is.

}

public function draw()
Expand Down Expand Up @@ -94,6 +97,7 @@ protected function writeHeader()
protected function runTests()
{
$result = (new Process(array_merge([$this->phpunitBinaryPath], explode(' ', $this->phpunitArguments))))
->setTimeout($this->phpunitTimeout)
->setTty(Process::isTtySupported())
->run(function ($type, $line) {
echo $line;
Expand Down