Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor tests #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 39 additions & 13 deletions tests/PhingTesterIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace VasekPurchart\Phing\PhingTester;

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

class PhingTesterIntegrationTest extends \PHPUnit\Framework\TestCase
Expand All @@ -13,9 +15,9 @@ public function testExecuteTarget(): void
{
$tester = new PhingTester(__DIR__ . '/phing-tester-integration-test.xml');
$target = __FUNCTION__;
$tester->executeTarget($target);

$this->assertTrue(true); // build should not fail and reach this
$this->expectNotToPerformAssertions();
$tester->executeTarget($target);
}

public function testMessageInLogs(): void
Expand Down Expand Up @@ -101,24 +103,48 @@ public function testFailBuildCheckBuildException(): void
$tester = new PhingTester(__DIR__ . '/phing-tester-integration-test.xml');
$target = __FUNCTION__;
$tester->expectFailedBuild($target, function (\BuildException $e) use ($target): void {
$this->assertRegExp(sprintf('~%s.+not.+exist~', $target), $e->getMessage());
Assert::assertRegExp(sprintf('~%s.+not.+exist~', $target), $e->getMessage());
});
}

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 All @@ -127,7 +153,7 @@ public function testGetCustomProjectProperties(): void
$target = __FUNCTION__;
$tester->executeTarget($target);

$this->assertSame('bar', $tester->getProject()->getProperty('foo'));
Assert::assertSame('bar', $tester->getProject()->getProperty('foo'));
}

}