diff --git a/composer.json b/composer.json index e49aeef..a028cf3 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/tests/SymfonyCommandTaskIntegrationTest.php b/tests/SymfonyCommandTaskIntegrationTest.php index 114aef7..b18f68d 100644 --- a/tests/SymfonyCommandTaskIntegrationTest.php +++ b/tests/SymfonyCommandTaskIntegrationTest.php @@ -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()); + } } } diff --git a/tests/symfony-command-task-integration-test.xml b/tests/symfony-command-task-integration-test.xml index b50e353..8e3e48f 100644 --- a/tests/symfony-command-task-integration-test.xml +++ b/tests/symfony-command-task-integration-test.xml @@ -5,67 +5,67 @@ - - - + + + - - + + - - - + + + - + - + - - - + + + - + - + - - - + + + - - + + - + - + - - + + - +