Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"require-dev": {
"consistence/coding-standard": "3.10.1",
"consistence/consistence": "2.0.2",
"maglnet/composer-require-checker": "2.0",
"php-parallel-lint/php-console-highlighter": "1.0",
"php-parallel-lint/php-parallel-lint": "1.3.2",
Expand Down
151 changes: 90 additions & 61 deletions tests/SymfonyCommandTaskIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,98 +4,127 @@

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
{

public function testCallCommand(): void
/**
* @return mixed[][]|\Generator
*/
public function callCommandDataProvider(): Generator
{
$tester = new PhingTester(__DIR__ . '/symfony-command-task-integration-test.xml');
$target = __FUNCTION__;
$tester->executeTarget($target);

$tester->assertLogMessageRegExp(sprintf(
'~executing.+%s.+%s.+hello:world~i',
$tester->getProject()->getProperty(__FUNCTION__ . '.default.executable'),
$tester->getProject()->getProperty(__FUNCTION__ . '.default.app')
), $target, Project::MSG_VERBOSE);
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',
];
})();
}

public function testCallCommandWithCustomExecutable(): void
/**
* @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');
$target = __FUNCTION__;
$tester->executeTarget($target);

$tester->assertLogMessageRegExp(sprintf(
'~executing.+%s.+%s.+hello:world~i',
$tester->getProject()->getProperty(__FUNCTION__ . '.test.executable'),
$tester->getProject()->getProperty(__FUNCTION__ . '.default.app')
), $target, Project::MSG_VERBOSE);
}

public function testCallCommandWithCustomApp(): void
{
$tester = new PhingTester(__DIR__ . '/symfony-command-task-integration-test.xml');
$target = __FUNCTION__;
$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',
$tester->getProject()->getProperty(__FUNCTION__ . '.default.executable'),
$tester->getProject()->getProperty(__FUNCTION__ . '.test.app')
), $target, Project::MSG_VERBOSE);
}

public function testCallCommandWithCustomExecutableAndApp(): void
{
$tester = new PhingTester(__DIR__ . '/symfony-command-task-integration-test.xml');
$target = __FUNCTION__;
$tester->executeTarget($target);

$tester->assertLogMessageRegExp(sprintf(
'~executing.+%s.+%s.+hello:world~i',
$tester->getProject()->getProperty(__FUNCTION__ . '.test.executable'),
$tester->getProject()->getProperty(__FUNCTION__ . '.test.app')
$expectedExecutable,
$expectedApp
), $target, Project::MSG_VERBOSE);
}

public function testCallCommandWithAppAsExecutable(): void
{
$tester = new PhingTester(__DIR__ . '/symfony-command-task-integration-test.xml');
$target = __FUNCTION__;
$target = 'call-command-with-app-as-executable';
$tester->executeTarget($target);

$tester->assertLogMessageRegExp(sprintf(
'~executing.+%s.+hello:world~i',
$tester->getProject()->getProperty(__FUNCTION__ . '.test.app')
), $target, Project::MSG_VERBOSE);
}

public function testCallCommandAndOverrideDefaults(): void
{
$tester = new PhingTester(__DIR__ . '/symfony-command-task-integration-test.xml');
$target = __FUNCTION__;
$tester->executeTarget($target);
$expectedApp = $tester->getProject()->getProperty($target . '.test.app');
Type::checkType($expectedApp, 'string');

$tester->assertLogMessageRegExp(sprintf(
'~executing.+%s.+%s.+hello:world~i',
$tester->getProject()->getProperty(__FUNCTION__ . '.test.executable'),
$tester->getProject()->getProperty(__FUNCTION__ . '.test.app')
'~executing.+%s.+hello:world~i',
$expectedApp
), $target, Project::MSG_VERBOSE);
}

public function testMissingApp(): void
{
$tester = new PhingTester(__DIR__ . '/symfony-command-task-integration-test.xml');
$target = __FUNCTION__;

$this->expectException(\BuildException::class);
$this->expectExceptionMessageMatches('~app.+required~');

$tester->executeTarget($target);
$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());
}
}

}
58 changes: 29 additions & 29 deletions tests/symfony-command-task-integration-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,67 @@

<taskdef name="symfony-cmd" classname="VasekPurchart\Phing\SymfonyCommand\SymfonyCommandTask"/>

<target name="testCallCommand">
<property name="testCallCommand.default.app" value="${project.basedir}/console"/>
<property name="symfony-command.default.app" value="${testCallCommand.default.app}"/>
<target name="call-command">
<property name="call-command.default.app" value="${project.basedir}/console"/>
<property name="symfony-command.default.app" value="${call-command.default.app}"/>

<property name="testCallCommand.default.executable" value="php"/>
<property name="symfony-command.default.executable" value="${testCallCommand.default.executable}"/>
<property name="call-command.default.executable" value="php"/>
<property name="symfony-command.default.executable" value="${call-command.default.executable}"/>

<symfony-cmd cmd="hello:world"/>
</target>

<target name="testCallCommandWithCustomExecutable">
<property name="testCallCommandWithCustomExecutable.default.app" value="${project.basedir}/console"/>
<property name="symfony-command.default.app" value="${testCallCommandWithCustomExecutable.default.app}"/>
<target name="call-command-with-custom-executable">
<property name="call-command-with-custom-executable.default.app" value="${project.basedir}/console"/>
<property name="symfony-command.default.app" value="${call-command-with-custom-executable.default.app}"/>

<property name="testCallCommandWithCustomApp.test.executable" value="php"/>
<property name="call-command-with-custom-executable.test.executable" value="php"/>

<symfony-cmd executable="${testCallCommandWithCustomApp.test.executable}" cmd="hello:world"/>
<symfony-cmd executable="${call-command-with-custom-executable.test.executable}" cmd="hello:world"/>
</target>

<target name="testCallCommandWithCustomApp">
<property name="testCallCommandWithCustomApp.default.executable" value="php"/>
<property name="symfony-command.default.executable" value="${testCallCommandWithCustomApp.default.executable}"/>
<target name="call-command-with-custom-app">
<property name="call-command-with-custom-app.default.executable" value="php"/>
<property name="symfony-command.default.executable" value="${call-command-with-custom-app.default.executable}"/>

<property name="testCallCommandWithCustomApp.test.app" value="${project.basedir}/console"/>
<property name="call-command-with-custom-app.test.app" value="${project.basedir}/console"/>

<symfony-cmd app="${testCallCommandWithCustomApp.test.app}" cmd="hello:world"/>
<symfony-cmd app="${call-command-with-custom-app.test.app}" cmd="hello:world"/>
</target>

<target name="testCallCommandWithCustomExecutableAndApp">
<property name="testCallCommandWithCustomExecutableAndApp.test.app" value="${project.basedir}/console"/>
<property name="testCallCommandWithCustomExecutableAndApp.test.executable" value="php"/>
<target name="call-command-with-custom-executable-and-app">
<property name="call-command-with-custom-executable-and-app.test.app" value="${project.basedir}/console"/>
<property name="call-command-with-custom-executable-and-app.test.executable" value="php"/>

<symfony-cmd
executable="${testCallCommandWithCustomExecutableAndApp.test.executable}"
app="${testCallCommandWithCustomExecutableAndApp.test.app}"
executable="${call-command-with-custom-executable-and-app.test.executable}"
app="${call-command-with-custom-executable-and-app.test.app}"
cmd="hello:world"
/>
</target>

<target name="testCallCommandWithAppAsExecutable">
<property name="testCallCommandWithAppAsExecutable.test.app" value="${project.basedir}/console"/>
<target name="call-command-with-app-as-executable">
<property name="call-command-with-app-as-executable.test.app" value="${project.basedir}/console"/>

<symfony-cmd app="${testCallCommandWithAppAsExecutable.test.app}" cmd="hello:world"/>
<symfony-cmd app="${call-command-with-app-as-executable.test.app}" cmd="hello:world"/>
</target>

<target name="testCallCommandAndOverrideDefaults">
<target name="call-command-and-override-defaults">
<property name="symfony-command.default.app" value="XXX"/>

<property name="symfony-command.default.executable" value="YYY"/>

<property name="testCallCommandAndOverrideDefaults.test.app" value="${project.basedir}/console"/>
<property name="testCallCommandAndOverrideDefaults.test.executable" value="php"/>
<property name="call-command-and-override-defaults.test.app" value="${project.basedir}/console"/>
<property name="call-command-and-override-defaults.test.executable" value="php"/>

<symfony-cmd
executable="${testCallCommandAndOverrideDefaults.test.executable}"
app="${testCallCommandAndOverrideDefaults.test.app}"
executable="${call-command-and-override-defaults.test.executable}"
app="${call-command-and-override-defaults.test.app}"
cmd="hello:world"
/>
</target>

<target name="testMissingApp">
<target name="missing-app">
<symfony-cmd cmd="hello:world"/>
</target>

Expand Down