dbUpdater = $this->prophesize(DbUpdaterInterface::class); $command = new UpdateDbCommand($this->dbUpdater->reveal()); $app = new Application(); $app->add($command); $this->commandTester = new CommandTester($command); } /** @test */ public function successMessageIsPrintedIfEverythingWorks(): void { $download = $this->dbUpdater->downloadFreshCopy(Argument::type('callable'))->will(function () { }); $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); $exitCode = $this->commandTester->getStatusCode(); $this->assertStringContainsString('GeoLite2 database properly updated', $output); $this->assertEquals(ExitCodes::EXIT_SUCCESS, $exitCode); $download->shouldHaveBeenCalledOnce(); } /** @test */ public function errorMessageIsPrintedIfAnExceptionIsThrown(): void { $download = $this->dbUpdater->downloadFreshCopy(Argument::type('callable'))->willThrow(RuntimeException::class); $this->commandTester->execute([]); $output = $this->commandTester->getDisplay(); $exitCode = $this->commandTester->getStatusCode(); $this->assertStringContainsString('An error occurred while updating GeoLite2 database', $output); $this->assertEquals(ExitCodes::EXIT_FAILURE, $exitCode); $download->shouldHaveBeenCalledOnce(); } /** @test */ public function warningMessageIsPrintedIfAnExceptionIsThrownAndErrorsAreIgnored(): void { $download = $this->dbUpdater->downloadFreshCopy(Argument::type('callable'))->willThrow(RuntimeException::class); $this->commandTester->execute(['--ignoreErrors' => true]); $output = $this->commandTester->getDisplay(); $exitCode = $this->commandTester->getStatusCode(); $this->assertStringContainsString('ignored', $output); $this->assertEquals(ExitCodes::EXIT_SUCCESS, $exitCode); $download->shouldHaveBeenCalledOnce(); } }