Skip to content

Commit

Permalink
Merge pull request #12 from keboola/odin-infection
Browse files Browse the repository at this point in the history
infection testing
  • Loading branch information
odinuv authored Apr 26, 2019
2 parents ca31326 + ff44973 commit cbdb4dd
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
composer.lock
vendor
/build/logs
/infection.log
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions infection.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"timeout": 10,
"source": {
"directories": [
"src\/"
]
},
"logs": {
"text": "infection.log"
},
"mutators": {
"@default": true
}
}
9 changes: 8 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@
<testsuite name="Library Test Suite">
<directory>tests</directory>
</testsuite>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">.</directory>
<exclude>
<directory suffix=".php">vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
16 changes: 8 additions & 8 deletions src/Temp.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

class Temp
{
private const FILE_MODE = 0777;

/**
* @var String
*/
Expand All @@ -31,17 +33,15 @@ class Temp
public function __construct(string $prefix = '')
{
$this->prefix = $prefix;
$this->id = uniqid("run-", true);
$this->id = uniqid('run-', true);
$this->fileSystem = new Filesystem();
}

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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
11 changes: 9 additions & 2 deletions tests/TempTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit cbdb4dd

Please sign in to comment.