Skip to content

Commit

Permalink
Merge pull request #40 from Ocramius/feature/mutation-testing
Browse files Browse the repository at this point in the history
Mutation testing, PHP 7.1 testing
  • Loading branch information
Ocramius authored Apr 20, 2017
2 parents 51e867c + 2ecf5ff commit e9cea37
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
.travis.install.sh export-ignore
.travis.yml export-ignore
phpunit.xml.dist export-ignore
humbug.json.dist
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/vendor/
src/PackageVersions/Versions.php
composer.lock
clover.xml
clover.xml
humbuglog.txt
humbuglog.json
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ sudo: false

php:
- 7.0
- 7.1

env:
- DEPENDENCIES=""
Expand All @@ -16,6 +17,7 @@ before_script:

script:
- ./vendor/bin/phpunit --disallow-test-output --report-useless-tests --coverage-clover ./clover.xml
- ./vendor/bin/humbug

after_script:
- sh .travis.coverage.sh
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"composer-plugin-api": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.4.7",
"phpunit/phpunit": "^5.7.5",
"humbug/humbug": "dev-master",
"composer/composer": "^1.3",
"ext-zip": "*"
},
Expand Down
12 changes: 12 additions & 0 deletions humbug.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"source": {
"directories": [
"src"
]
},
"timeout": 10,
"logs": {
"text": "humbuglog.txt",
"json": "humbuglog.json"
}
}
11 changes: 5 additions & 6 deletions src/PackageVersions/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,11 @@ private static function writeVersionClassToFile(
Config $composerConfig,
RootPackageInterface $rootPackage
) {
file_put_contents(
self::locateRootPackageInstallPath($composerConfig, $rootPackage)
. '/src/PackageVersions/Versions.php',
$versionClassSource,
0664
);
$installPath = self::locateRootPackageInstallPath($composerConfig, $rootPackage)
. '/src/PackageVersions/Versions.php';

file_put_contents($installPath, $versionClassSource);
chmod($installPath, 0664);
}

/**
Expand Down
69 changes: 68 additions & 1 deletion test/PackageVersionsTest/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function testDumpVersionsClass()

$expectedPath = $vendorDir . '/ocramius/package-versions/src/PackageVersions';

/** @noinspection MkdirRaceConditionInspection */
mkdir($expectedPath, 0777, true);

$locker
Expand Down Expand Up @@ -206,6 +207,7 @@ public function testDumpVersionsClassNoDev()

$expectedPath = $vendorDir . '/ocramius/package-versions/src/PackageVersions';

/** @noinspection MkdirRaceConditionInspection */
mkdir($expectedPath, 0777, true);

$locker
Expand Down Expand Up @@ -318,6 +320,7 @@ public function testDumpVersionsWithoutPackageSourceDetails()

$expectedPath = $vendorDir . '/ocramius/package-versions/src/PackageVersions';

/** @noinspection MkdirRaceConditionInspection */
mkdir($expectedPath, 0777, true);

$locker
Expand Down Expand Up @@ -427,12 +430,15 @@ public function testDumpsVersionsClassToSpecificLocation(RootPackageInterface $r

$vendorDir = sys_get_temp_dir() . '/' . uniqid('InstallerTest', true) . '/vendor';

/** @noinspection MkdirRaceConditionInspection */
mkdir($vendorDir, 0777, true);

$expectedPath = $inVendor
/** @noinspection RealpathInSteamContextInspection */
$expectedPath = $inVendor
? $vendorDir . '/ocramius/package-versions/src/PackageVersions'
: realpath($vendorDir . '/..') . '/src/PackageVersions';

/** @noinspection MkdirRaceConditionInspection */
mkdir($expectedPath, 0777, true);

$locker
Expand Down Expand Up @@ -530,6 +536,7 @@ public function testVersionsAreNotDumpedIfPackageVersionsNotExplicitlyRequired()

$expectedPath = $vendorDir . '/ocramius/package-versions/src/PackageVersions';

/** @noinspection MkdirRaceConditionInspection */
mkdir($expectedPath, 0777, true);

$locker
Expand Down Expand Up @@ -576,6 +583,66 @@ public function testVersionsAreNotDumpedIfPackageVersionsNotExplicitlyRequired()
$this->rmDir($vendorDir);
}

public function testGeneratedVersionFileAccessRights()
{
if (0 === strpos(\PHP_OS, 'WIN')) {
$this->markTestSkipped('Windows is kinda "meh" at file access levels');
}

$config = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
$locker = $this->getMockBuilder(Locker::class)->disableOriginalConstructor()->getMock();
$repositoryManager = $this->getMockBuilder(RepositoryManager::class)->disableOriginalConstructor()->getMock();
$installManager = $this->getMockBuilder(InstallationManager::class)->disableOriginalConstructor()->getMock();
$repository = $this->createMock(InstalledRepositoryInterface::class);
$package = $this->createMock(RootPackageInterface::class);

$vendorDir = sys_get_temp_dir() . '/' . uniqid('InstallerTest', true);

$expectedPath = $vendorDir . '/ocramius/package-versions/src/PackageVersions';

/** @noinspection MkdirRaceConditionInspection */
mkdir($expectedPath, 0777, true);

$locker
->expects(self::any())
->method('getLockData')
->willReturn([
'packages' => [
[
'name' => 'ocramius/package-versions',
'version' => '1.0.0',
],
],
]);

$repositoryManager->expects(self::any())->method('getLocalRepository')->willReturn($repository);

$this->composer->expects(self::any())->method('getConfig')->willReturn($config);
$this->composer->expects(self::any())->method('getLocker')->willReturn($locker);
$this->composer->expects(self::any())->method('getRepositoryManager')->willReturn($repositoryManager);
$this->composer->expects(self::any())->method('getPackage')->willReturn($package);
$this->composer->expects(self::any())->method('getInstallationManager')->willReturn($installManager);

$package->expects(self::any())->method('getName')->willReturn('root/package');
$package->expects(self::any())->method('getVersion')->willReturn('1.3.5');
$package->expects(self::any())->method('getSourceReference')->willReturn('aaabbbcccddd');

$config->expects(self::any())->method('get')->with('vendor-dir')->willReturn($vendorDir);

Installer::dumpVersionsClass(new Event(
'post-install-cmd',
$this->composer,
$this->io
));

$filePath = $expectedPath . '/Versions.php';

self::assertFileExists($filePath);
self::assertSame('0664', substr(sprintf('%o', fileperms($filePath)), -4));

$this->rmDir($vendorDir);
}

/**
* @param string $directory
*
Expand Down

0 comments on commit e9cea37

Please sign in to comment.