-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSymfonyCommandTaskIntegrationTest.php
More file actions
130 lines (107 loc) · 3.7 KB
/
SymfonyCommandTaskIntegrationTest.php
File metadata and controls
130 lines (107 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
declare(strict_types = 1);
namespace VasekPurchart\Phing\SymfonyCommand;
use Consistence\Type\Type;
use Generator;
use PHPUnit\Framework\Assert;
use Project;
use VasekPurchart\Phing\PhingTester\PhingTester;
class SymfonyCommandTaskIntegrationTest extends \PHPUnit\Framework\TestCase
{
/**
* @return mixed[][]|\Generator
*/
public function callCommandDataProvider(): Generator
{
yield 'call command' => (static function (): array {
$target = 'call-command';
return [
'target' => $target,
'propertyNameWithExpectedExecutable' => $target . '.default.executable',
'propertyNameWithExpectedApp' => $target . '.default.app',
];
})();
yield 'call command with custom executable' => (static function (): array {
$target = 'call-command-with-custom-executable';
return [
'target' => $target,
'propertyNameWithExpectedExecutable' => $target . '.test.executable',
'propertyNameWithExpectedApp' => $target . '.default.app',
];
})();
yield 'call command with custom app' => (static function (): array {
$target = 'call-command-with-custom-app';
return [
'target' => $target,
'propertyNameWithExpectedExecutable' => $target . '.default.executable',
'propertyNameWithExpectedApp' => $target . '.test.app',
];
})();
yield 'call command with custom executable and app' => (static function (): array {
$target = 'call-command-with-custom-executable-and-app';
return [
'target' => $target,
'propertyNameWithExpectedExecutable' => $target . '.test.executable',
'propertyNameWithExpectedApp' => $target . '.test.app',
];
})();
yield 'call command and override defaults' => (static function (): array {
$target = 'call-command-and-override-defaults';
return [
'target' => $target,
'propertyNameWithExpectedExecutable' => $target . '.test.executable',
'propertyNameWithExpectedApp' => $target . '.test.app',
];
})();
}
/**
* @dataProvider callCommandDataProvider
*
* @param string $target
* @param string $propertyNameWithExpectedExecutable
* @param string $propertyNameWithExpectedApp
*/
public function testCallCommand(
string $target,
string $propertyNameWithExpectedExecutable,
string $propertyNameWithExpectedApp
): void
{
$tester = new PhingTester(__DIR__ . '/symfony-command-task-integration-test.xml');
$tester->executeTarget($target);
$expectedExecutable = $tester->getProject()->getProperty($propertyNameWithExpectedExecutable);
$expectedApp = $tester->getProject()->getProperty($propertyNameWithExpectedApp);
Type::checkType($expectedExecutable, 'string');
Type::checkType($expectedApp, 'string');
$tester->assertLogMessageRegExp(sprintf(
'~executing.+%s.+%s.+hello:world~i',
$expectedExecutable,
$expectedApp
), $target, Project::MSG_VERBOSE);
}
public function testCallCommandWithAppAsExecutable(): void
{
$tester = new PhingTester(__DIR__ . '/symfony-command-task-integration-test.xml');
$target = 'call-command-with-app-as-executable';
$tester->executeTarget($target);
$expectedApp = $tester->getProject()->getProperty($target . '.test.app');
Type::checkType($expectedApp, 'string');
$tester->assertLogMessageRegExp(sprintf(
'~executing.+%s.+hello:world~i',
$expectedApp
), $target, Project::MSG_VERBOSE);
}
public function testMissingApp(): void
{
$buildFilePath = __DIR__ . '/symfony-command-task-integration-test.xml';
$tester = new PhingTester($buildFilePath);
$target = 'missing-app';
try {
$tester->executeTarget($target);
Assert::fail('Exception expected');
} catch (\BuildException $e) {
Assert::assertStringStartsWith($buildFilePath, $e->getLocation()->toString());
Assert::assertRegExp('~app.+required~', $e->getMessage());
}
}
}