Skip to content

Commit 10b0332

Browse files
committed
deduplicate testing throwing BuildException using data provider
1 parent c851cb0 commit 10b0332

1 file changed

Lines changed: 31 additions & 42 deletions

File tree

tests/CopyFilesTaskIntegrationTest.php

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -286,63 +286,52 @@ public function testCopyFileToNonExistingDirectory(): void
286286
$tester->assertLogMessageRegExp('~/foo.+cannot be copied.+/foo-copy~', $target, Project::MSG_ERR);
287287
}
288288

289-
public function testMissingCopyFileElement(): void
290-
{
291-
$buildFilePath = __DIR__ . '/copy-files-task-integration-test.xml';
292-
$tester = new PhingTester($buildFilePath);
293-
$target = __FUNCTION__;
294-
295-
try {
296-
$tester->executeTarget($target);
297-
Assert::fail('Exception expected');
298-
} catch (\BuildException $e) {
299-
Assert::assertStringStartsWith($buildFilePath, $e->getLocation()->toString());
300-
Assert::assertRegExp('~one.+<file>.+expected~', $e->getMessage());
301-
}
302-
}
303-
304-
public function testMissingSource(): void
289+
/**
290+
* @return mixed[][]|\Generator
291+
*/
292+
public function throwBuildExceptionDataProvider(): Generator
305293
{
306-
$buildFilePath = __DIR__ . '/copy-files-task-integration-test.xml';
307-
$tester = new PhingTester($buildFilePath);
308-
$target = __FUNCTION__;
294+
yield 'missing copy file element' => [
295+
'target' => 'testMissingCopyFileElement',
296+
'expectedMessagePatternRegExp' => '~one.+<file>.+expected~',
297+
];
309298

310-
try {
311-
$tester->executeTarget($target);
312-
Assert::fail('Exception expected');
313-
} catch (\BuildException $e) {
314-
Assert::assertStringStartsWith($buildFilePath, $e->getLocation()->toString());
315-
Assert::assertRegExp('~<file>.+`source`~', $e->getMessage());
316-
}
317-
}
299+
yield 'missing source' => [
300+
'target' => 'testMissingSource',
301+
'expectedMessagePatternRegExp' => '~<file>.+`source`~',
302+
];
318303

319-
public function testMissingTarget(): void
320-
{
321-
$buildFilePath = __DIR__ . '/copy-files-task-integration-test.xml';
322-
$tester = new PhingTester($buildFilePath);
323-
$target = __FUNCTION__;
304+
yield 'missing target' => [
305+
'target' => 'testMissingTarget',
306+
'expectedMessagePatternRegExp' => '~<file>.+`target`~',
307+
];
324308

325-
try {
326-
$tester->executeTarget($target);
327-
Assert::fail('Exception expected');
328-
} catch (\BuildException $e) {
329-
Assert::assertStringStartsWith($buildFilePath, $e->getLocation()->toString());
330-
Assert::assertRegExp('~<file>.+`target`~', $e->getMessage());
331-
}
309+
yield 'invalid file exists mode' => [
310+
'target' => 'testInvalidFileExistsMode',
311+
'expectedMessagePatternRegExp' => '~invalid.+mode~i',
312+
];
332313
}
333314

334-
public function testInvalidFileExistsMode(): void
315+
/**
316+
* @dataProvider throwBuildExceptionDataProvider
317+
*
318+
* @param string $target
319+
* @param string $expectedMessagePatternRegExp
320+
*/
321+
public function testThrowBuildException(
322+
string $target,
323+
string $expectedMessagePatternRegExp
324+
): void
335325
{
336326
$buildFilePath = __DIR__ . '/copy-files-task-integration-test.xml';
337327
$tester = new PhingTester($buildFilePath);
338-
$target = __FUNCTION__;
339328

340329
try {
341330
$tester->executeTarget($target);
342331
Assert::fail('Exception expected');
343332
} catch (\BuildException $e) {
344333
Assert::assertStringStartsWith($buildFilePath, $e->getLocation()->toString());
345-
Assert::assertRegExp('~invalid.+mode~i', $e->getMessage());
334+
Assert::assertRegExp($expectedMessagePatternRegExp, $e->getMessage());
346335
}
347336
}
348337

0 commit comments

Comments
 (0)