From 60e267a1b61e6a81bdd10d05debea513f203f6d5 Mon Sep 17 00:00:00 2001 From: Soner Sayakci Date: Mon, 21 Oct 2024 10:21:41 +0200 Subject: [PATCH] feat: add fastly:snippet:deploy command --- src/Command/FastlySnippetDeployCommand.php | 42 ++++++++++++++++ .../FastlySnippetDeployCommandTest.php | 50 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 src/Command/FastlySnippetDeployCommand.php create mode 100644 tests/Command/FastlySnippetDeployCommandTest.php diff --git a/src/Command/FastlySnippetDeployCommand.php b/src/Command/FastlySnippetDeployCommand.php new file mode 100644 index 0000000..96fc5b9 --- /dev/null +++ b/src/Command/FastlySnippetDeployCommand.php @@ -0,0 +1,42 @@ +writeln('FASTLY_API_TOKEN or FASTLY_SERVICE_ID is not set.'); + + return self::FAILURE; + } + + $this->fastlyServiceUpdater->__invoke(new PostDeploy(new RunConfiguration(), $output)); + + return self::SUCCESS; + } +} diff --git a/tests/Command/FastlySnippetDeployCommandTest.php b/tests/Command/FastlySnippetDeployCommandTest.php new file mode 100644 index 0000000..dfb7629 --- /dev/null +++ b/tests/Command/FastlySnippetDeployCommandTest.php @@ -0,0 +1,50 @@ +createMock(FastlyServiceUpdater::class); + $updater + ->expects($this->never()) + ->method('__invoke'); + + $command = new FastlySnippetDeployCommand($updater); + $tester = new CommandTester($command); + + $tester->execute([]); + + static::assertEquals(Command::FAILURE, $tester->getStatusCode()); + static::assertStringContainsString('FASTLY_API_TOKEN or FASTLY_SERVICE_ID is not set.', $tester->getDisplay()); + } + + #[Env('FASTLY_API_TOKEN', 'apiToken')] + #[Env('FASTLY_SERVICE_ID', 'serviceId')] + public function testRunCommandWithEnv(): void + { + $updater = $this->createMock(FastlyServiceUpdater::class); + $updater + ->expects($this->once()) + ->method('__invoke'); + + $command = new FastlySnippetDeployCommand($updater); + $tester = new CommandTester($command); + + $tester->execute([]); + + static::assertEquals(Command::SUCCESS, $tester->getStatusCode()); + } +}