diff --git a/composer.json b/composer.json index c0b4715..8a62d3a 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,12 @@ { - "name":"yosymfony/resource-watcher", + "name": "yosymfony/resource-watcher", "description": "A simple resource watcher using Symfony Finder", - "keywords": ["resources","watcher","finder","symfony"], + "keywords": [ + "resources", + "watcher", + "finder", + "symfony" + ], "license": "MIT", "homepage": "http://yosymfony.com", "authors": [ @@ -11,12 +16,12 @@ } ], "require": { - "php": ">=5.6", - "symfony/finder": "^2.7|^3.0|^4.0|^5.0" + "php": ">=7.4", + "symfony/finder": "^2.7|^3.0|^4.0|^5.0|^6.0" }, "require-dev": { "symfony/filesystem": "^2.7|^3.0|^4.0|^5.0", - "phpunit/phpunit": "^5.7" + "phpunit/phpunit": "^9.0" }, "autoload": { "psr-4": { @@ -31,4 +36,4 @@ "scripts": { "test": "vendor/bin/phpunit" } -} +} \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c65e8db..08a506d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,29 +1,27 @@ - - + + + + ./ + + + ./vendor + ./tests + + ./tests - - - - ./ - - ./vendor - ./tests - - - \ No newline at end of file diff --git a/src/ResourceCachePhpFile.php b/src/ResourceCachePhpFile.php index 66f8594..4f5cf64 100644 --- a/src/ResourceCachePhpFile.php +++ b/src/ResourceCachePhpFile.php @@ -11,6 +11,8 @@ namespace Yosymfony\ResourceWatcher; +use InvalidArgumentException; + /** * Resource cache implementation using a PHP file with an array. * @@ -73,7 +75,7 @@ public function save() private function warmUpCacheFromFile($filename) { if (preg_match('#\.php$#', $filename) == false) { - throw new \InvalidArgumentException('The cache filename must ends with the extension ".php".'); + throw new InvalidArgumentException('The cache filename must ends with the extension ".php".'); } if (file_exists($filename) == false) { @@ -84,8 +86,8 @@ private function warmUpCacheFromFile($filename) $fileContent = include($filename); - if (is_array($fileContent) == false) { - throw new \InvalidArgumentException('Cache file invalid format.'); + if (is_array($fileContent) === false) { + throw new InvalidArgumentException('Cache file invalid format.'); } foreach ($fileContent as $filename => $hash) { diff --git a/tests/ResourceCacheMemoryTest.php b/tests/ResourceCacheMemoryTest.php index a46cf68..7da1520 100644 --- a/tests/ResourceCacheMemoryTest.php +++ b/tests/ResourceCacheMemoryTest.php @@ -18,7 +18,7 @@ class ResourceCacheMemoryTest extends TestCase { private $cache; - public function setUp() + public function setUp(): void { $this->cache = new ResourceCacheMemory(); } diff --git a/tests/ResourceCachePhpFileTest.php b/tests/ResourceCachePhpFileTest.php index bfdb1f5..f7c498b 100644 --- a/tests/ResourceCachePhpFileTest.php +++ b/tests/ResourceCachePhpFileTest.php @@ -11,6 +11,7 @@ namespace Yosymfony\ResourceWatcher\Tests; +use InvalidArgumentException; use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; use Yosymfony\ResourceWatcher\ResourceCachePhpFile; @@ -21,7 +22,7 @@ class ResourceCachePhpFileTest extends TestCase private $fs; private $tmpDir; - public function setUp() + public function setUp(): void { $this->tmpDir = sys_get_temp_dir() . '/resource-watchers-tests'; $this->cacheFile = $this->tmpDir . '/cache-file-test.php'; @@ -29,7 +30,7 @@ public function setUp() $this->fs->mkdir($this->tmpDir); } - public function tearDown() + public function tearDown(): void { $this->fs->remove($this->tmpDir); } @@ -78,6 +79,8 @@ public function testConstructWithAInvalidCacheFileMustThrownAnException() { $this->fs->dumpFile($this->cacheFile, ''); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Cache file invalid format.'); $rc = new ResourceCachePhpFile($this->cacheFile); } @@ -87,6 +90,9 @@ public function testConstructWithAInvalidCacheFileMustThrownAnException() */ public function testConstructWithANoPhpFileExtensionMustThrownAnException() { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('The cache filename must ends with the extension ".php".'); + $rc = new ResourceCachePhpFile($this->tmpDir . '/cache-file-test.txt'); } } diff --git a/tests/ResourceWatcherResultTest.php b/tests/ResourceWatcherResultTest.php index e884487..069735a 100644 --- a/tests/ResourceWatcherResultTest.php +++ b/tests/ResourceWatcherResultTest.php @@ -21,7 +21,7 @@ class ResourceWatcherResultTests extends TestCase private $updatedFiles; private $resourceWatcherResult; - public function setUp() + public function setUp(): void { $this->newFiles = ['/my-path/newfile.txt']; $this->deletedFiles = ['/my-path/deletedfile.txt']; diff --git a/tests/ResourceWatcherTest.php b/tests/ResourceWatcherTest.php index 9260a34..57ed02e 100644 --- a/tests/ResourceWatcherTest.php +++ b/tests/ResourceWatcherTest.php @@ -23,7 +23,7 @@ class ResourceWatcherTest extends TestCase protected $tmpDir; protected $fs; - public function setUp() + public function setUp(): void { $this->tmpDir = sys_get_temp_dir() . '/resourceWatcher-tests'; $this->fs = new Filesystem(); @@ -31,7 +31,7 @@ public function setUp() $this->fs->mkdir($this->tmpDir); } - public function tearDown() + public function tearDown(): void { $this->fs->remove($this->tmpDir); }