Skip to content

Commit 5942c80

Browse files
committed
deduplicate testing calling command using data provider
1 parent 11031a5 commit 5942c80

1 file changed

Lines changed: 48 additions & 53 deletions

File tree

tests/SymfonyCommandTaskIntegrationTest.php

Lines changed: 48 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,70 @@
44

55
namespace VasekPurchart\Phing\SymfonyCommand;
66

7+
use Generator;
78
use PHPUnit\Framework\Assert;
89
use Project;
910
use VasekPurchart\Phing\PhingTester\PhingTester;
1011

1112
class SymfonyCommandTaskIntegrationTest extends \PHPUnit\Framework\TestCase
1213
{
1314

14-
public function testCallCommand(): void
15+
/**
16+
* @return mixed[][]|\Generator
17+
*/
18+
public function callCommandDataProvider(): Generator
1519
{
16-
$tester = new PhingTester(__DIR__ . '/symfony-command-task-integration-test.xml');
17-
$target = __FUNCTION__;
18-
$tester->executeTarget($target);
19-
20-
$tester->assertLogMessageRegExp(sprintf(
21-
'~executing.+%s.+%s.+hello:world~i',
22-
$tester->getProject()->getProperty(__FUNCTION__ . '.default.executable'),
23-
$tester->getProject()->getProperty(__FUNCTION__ . '.default.app')
24-
), $target, Project::MSG_VERBOSE);
20+
yield 'call command' => [
21+
'target' => 'testCallCommand',
22+
'expectedLogMessageRegExpExecutable' => '.default.executable',
23+
'expectedLogMessageRegExpApp' => '.default.app',
24+
];
25+
26+
yield 'call command with custom executable' => [
27+
'target' => 'testCallCommandWithCustomExecutable',
28+
'expectedLogMessageRegExpExecutable' => '.test.executable',
29+
'expectedLogMessageRegExpApp' => '.default.app',
30+
];
31+
32+
yield 'call command with custom app' => [
33+
'target' => 'testCallCommandWithCustomApp',
34+
'expectedLogMessageRegExpExecutable' => '.default.executable',
35+
'expectedLogMessageRegExpApp' => '.test.app',
36+
];
37+
38+
yield 'call command with custom executable and app' => [
39+
'target' => 'testCallCommandWithCustomExecutableAndApp',
40+
'expectedLogMessageRegExpExecutable' => '.test.executable',
41+
'expectedLogMessageRegExpApp' => '.test.app',
42+
];
43+
44+
yield 'call command and override defaults' => [
45+
'target' => 'testCallCommandAndOverrideDefaults',
46+
'expectedLogMessageRegExpExecutable' => '.test.executable',
47+
'expectedLogMessageRegExpApp' => '.test.app',
48+
];
2549
}
2650

27-
public function testCallCommandWithCustomExecutable(): void
51+
/**
52+
* @dataProvider callCommandDataProvider
53+
*
54+
* @param string $target
55+
* @param string $expectedLogMessageRegExpExecutable
56+
* @param string $expectedLogMessageRegExpApp
57+
*/
58+
public function testCallCommand(
59+
string $target,
60+
string $expectedLogMessageRegExpExecutable,
61+
string $expectedLogMessageRegExpApp
62+
): void
2863
{
2964
$tester = new PhingTester(__DIR__ . '/symfony-command-task-integration-test.xml');
30-
$target = __FUNCTION__;
3165
$tester->executeTarget($target);
3266

3367
$tester->assertLogMessageRegExp(sprintf(
3468
'~executing.+%s.+%s.+hello:world~i',
35-
$tester->getProject()->getProperty(__FUNCTION__ . '.test.executable'),
36-
$tester->getProject()->getProperty(__FUNCTION__ . '.default.app')
37-
), $target, Project::MSG_VERBOSE);
38-
}
39-
40-
public function testCallCommandWithCustomApp(): void
41-
{
42-
$tester = new PhingTester(__DIR__ . '/symfony-command-task-integration-test.xml');
43-
$target = __FUNCTION__;
44-
$tester->executeTarget($target);
45-
46-
$tester->assertLogMessageRegExp(sprintf(
47-
'~executing.+%s.+%s.+hello:world~i',
48-
$tester->getProject()->getProperty(__FUNCTION__ . '.default.executable'),
49-
$tester->getProject()->getProperty(__FUNCTION__ . '.test.app')
50-
), $target, Project::MSG_VERBOSE);
51-
}
52-
53-
public function testCallCommandWithCustomExecutableAndApp(): void
54-
{
55-
$tester = new PhingTester(__DIR__ . '/symfony-command-task-integration-test.xml');
56-
$target = __FUNCTION__;
57-
$tester->executeTarget($target);
58-
59-
$tester->assertLogMessageRegExp(sprintf(
60-
'~executing.+%s.+%s.+hello:world~i',
61-
$tester->getProject()->getProperty(__FUNCTION__ . '.test.executable'),
62-
$tester->getProject()->getProperty(__FUNCTION__ . '.test.app')
69+
$tester->getProject()->getProperty($target . $expectedLogMessageRegExpExecutable),
70+
$tester->getProject()->getProperty($target . $expectedLogMessageRegExpApp)
6371
), $target, Project::MSG_VERBOSE);
6472
}
6573

@@ -75,19 +83,6 @@ public function testCallCommandWithAppAsExecutable(): void
7583
), $target, Project::MSG_VERBOSE);
7684
}
7785

78-
public function testCallCommandAndOverrideDefaults(): void
79-
{
80-
$tester = new PhingTester(__DIR__ . '/symfony-command-task-integration-test.xml');
81-
$target = __FUNCTION__;
82-
$tester->executeTarget($target);
83-
84-
$tester->assertLogMessageRegExp(sprintf(
85-
'~executing.+%s.+%s.+hello:world~i',
86-
$tester->getProject()->getProperty(__FUNCTION__ . '.test.executable'),
87-
$tester->getProject()->getProperty(__FUNCTION__ . '.test.app')
88-
), $target, Project::MSG_VERBOSE);
89-
}
90-
9186
public function testMissingApp(): void
9287
{
9388
$buildFilePath = __DIR__ . '/symfony-command-task-integration-test.xml';

0 commit comments

Comments
 (0)