From e51c118ce6077ad2b57c7f6f0d7c9b765f0b6ee9 Mon Sep 17 00:00:00 2001 From: Petr Duda Date: Wed, 12 Apr 2023 22:37:56 +0200 Subject: [PATCH 1/3] replace assertTrue(true) with expectNotToPerformAssertions() --- tests/PhingTesterIntegrationTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/PhingTesterIntegrationTest.php b/tests/PhingTesterIntegrationTest.php index ec6a951..85fb499 100644 --- a/tests/PhingTesterIntegrationTest.php +++ b/tests/PhingTesterIntegrationTest.php @@ -13,9 +13,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 From 0ba2b09ca1dd6045dbf736c1ba2cb52256f343fa Mon Sep 17 00:00:00 2001 From: Petr Duda Date: Mon, 10 Apr 2023 17:35:01 +0200 Subject: [PATCH 2/3] stop calling static methods in tests as non-static --- tests/PhingTesterIntegrationTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/PhingTesterIntegrationTest.php b/tests/PhingTesterIntegrationTest.php index 85fb499..422f606 100644 --- a/tests/PhingTesterIntegrationTest.php +++ b/tests/PhingTesterIntegrationTest.php @@ -4,6 +4,7 @@ namespace VasekPurchart\Phing\PhingTester; +use PHPUnit\Framework\Assert; use Project; class PhingTesterIntegrationTest extends \PHPUnit\Framework\TestCase @@ -101,7 +102,7 @@ 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()); }); } @@ -127,7 +128,7 @@ public function testGetCustomProjectProperties(): void $target = __FUNCTION__; $tester->executeTarget($target); - $this->assertSame('bar', $tester->getProject()->getProperty('foo')); + Assert::assertSame('bar', $tester->getProject()->getProperty('foo')); } } From d4ec760c60ce97a45998521708de60ae73df86f1 Mon Sep 17 00:00:00 2001 From: Petr Duda Date: Mon, 10 Apr 2023 17:47:32 +0200 Subject: [PATCH 3/3] deduplicate testing base directory path using data provider --- tests/PhingTesterIntegrationTest.php | 43 ++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/tests/PhingTesterIntegrationTest.php b/tests/PhingTesterIntegrationTest.php index 422f606..ce31614 100644 --- a/tests/PhingTesterIntegrationTest.php +++ b/tests/PhingTesterIntegrationTest.php @@ -4,6 +4,7 @@ namespace VasekPurchart\Phing\PhingTester; +use Generator; use PHPUnit\Framework\Assert; use Project; @@ -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