diff --git a/.gitignore b/.gitignore index 1fdff8f..d719189 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ composer.lock vendor /build/logs +/infection.log diff --git a/.travis.yml b/.travis.yml index d93816d..05be5b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ env: install: - composer install --dev --no-scripts script: - - php vendor/bin/phpunit --coverage-clover build/logs/clover.xml --whitelist=src/ + - composer ci after_success: - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter diff --git a/composer.json b/composer.json index 3d8ec43..902f5e5 100644 --- a/composer.json +++ b/composer.json @@ -13,14 +13,15 @@ } ], "require": { - "symfony/filesystem": ">2.8", - "php": ">=7.1" + "php": ">=7.1", + "symfony/filesystem": ">2.8" }, "require-dev": { - "phpunit/phpunit": "^7.4", + "phpunit/phpunit": "^7.0|^8.0", "jakub-onderka/php-parallel-lint": "^1.0", - "phpstan/phpstan-shim": "^0.10.5", - "keboola/coding-standard": "^6.0" + "phpstan/phpstan-shim": "^0.11", + "keboola/coding-standard": "^8.0", + "infection/infection": "^0.12" }, "autoload": { "psr-4": { @@ -33,15 +34,17 @@ } }, "scripts": { - "tests": "phpunit", + "tests": "phpunit --coverage-clover build/logs/clover.xml --coverage-xml=build/logs/coverage-xml --log-junit=build/logs/phpunit.junit.xml", "phpstan": "phpstan analyse ./src ./tests --level=max --no-progress -c phpstan.neon", "phpcs": "phpcs -n --ignore=vendor --extensions=php .", "phplint": "parallel-lint -j 10 --exclude vendor .", + "infection": "infection --threads=4 --min-covered-msi=80 --coverage=build/logs", "build": [ "@phplint", "@phpcs", "@phpstan", - "@tests" + "@tests", + "@infection" ], "ci": [ "@composer validate --no-check-publish --no-check-all", diff --git a/infection.json.dist b/infection.json.dist new file mode 100644 index 0000000..42f1627 --- /dev/null +++ b/infection.json.dist @@ -0,0 +1,14 @@ +{ + "timeout": 10, + "source": { + "directories": [ + "src\/" + ] + }, + "logs": { + "text": "infection.log" + }, + "mutators": { + "@default": true + } +} \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index c8a890e..3289757 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -12,5 +12,12 @@ tests - + + + . + + vendor + + + diff --git a/src/Temp.php b/src/Temp.php index 3558302..2233252 100644 --- a/src/Temp.php +++ b/src/Temp.php @@ -8,6 +8,8 @@ class Temp { + private const FILE_MODE = 0777; + /** * @var String */ @@ -31,7 +33,7 @@ class Temp public function __construct(string $prefix = '') { $this->prefix = $prefix; - $this->id = uniqid("run-", true); + $this->id = uniqid('run-', true); $this->fileSystem = new Filesystem(); } @@ -39,9 +41,7 @@ private function initRunFolder(): void { clearstatcache(); $path = $this->getTmpPath(); - if (!file_exists($path) && !is_dir($path)) { - $this->fileSystem->mkdir($path, 0777); - } + $this->fileSystem->mkdir($path, self::FILE_MODE); $this->tmpFolder = $path; } @@ -54,9 +54,9 @@ private function getTmpPath(): string { $tmpDir = sys_get_temp_dir(); if (!empty($this->prefix)) { - $tmpDir .= "/" . $this->prefix; + $tmpDir .= '/' . $this->prefix; } - $tmpDir .= "/" . $this->id; + $tmpDir .= '/' . $this->id; return $tmpDir; } @@ -101,10 +101,10 @@ public function createFile(string $fileName): \SplFileInfo $fileInfo = new \SplFileInfo($this->getTmpFolder() . '/' . $fileName); $pathName = $fileInfo->getPathname(); if (!file_exists(dirname($pathName))) { - $this->fileSystem->mkdir(dirname($pathName), 0777); + $this->fileSystem->mkdir(dirname($pathName), self::FILE_MODE); } $this->fileSystem->touch($pathName); - $this->fileSystem->chmod($pathName, 0600); + $this->fileSystem->chmod($pathName, self::FILE_MODE); return $fileInfo; } diff --git a/tests/TempTest.php b/tests/TempTest.php index 5afbf17..f168e7e 100644 --- a/tests/TempTest.php +++ b/tests/TempTest.php @@ -16,7 +16,13 @@ public function testCreateTmpFile(): void $file = $temp->createTmpFile('filename_suffix'); self::assertFileExists($file->getPathname()); - self::assertContains($tempFolder, $file->getPathname()); + self::assertStringContainsString($tempFolder, $file->getPathname()); + self::assertStringEndsWith('-filename_suffix', $file->getFilename()); + self::assertNotEquals('-filename_suffix', $file->getFilename()); + $dirParts = explode('/', $file->getPath()); + $tempDirName = (string) end($dirParts); + self::assertStringStartsWith('run-', $tempDirName); + self::assertGreaterThan(20, strlen($tempDirName)); } public function testCreateFile(): void @@ -26,6 +32,7 @@ public function testCreateFile(): void self::assertInstanceOf('SplFileInfo', $file); self::assertEquals($temp->getTmpFolder() . '/' . $file->getFilename(), $file->getPathname()); + self::assertEquals('0777', substr(sprintf('%o', $file->getPerms()), -4)); } public function testCreateFileNested(): void @@ -42,7 +49,7 @@ public function testGetTmpFolder(): void $tempFolder = $temp->getTmpFolder(); self::assertNotEmpty($tempFolder); - self::assertContains(sys_get_temp_dir() . '/test', $temp->getTmpFolder()); + self::assertStringContainsString(sys_get_temp_dir() . '/test', $temp->getTmpFolder()); } public function testCleanup(): void