From f8e360d9e4fe4280229f6d425f3bf02127a141fd Mon Sep 17 00:00:00 2001 From: Casper Boone Date: Tue, 1 Aug 2017 14:34:59 +0200 Subject: [PATCH] Switch to in memory cache (#8) --- .gitignore | 1 - README.md | 2 -- src/Watcher.php | 18 ++---------------- src/WatcherFactory.php | 7 +------ 4 files changed, 3 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index 6b2c97b..f02a2f8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ build composer.lock docs vendor -.phpunit-watcher-cache.php diff --git a/README.md b/README.md index 69950a2..9669b62 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Watcher.php b/src/Watcher.php index c952915..81e48ae 100644 --- a/src/Watcher.php +++ b/src/Watcher.php @@ -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) @@ -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); diff --git a/src/WatcherFactory.php b/src/WatcherFactory.php index 5dfd89b..8176008 100644 --- a/src/WatcherFactory.php +++ b/src/WatcherFactory.php @@ -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']); @@ -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) {