Skip to content

Commit

Permalink
Merge 9bc4f26 into 09dcb67
Browse files Browse the repository at this point in the history
  • Loading branch information
BruceGitHub committed Feb 27, 2019
2 parents 09dcb67 + 9bc4f26 commit f38fb95
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/Paraunit/Configuration/PHPUnitConfig.php
Expand Up @@ -6,7 +6,9 @@

class PHPUnitConfig
{
const DEFAULT_FILE_NAME = 'phpunit.xml.dist';
public const DEFAULT_FILE_NAME = 'phpunit.xml';

public const FALLBACK_CONFIG_FILE_NAME = 'phpunit.xml.dist';

/** @var string */
private $configFilename;
Expand Down Expand Up @@ -64,7 +66,7 @@ private function getConfigFileRealpath(string $inputPathOrFileName): string
}

if (is_dir($configFile)) {
$configFile .= DIRECTORY_SEPARATOR . self::DEFAULT_FILE_NAME;
$configFile .= DIRECTORY_SEPARATOR . $this->getConfigFile($configFile);
}

if (! is_file($configFile) || ! is_readable($configFile)) {
Expand All @@ -73,4 +75,13 @@ private function getConfigFileRealpath(string $inputPathOrFileName): string

return $configFile;
}

private function getConfigFile(string $path): string
{
if (file_exists($path . DIRECTORY_SEPARATOR . self::DEFAULT_FILE_NAME)) {
return self::DEFAULT_FILE_NAME;
}

return self::FALLBACK_CONFIG_FILE_NAME;
}
}
2 changes: 1 addition & 1 deletion src/Paraunit/Configuration/TempFilenameFactory.php
Expand Up @@ -33,7 +33,7 @@ public function getFilenameForCoverage(string $uniqueId): string

public function getFilenameForConfiguration(): string
{
return $this->getTempFilename('config', 'phpunit', 'xml.dist');
return $this->getTempFilename('config', 'phpunit', 'xml');
}

private function getTempFilename(string $subDir, string $filename, string $extension): string
Expand Down
23 changes: 23 additions & 0 deletions tests/Stub/StubbedXMLConfigs/MissDefault/phpunit.xml.dist
@@ -0,0 +1,23 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<php>
<ini name="error_reporting" value="-1"/>
<ini name="intl.default_locale" value="en"/>
<ini name="intl.error_level" value="0"/>
<ini name="memory_limit" value="-1"/>
</php>

<testsuites>
<testsuite>
<directory suffix="TestSuffix.php">./only/selected/test/suite/</directory>
</testsuite>
<testsuite>
<directory>./other/test/suite/</directory>
</testsuite>
</testsuites>

</phpunit>
Empty file.
21 changes: 20 additions & 1 deletion tests/Unit/Configuration/PHPUnitConfigTest.php
Expand Up @@ -29,11 +29,30 @@ public function testGetFileFullPathWithDirAndUseDefaultFileName()
$this->assertEquals($configurationFile, $config->getFileFullPath());
}

public function testGetFileFullPathWithMissConfigDefault(): void
{
$dir = $this->getStubPath() . 'StubbedXMLConfigs' . DIRECTORY_SEPARATOR . 'MissDefault';
$config = new PHPUnitConfig($dir);

$configurationFile = $dir . DIRECTORY_SEPARATOR . 'phpunit.xml.dist';
$this->assertEquals($configurationFile, $config->getFileFullPath());
}

public function testGetFileFullPathWithMissConfigDefaultAndFallBack(): void
{
$dir = $this->getStubPath() . 'StubbedXMLConfigs' . DIRECTORY_SEPARATOR . 'MissDefaultAndFallback';

$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage(PHPUnitConfig::FALLBACK_CONFIG_FILE_NAME . ' does not exist');

new PHPUnitConfig($dir);
}

public function testGetFileFullPathWithFileDoesNotExistWillThrowException()
{
$dir = $this->getStubPath() . 'PHPUnitJSONLogOutput';
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage(PHPUnitConfig::DEFAULT_FILE_NAME . ' does not exist');
$this->expectExceptionMessage(PHPUnitConfig::FALLBACK_CONFIG_FILE_NAME . ' does not exist');

new PHPUnitConfig($dir);
}
Expand Down

0 comments on commit f38fb95

Please sign in to comment.