From 3dc48ecbbcdc597c9bdcff44a57a01b9f25efa48 Mon Sep 17 00:00:00 2001 From: Petr Duda Date: Tue, 28 Mar 2023 10:28:32 +0200 Subject: [PATCH 1/5] stop calling static methods in tests as non-static --- tests/CopyFilesTaskIntegrationTest.php | 45 +++++++++++++------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/tests/CopyFilesTaskIntegrationTest.php b/tests/CopyFilesTaskIntegrationTest.php index 1512f8a..9c8fbe6 100644 --- a/tests/CopyFilesTaskIntegrationTest.php +++ b/tests/CopyFilesTaskIntegrationTest.php @@ -4,6 +4,7 @@ namespace VasekPurchart\Phing\CopyFiles; +use PHPUnit\Framework\Assert; use Project; use VasekPurchart\Phing\PhingTester\PhingTester; @@ -25,7 +26,7 @@ public function testCopyFile(): void $target = __FUNCTION__; $tester->executeTarget($target); - $this->assertFileEquals($sourceFilePath, $targetFilePath); + Assert::assertFileEquals($sourceFilePath, $targetFilePath); $tester->assertLogMessageRegExp('~Copying.+/foo.+->.+/foo-copy~', $target, Project::MSG_INFO); } @@ -42,7 +43,7 @@ public function testCopyFileWithAbsolutePath(): void $target = __FUNCTION__; $tester->executeTarget($target); - $this->assertFileEquals($sourceFilePath, $targetFilePath); + Assert::assertFileEquals($sourceFilePath, $targetFilePath); $tester->assertLogMessageRegExp('~Copying.+/foo.+->.+/foo-copy~', $target, Project::MSG_INFO); } @@ -57,8 +58,8 @@ public function testTargetFileExists(): void $target = __FUNCTION__; $tester->executeTarget($target); - $this->assertFileExists($targetFilePath); - $this->assertSame('EXISTING', file_get_contents($targetFilePath)); + Assert::assertFileExists($targetFilePath); + Assert::assertSame('EXISTING', file_get_contents($targetFilePath)); $tester->assertLogMessageRegExp('~/existing.+already exists.+SKIPPING~', $target, Project::MSG_INFO); } @@ -73,8 +74,8 @@ public function testTargetFileExistsSkip(): void $target = __FUNCTION__; $tester->executeTarget($target); - $this->assertFileExists($targetFilePath); - $this->assertSame('EXISTING', file_get_contents($targetFilePath)); + Assert::assertFileExists($targetFilePath); + Assert::assertSame('EXISTING', file_get_contents($targetFilePath)); $tester->assertLogMessageRegExp('~/existing.+already exists.+SKIPPING~', $target, Project::MSG_INFO); } @@ -89,7 +90,7 @@ public function testTargetFileExistsReplace(): void $target = __FUNCTION__; $tester->executeTarget($target); - $this->assertFileEquals($sourceFilePath, $targetFilePath); + Assert::assertFileEquals($sourceFilePath, $targetFilePath); $tester->assertLogMessageRegExp('~/existing.+already exists~', $target, Project::MSG_VERBOSE); } @@ -105,8 +106,8 @@ public function testTargetFileExistsFail(): void $tester->expectFailedBuild($target); - $this->assertFileExists($targetFilePath); - $this->assertSame('EXISTING', file_get_contents($targetFilePath)); + Assert::assertFileExists($targetFilePath); + Assert::assertSame('EXISTING', file_get_contents($targetFilePath)); $tester->assertLogMessageRegExp('~/existing.+already exists~', $target, Project::MSG_ERR); } @@ -129,9 +130,9 @@ public function testCopyMultipleFiles(): void $target = __FUNCTION__; $tester->executeTarget($target); - $this->assertFileEquals($sourceFooFilePath, $targetFooFilePath); + Assert::assertFileEquals($sourceFooFilePath, $targetFooFilePath); $tester->assertLogMessageRegExp('~Copying.+/foo.+->.+/foo-copy~', $target, Project::MSG_INFO); - $this->assertFileEquals($sourceBarFilePath, $targetBarFilePath); + Assert::assertFileEquals($sourceBarFilePath, $targetBarFilePath); $tester->assertLogMessageRegExp('~Copying.+/bar.+->.+/bar-copy~', $target, Project::MSG_INFO); } @@ -151,11 +152,11 @@ public function testReplaceMultipleFilesWithExistingTargets(): void $target = __FUNCTION__; $tester->executeTarget($target); - $this->assertFileEquals($sourceFooFilePath, $targetFooFilePath); + Assert::assertFileEquals($sourceFooFilePath, $targetFooFilePath); $tester->assertLogMessageRegExp('~Copying.+/foo-new.+->.+/foo-existing~', $target, Project::MSG_INFO); $tester->assertLogMessageRegExp('~/foo-existing.+already exists~', $target, Project::MSG_VERBOSE); - $this->assertFileEquals($sourceBarFilePath, $targetBarFilePath); + Assert::assertFileEquals($sourceBarFilePath, $targetBarFilePath); $tester->assertLogMessageRegExp('~Copying.+/bar-new.+->.+/bar-existing~', $target, Project::MSG_INFO); $tester->assertLogMessageRegExp('~/bar-existing.+already exists~', $target, Project::MSG_VERBOSE); } @@ -181,15 +182,15 @@ public function testCopyMultipleFilesWithExistingTargetsUsingDifferentModes(): v $target = __FUNCTION__; $tester->executeTarget($target); - $this->assertFileExists($targetSkipFilePath); - $this->assertSame('SKIP-EXISTING', file_get_contents($targetSkipFilePath)); + Assert::assertFileExists($targetSkipFilePath); + Assert::assertSame('SKIP-EXISTING', file_get_contents($targetSkipFilePath)); - $this->assertFileEquals($sourceReplaceFilePath, $targetReplaceFilePath); + Assert::assertFileEquals($sourceReplaceFilePath, $targetReplaceFilePath); $tester->assertLogMessageRegExp('~Copying.+/replace-new.+->.+/replace-existing~', $target, Project::MSG_INFO); $tester->assertLogMessageRegExp('~/replace-existing.+already exists~', $target, Project::MSG_VERBOSE); - $this->assertFileExists($targetDefaultFilePath); - $this->assertSame('DEFAULT-EXISTING', file_get_contents($targetDefaultFilePath)); + Assert::assertFileExists($targetDefaultFilePath); + Assert::assertSame('DEFAULT-EXISTING', file_get_contents($targetDefaultFilePath)); } public function testCopyMultipleFilesWithExistingTargetsUsingDifferentModesWithReplaceFallback(): void @@ -213,14 +214,14 @@ public function testCopyMultipleFilesWithExistingTargetsUsingDifferentModesWithR $target = __FUNCTION__; $tester->executeTarget($target); - $this->assertFileExists($targetSkipFilePath); - $this->assertSame('SKIP-EXISTING', file_get_contents($targetSkipFilePath)); + Assert::assertFileExists($targetSkipFilePath); + Assert::assertSame('SKIP-EXISTING', file_get_contents($targetSkipFilePath)); - $this->assertFileEquals($sourceReplaceFilePath, $targetReplaceFilePath); + Assert::assertFileEquals($sourceReplaceFilePath, $targetReplaceFilePath); $tester->assertLogMessageRegExp('~Copying.+/replace-new.+->.+/replace-existing~', $target, Project::MSG_INFO); $tester->assertLogMessageRegExp('~/replace-existing.+already exists~', $target, Project::MSG_VERBOSE); - $this->assertFileEquals($sourceDefaultFilePath, $targetDefaultFilePath); + Assert::assertFileEquals($sourceDefaultFilePath, $targetDefaultFilePath); $tester->assertLogMessageRegExp('~Copying.+/default-new.+->.+/default-existing~', $target, Project::MSG_INFO); $tester->assertLogMessageRegExp('~/default-existing.+already exists~', $target, Project::MSG_VERBOSE); } From ae4b8c83a5e52c75e2fcb85995fbb7358eb2cc03 Mon Sep 17 00:00:00 2001 From: Petr Duda Date: Tue, 28 Mar 2023 11:40:39 +0200 Subject: [PATCH 2/5] use try+catch+fail when expecting exceptions with properties --- tests/CopyFilesTaskIntegrationTest.php | 56 +++++++++++++++++--------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/tests/CopyFilesTaskIntegrationTest.php b/tests/CopyFilesTaskIntegrationTest.php index 9c8fbe6..316308e 100644 --- a/tests/CopyFilesTaskIntegrationTest.php +++ b/tests/CopyFilesTaskIntegrationTest.php @@ -266,46 +266,62 @@ public function testCopyFileToNonExistingDirectory(): void public function testMissingCopyFileElement(): void { - $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml'); + $buildFilePath = __DIR__ . '/copy-files-task-integration-test.xml'; + $tester = new PhingTester($buildFilePath); $target = __FUNCTION__; - $this->expectException(\BuildException::class); - $this->expectExceptionMessageMatches('~one.+.+expected~'); - - $tester->executeTarget($target); + try { + $tester->executeTarget($target); + Assert::fail('Exception expected'); + } catch (\BuildException $e) { + Assert::assertStringStartsWith($buildFilePath, $e->getLocation()->toString()); + Assert::assertRegExp('~one.+.+expected~', $e->getMessage()); + } } public function testMissingSource(): void { - $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml'); + $buildFilePath = __DIR__ . '/copy-files-task-integration-test.xml'; + $tester = new PhingTester($buildFilePath); $target = __FUNCTION__; - $this->expectException(\BuildException::class); - $this->expectExceptionMessageMatches('~.+`source`~'); - - $tester->executeTarget($target); + try { + $tester->executeTarget($target); + Assert::fail('Exception expected'); + } catch (\BuildException $e) { + Assert::assertStringStartsWith($buildFilePath, $e->getLocation()->toString()); + Assert::assertRegExp('~.+`source`~', $e->getMessage()); + } } public function testMissingTarget(): void { - $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml'); + $buildFilePath = __DIR__ . '/copy-files-task-integration-test.xml'; + $tester = new PhingTester($buildFilePath); $target = __FUNCTION__; - $this->expectException(\BuildException::class); - $this->expectExceptionMessageMatches('~.+`target`~'); - - $tester->executeTarget($target); + try { + $tester->executeTarget($target); + Assert::fail('Exception expected'); + } catch (\BuildException $e) { + Assert::assertStringStartsWith($buildFilePath, $e->getLocation()->toString()); + Assert::assertRegExp('~.+`target`~', $e->getMessage()); + } } public function testInvalidFileExistsMode(): void { - $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml'); + $buildFilePath = __DIR__ . '/copy-files-task-integration-test.xml'; + $tester = new PhingTester($buildFilePath); $target = __FUNCTION__; - $this->expectException(\BuildException::class); - $this->expectExceptionMessageMatches('~invalid.+mode~i'); - - $tester->executeTarget($target); + try { + $tester->executeTarget($target); + Assert::fail('Exception expected'); + } catch (\BuildException $e) { + Assert::assertStringStartsWith($buildFilePath, $e->getLocation()->toString()); + Assert::assertRegExp('~invalid.+mode~i', $e->getMessage()); + } } } From c851cb000dc13df5d91493b9dce7b9a152628fcf Mon Sep 17 00:00:00 2001 From: Petr Duda Date: Wed, 5 Apr 2023 11:24:25 +0200 Subject: [PATCH 3/5] deduplicate testing copying file using data provider --- tests/CopyFilesTaskIntegrationTest.php | 158 ++++++++++++++----------- 1 file changed, 90 insertions(+), 68 deletions(-) diff --git a/tests/CopyFilesTaskIntegrationTest.php b/tests/CopyFilesTaskIntegrationTest.php index 316308e..312e2da 100644 --- a/tests/CopyFilesTaskIntegrationTest.php +++ b/tests/CopyFilesTaskIntegrationTest.php @@ -4,6 +4,7 @@ namespace VasekPurchart\Phing\CopyFiles; +use Generator; use PHPUnit\Framework\Assert; use Project; use VasekPurchart\Phing\PhingTester\PhingTester; @@ -13,85 +14,106 @@ class CopyFilesTaskIntegrationTest extends \PHPUnit\Framework\TestCase private const TEMP_DIRECTORY_PATH = __DIR__ . '/temp'; - public function testCopyFile(): void + /** + * @return mixed[][]|\Generator + */ + public function copyFileDataProvider(): Generator { - $sourceFilePath = self::TEMP_DIRECTORY_PATH . '/foo'; - file_put_contents($sourceFilePath, 'FOO'); - $targetFilePath = self::TEMP_DIRECTORY_PATH . '/foo-copy'; - if (file_exists($targetFilePath)) { - unlink($targetFilePath); - } - - $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml', self::TEMP_DIRECTORY_PATH); - $target = __FUNCTION__; - $tester->executeTarget($target); - - Assert::assertFileEquals($sourceFilePath, $targetFilePath); - $tester->assertLogMessageRegExp('~Copying.+/foo.+->.+/foo-copy~', $target, Project::MSG_INFO); + yield 'copy file' => [ + 'target' => 'testCopyFile', + 'sourceFileName' => '/foo', + 'targetFileName' => '/foo-copy', + 'existingSourceFileContents' => 'FOO', + 'existingTargetFileContents' => null, + 'expectedTargetFileContents' => 'FOO', + 'logMessageRegExp' => '~Copying.+/foo.+->.+/foo-copy~', + 'logMessagePriority' => Project::MSG_INFO, + ]; + + yield 'copy file with absolute path' => [ + 'target' => 'testCopyFileWithAbsolutePath', + 'sourceFileName' => '/foo', + 'targetFileName' => '/foo-copy', + 'existingSourceFileContents' => 'FOO', + 'existingTargetFileContents' => null, + 'expectedTargetFileContents' => 'FOO', + 'logMessageRegExp' => '~Copying.+/foo.+->.+/foo-copy~', + 'logMessagePriority' => Project::MSG_INFO, + ]; + + yield 'target file exists' => [ + 'target' => 'testTargetFileExists', + 'sourceFileName' => '/new', + 'targetFileName' => '/existing', + 'existingSourceFileContents' => 'NEW', + 'existingTargetFileContents' => 'EXISTING', + 'expectedTargetFileContents' => 'EXISTING', + 'logMessageRegExp' => '~/existing.+already exists.+SKIPPING~', + 'logMessagePriority' => Project::MSG_INFO, + ]; + + yield 'target file exists skip' => [ + 'target' => 'testTargetFileExistsSkip', + 'sourceFileName' => '/new', + 'targetFileName' => '/existing', + 'existingSourceFileContents' => 'NEW', + 'existingTargetFileContents' => 'EXISTING', + 'expectedTargetFileContents' => 'EXISTING', + 'logMessageRegExp' => '~/existing.+already exists.+SKIPPING~', + 'logMessagePriority' => Project::MSG_INFO, + ]; + + yield 'target file exists replace' => [ + 'target' => 'testTargetFileExistsReplace', + 'sourceFileName' => '/new', + 'targetFileName' => '/existing', + 'existingSourceFileContents' => 'NEW', + 'existingTargetFileContents' => 'EXISTING', + 'expectedTargetFileContents' => 'NEW', + 'logMessageRegExp' => '~/existing.+already exists~', + 'logMessagePriority' => Project::MSG_VERBOSE, + ]; } - public function testCopyFileWithAbsolutePath(): void + /** + * @dataProvider copyFileDataProvider + * + * @param string $target + * @param string $sourceFileName + * @param string $targetFileName + * @param string $existingSourceFileContents + * @param string|null $existingTargetFileContents + * @param string $expectedTargetFileContents + * @param string $logMessageRegExp + * @param int $logMessagePriority + */ + public function testCopyFile( + string $target, + string $sourceFileName, + string $targetFileName, + string $existingSourceFileContents, + ?string $existingTargetFileContents, + string $expectedTargetFileContents, + string $logMessageRegExp, + int $logMessagePriority + ): void { - $sourceFilePath = self::TEMP_DIRECTORY_PATH . '/foo'; - file_put_contents($sourceFilePath, 'FOO'); - $targetFilePath = self::TEMP_DIRECTORY_PATH . '/foo-copy'; - if (file_exists($targetFilePath)) { + $sourceFilePath = self::TEMP_DIRECTORY_PATH . $sourceFileName; + file_put_contents($sourceFilePath, $existingSourceFileContents); + + $targetFilePath = self::TEMP_DIRECTORY_PATH . $targetFileName; + if ($existingTargetFileContents !== null) { + file_put_contents($targetFilePath, $existingTargetFileContents); + } elseif (file_exists($targetFilePath)) { unlink($targetFilePath); } $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml', self::TEMP_DIRECTORY_PATH); - $target = __FUNCTION__; - $tester->executeTarget($target); - - Assert::assertFileEquals($sourceFilePath, $targetFilePath); - $tester->assertLogMessageRegExp('~Copying.+/foo.+->.+/foo-copy~', $target, Project::MSG_INFO); - } - - public function testTargetFileExists(): void - { - $sourceFilePath = self::TEMP_DIRECTORY_PATH . '/new'; - file_put_contents($sourceFilePath, 'NEW'); - $targetFilePath = self::TEMP_DIRECTORY_PATH . '/existing'; - file_put_contents($targetFilePath, 'EXISTING'); - - $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml', self::TEMP_DIRECTORY_PATH); - $target = __FUNCTION__; - $tester->executeTarget($target); - - Assert::assertFileExists($targetFilePath); - Assert::assertSame('EXISTING', file_get_contents($targetFilePath)); - $tester->assertLogMessageRegExp('~/existing.+already exists.+SKIPPING~', $target, Project::MSG_INFO); - } - - public function testTargetFileExistsSkip(): void - { - $sourceFilePath = self::TEMP_DIRECTORY_PATH . '/new'; - file_put_contents($sourceFilePath, 'NEW'); - $targetFilePath = self::TEMP_DIRECTORY_PATH . '/existing'; - file_put_contents($targetFilePath, 'EXISTING'); - - $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml', self::TEMP_DIRECTORY_PATH); - $target = __FUNCTION__; $tester->executeTarget($target); Assert::assertFileExists($targetFilePath); - Assert::assertSame('EXISTING', file_get_contents($targetFilePath)); - $tester->assertLogMessageRegExp('~/existing.+already exists.+SKIPPING~', $target, Project::MSG_INFO); - } - - public function testTargetFileExistsReplace(): void - { - $sourceFilePath = self::TEMP_DIRECTORY_PATH . '/new'; - file_put_contents($sourceFilePath, 'NEW'); - $targetFilePath = self::TEMP_DIRECTORY_PATH . '/existing'; - file_put_contents($targetFilePath, 'EXISTING'); - - $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml', self::TEMP_DIRECTORY_PATH); - $target = __FUNCTION__; - $tester->executeTarget($target); - - Assert::assertFileEquals($sourceFilePath, $targetFilePath); - $tester->assertLogMessageRegExp('~/existing.+already exists~', $target, Project::MSG_VERBOSE); + Assert::assertSame($expectedTargetFileContents, file_get_contents($targetFilePath)); + $tester->assertLogMessageRegExp($logMessageRegExp, $target, $logMessagePriority); } public function testTargetFileExistsFail(): void From 10b033272ad613f1f6aa77c9784875253233a5d7 Mon Sep 17 00:00:00 2001 From: Petr Duda Date: Wed, 5 Apr 2023 11:17:55 +0200 Subject: [PATCH 4/5] deduplicate testing throwing BuildException using data provider --- tests/CopyFilesTaskIntegrationTest.php | 73 +++++++++++--------------- 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/tests/CopyFilesTaskIntegrationTest.php b/tests/CopyFilesTaskIntegrationTest.php index 312e2da..7170396 100644 --- a/tests/CopyFilesTaskIntegrationTest.php +++ b/tests/CopyFilesTaskIntegrationTest.php @@ -286,63 +286,52 @@ public function testCopyFileToNonExistingDirectory(): void $tester->assertLogMessageRegExp('~/foo.+cannot be copied.+/foo-copy~', $target, Project::MSG_ERR); } - public function testMissingCopyFileElement(): void - { - $buildFilePath = __DIR__ . '/copy-files-task-integration-test.xml'; - $tester = new PhingTester($buildFilePath); - $target = __FUNCTION__; - - try { - $tester->executeTarget($target); - Assert::fail('Exception expected'); - } catch (\BuildException $e) { - Assert::assertStringStartsWith($buildFilePath, $e->getLocation()->toString()); - Assert::assertRegExp('~one.+.+expected~', $e->getMessage()); - } - } - - public function testMissingSource(): void + /** + * @return mixed[][]|\Generator + */ + public function throwBuildExceptionDataProvider(): Generator { - $buildFilePath = __DIR__ . '/copy-files-task-integration-test.xml'; - $tester = new PhingTester($buildFilePath); - $target = __FUNCTION__; + yield 'missing copy file element' => [ + 'target' => 'testMissingCopyFileElement', + 'expectedMessagePatternRegExp' => '~one.+.+expected~', + ]; - try { - $tester->executeTarget($target); - Assert::fail('Exception expected'); - } catch (\BuildException $e) { - Assert::assertStringStartsWith($buildFilePath, $e->getLocation()->toString()); - Assert::assertRegExp('~.+`source`~', $e->getMessage()); - } - } + yield 'missing source' => [ + 'target' => 'testMissingSource', + 'expectedMessagePatternRegExp' => '~.+`source`~', + ]; - public function testMissingTarget(): void - { - $buildFilePath = __DIR__ . '/copy-files-task-integration-test.xml'; - $tester = new PhingTester($buildFilePath); - $target = __FUNCTION__; + yield 'missing target' => [ + 'target' => 'testMissingTarget', + 'expectedMessagePatternRegExp' => '~.+`target`~', + ]; - try { - $tester->executeTarget($target); - Assert::fail('Exception expected'); - } catch (\BuildException $e) { - Assert::assertStringStartsWith($buildFilePath, $e->getLocation()->toString()); - Assert::assertRegExp('~.+`target`~', $e->getMessage()); - } + yield 'invalid file exists mode' => [ + 'target' => 'testInvalidFileExistsMode', + 'expectedMessagePatternRegExp' => '~invalid.+mode~i', + ]; } - public function testInvalidFileExistsMode(): void + /** + * @dataProvider throwBuildExceptionDataProvider + * + * @param string $target + * @param string $expectedMessagePatternRegExp + */ + public function testThrowBuildException( + string $target, + string $expectedMessagePatternRegExp + ): void { $buildFilePath = __DIR__ . '/copy-files-task-integration-test.xml'; $tester = new PhingTester($buildFilePath); - $target = __FUNCTION__; try { $tester->executeTarget($target); Assert::fail('Exception expected'); } catch (\BuildException $e) { Assert::assertStringStartsWith($buildFilePath, $e->getLocation()->toString()); - Assert::assertRegExp('~invalid.+mode~i', $e->getMessage()); + Assert::assertRegExp($expectedMessagePatternRegExp, $e->getMessage()); } } From ddbad068d56f5505616f171f1c92593d22894963 Mon Sep 17 00:00:00 2001 From: Petr Duda Date: Wed, 5 Apr 2023 11:43:58 +0200 Subject: [PATCH 5/5] rename targets to kebab-case --- tests/CopyFilesTaskIntegrationTest.php | 34 +++++++++++----------- tests/copy-files-task-integration-test.xml | 34 +++++++++++----------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/tests/CopyFilesTaskIntegrationTest.php b/tests/CopyFilesTaskIntegrationTest.php index 7170396..c356cf2 100644 --- a/tests/CopyFilesTaskIntegrationTest.php +++ b/tests/CopyFilesTaskIntegrationTest.php @@ -20,7 +20,7 @@ class CopyFilesTaskIntegrationTest extends \PHPUnit\Framework\TestCase public function copyFileDataProvider(): Generator { yield 'copy file' => [ - 'target' => 'testCopyFile', + 'target' => 'copy-file', 'sourceFileName' => '/foo', 'targetFileName' => '/foo-copy', 'existingSourceFileContents' => 'FOO', @@ -31,7 +31,7 @@ public function copyFileDataProvider(): Generator ]; yield 'copy file with absolute path' => [ - 'target' => 'testCopyFileWithAbsolutePath', + 'target' => 'copy-file-with-absolute-path', 'sourceFileName' => '/foo', 'targetFileName' => '/foo-copy', 'existingSourceFileContents' => 'FOO', @@ -42,7 +42,7 @@ public function copyFileDataProvider(): Generator ]; yield 'target file exists' => [ - 'target' => 'testTargetFileExists', + 'target' => 'target-file-exists', 'sourceFileName' => '/new', 'targetFileName' => '/existing', 'existingSourceFileContents' => 'NEW', @@ -53,7 +53,7 @@ public function copyFileDataProvider(): Generator ]; yield 'target file exists skip' => [ - 'target' => 'testTargetFileExistsSkip', + 'target' => 'target-file-exists-skip', 'sourceFileName' => '/new', 'targetFileName' => '/existing', 'existingSourceFileContents' => 'NEW', @@ -64,7 +64,7 @@ public function copyFileDataProvider(): Generator ]; yield 'target file exists replace' => [ - 'target' => 'testTargetFileExistsReplace', + 'target' => 'target-file-exists-replace', 'sourceFileName' => '/new', 'targetFileName' => '/existing', 'existingSourceFileContents' => 'NEW', @@ -124,7 +124,7 @@ public function testTargetFileExistsFail(): void file_put_contents($targetFilePath, 'EXISTING'); $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml', self::TEMP_DIRECTORY_PATH); - $target = __FUNCTION__; + $target = 'target-file-exists-fail'; $tester->expectFailedBuild($target); @@ -149,7 +149,7 @@ public function testCopyMultipleFiles(): void } $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml', self::TEMP_DIRECTORY_PATH); - $target = __FUNCTION__; + $target = 'copy-multiple-files'; $tester->executeTarget($target); Assert::assertFileEquals($sourceFooFilePath, $targetFooFilePath); @@ -171,7 +171,7 @@ public function testReplaceMultipleFilesWithExistingTargets(): void file_put_contents($targetBarFilePath, 'BAR-EXISTING'); $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml', self::TEMP_DIRECTORY_PATH); - $target = __FUNCTION__; + $target = 'replace-multiple-files-with-existing-targets'; $tester->executeTarget($target); Assert::assertFileEquals($sourceFooFilePath, $targetFooFilePath); @@ -201,7 +201,7 @@ public function testCopyMultipleFilesWithExistingTargetsUsingDifferentModes(): v file_put_contents($targetDefaultFilePath, 'DEFAULT-EXISTING'); $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml', self::TEMP_DIRECTORY_PATH); - $target = __FUNCTION__; + $target = 'copy-multiple-files-with-existing-targets-using-different-modes'; $tester->executeTarget($target); Assert::assertFileExists($targetSkipFilePath); @@ -233,7 +233,7 @@ public function testCopyMultipleFilesWithExistingTargetsUsingDifferentModesWithR file_put_contents($targetDefaultFilePath, 'DEFAULT-EXISTING'); $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml', self::TEMP_DIRECTORY_PATH); - $target = __FUNCTION__; + $target = 'copy-multiple-files-with-existing-targets-using-different-modes-with-replace-fallback'; $tester->executeTarget($target); Assert::assertFileExists($targetSkipFilePath); @@ -251,7 +251,7 @@ public function testCopyMultipleFilesWithExistingTargetsUsingDifferentModesWithR public function testCopyNonExistentFile(): void { $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml'); - $target = __FUNCTION__; + $target = 'copy-non-existent-file'; $tester->expectFailedBuild($target); @@ -261,7 +261,7 @@ public function testCopyNonExistentFile(): void public function testCopyMultipleNonExistentFiles(): void { $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml'); - $target = __FUNCTION__; + $target = 'copy-multiple-non-existent-files'; $tester->expectFailedBuild($target); @@ -279,7 +279,7 @@ public function testCopyFileToNonExistingDirectory(): void } $tester = new PhingTester(__DIR__ . '/copy-files-task-integration-test.xml', self::TEMP_DIRECTORY_PATH); - $target = __FUNCTION__; + $target = 'copy-file-to-non-existing-directory'; $tester->expectFailedBuild($target); @@ -292,22 +292,22 @@ public function testCopyFileToNonExistingDirectory(): void public function throwBuildExceptionDataProvider(): Generator { yield 'missing copy file element' => [ - 'target' => 'testMissingCopyFileElement', + 'target' => 'missing-copy-file-element', 'expectedMessagePatternRegExp' => '~one.+.+expected~', ]; yield 'missing source' => [ - 'target' => 'testMissingSource', + 'target' => 'missing-source', 'expectedMessagePatternRegExp' => '~.+`source`~', ]; yield 'missing target' => [ - 'target' => 'testMissingTarget', + 'target' => 'missing-target', 'expectedMessagePatternRegExp' => '~.+`target`~', ]; yield 'invalid file exists mode' => [ - 'target' => 'testInvalidFileExistsMode', + 'target' => 'invalid-file-exists-mode', 'expectedMessagePatternRegExp' => '~invalid.+mode~i', ]; } diff --git a/tests/copy-files-task-integration-test.xml b/tests/copy-files-task-integration-test.xml index 2160312..aa68395 100644 --- a/tests/copy-files-task-integration-test.xml +++ b/tests/copy-files-task-integration-test.xml @@ -3,57 +3,57 @@ - + - + - + - + - + - + - + - + - + @@ -61,7 +61,7 @@ - + @@ -69,43 +69,43 @@ - + - + - + - + - + - + - +