Skip to content

Commit

Permalink
Switch to in memory cache (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
casperboone authored and freekmurze committed Aug 1, 2017
1 parent f29cedd commit f8e360d
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 25 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ build
composer.lock
docs
vendor
.phpunit-watcher-cache.php
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ composer require spatie/phpunit-watcher --dev

Locally installed you can run it with `vendor/bin/phpunit-watcher watch`

For performance reasons the package will create a `.phpunit-watcher.cache.php` inside the directory where it is run. You should add an entry for that file in your [global gitignore](https://murze.be/2014/12/create-a-global-gitignore/).


## Usage

Expand Down
18 changes: 2 additions & 16 deletions src/Watcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,19 @@
use Symfony\Component\Finder\Finder;
use Symfony\Component\Process\Process;
use Yosymfony\ResourceWatcher\ResourceWatcher;
use Yosymfony\ResourceWatcher\ResourceCacheFile;
use Yosymfony\ResourceWatcher\ResourceCacheMemory;

class Watcher
{
/** @var \Symfony\Component\Finder\Finder */
protected $finder;

/** @var string */
protected $pathToCacheFile;

/** @var $string */
protected $phpunitArguments;

public function __construct(Finder $finder)
{
$this->finder = $finder;

$this->pathToCacheFile = '.phpunit-watcher-cache.php';
}

public function useCacheFile(string $pathToCacheFile)
{
$this->pathToCacheFile = $pathToCacheFile;
}

public function usePhpunitArguments(string $arguments)
Expand All @@ -41,11 +31,7 @@ public function startWatching()
{
$this->runTests();

$cache = new ResourceCacheFile(
$this->pathToCacheFile
);

$watcher = new ResourceWatcher($cache);
$watcher = new ResourceWatcher(new ResourceCacheMemory());

$watcher->setFinder($this->finder);

Expand Down
7 changes: 1 addition & 6 deletions src/WatcherFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ public static function create(array $options = []): array
->files()
->in($options['watch']['directories']);

$watcher = (new Watcher($finder));

if (isset($options['cache'])) {
$watcher->useCacheFile($options['cache']);
}
$watcher = new Watcher($finder);

if (isset($options['phpunitArguments'])) {
$watcher->usePhpunitArguments($options['phpunitArguments']);
Expand All @@ -40,7 +36,6 @@ protected static function mergeWithDefaultOptions(array $options): array
],
'fileMask' => '*.php',
],
'cache' => '.phpunit-watcher-cache.php',
], $options);

foreach ($options['watch']['directories'] as $index => $directory) {
Expand Down

0 comments on commit f8e360d

Please sign in to comment.