Skip to content

Commit

Permalink
deduplicate testing base directory path using data provider
Browse files Browse the repository at this point in the history
  • Loading branch information
petrduda committed Apr 12, 2023
1 parent 0ba2b09 commit d4ec760
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions tests/PhingTesterIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace VasekPurchart\Phing\PhingTester;

use Generator;
use PHPUnit\Framework\Assert;
use Project;

Expand Down Expand Up @@ -106,20 +107,44 @@ public function testFailBuildCheckBuildException(): void
});
}

public function testDefaultBaseDirectoryMatchesBuildfile(): void
/**
* @return mixed[][]|\Generator
*/
public function baseDirectoryDataProvider(): Generator
{
$tester = new PhingTester(__DIR__ . '/phing-tester-integration-test.xml');
$tester->executeTarget('base-directory');
$tester->assertLogMessageRegExp(sprintf('~^basedir: %s$~', __DIR__));
yield 'default base directory matches buildfile' => [
'buildFilePath' => __DIR__ . '/phing-tester-integration-test.xml',
'baseDirectoryPath' => null,
'expectedLogMessageRegExp' => sprintf('~^basedir: %s$~', __DIR__),
];

yield 'custom base directory' => (static function (): array {
$customBaseDir = realpath(__DIR__ . '/..');

return [
'buildFilePath' => __DIR__ . '/phing-tester-integration-test.xml',
'baseDirectoryPath' => $customBaseDir,
'expectedLogMessageRegExp' => sprintf('~^basedir: %s$~', $customBaseDir),
];
})();
}

public function testSetCustomBaseDirectory(): void
/**
* @dataProvider baseDirectoryDataProvider
*
* @param string $buildFilePath
* @param string|null $baseDirectoryPath
* @param string $expectedLogMessageRegExp
*/
public function testBaseDirectory(
string $buildFilePath,
?string $baseDirectoryPath,
string $expectedLogMessageRegExp
): void
{
$customBaseDir = realpath(__DIR__ . '/..');

$tester = new PhingTester(__DIR__ . '/phing-tester-integration-test.xml', $customBaseDir);
$tester = new PhingTester($buildFilePath, $baseDirectoryPath);
$tester->executeTarget('base-directory');
$tester->assertLogMessageRegExp(sprintf('~^basedir: %s$~', $customBaseDir));
$tester->assertLogMessageRegExp($expectedLogMessageRegExp);
}

public function testGetCustomProjectProperties(): void
Expand Down

0 comments on commit d4ec760

Please sign in to comment.