diff --git a/module/CLI/test/Command/Visit/ProcessVisitsCommandTest.php b/module/CLI/test/Command/Visit/ProcessVisitsCommandTest.php index 6988fb7c..5a28e5ab 100644 --- a/module/CLI/test/Command/Visit/ProcessVisitsCommandTest.php +++ b/module/CLI/test/Command/Visit/ProcessVisitsCommandTest.php @@ -23,15 +23,15 @@ class ProcessVisitsCommandTest extends TestCase /** * @var CommandTester */ - protected $commandTester; + private $commandTester; /** * @var ObjectProphecy */ - protected $visitService; + private $visitService; /** * @var ObjectProphecy */ - protected $ipResolver; + private $ipResolver; public function setUp() { diff --git a/module/CLI/test/Command/Visit/UpdateDbCommandTest.php b/module/CLI/test/Command/Visit/UpdateDbCommandTest.php new file mode 100644 index 00000000..eeb4f1ff --- /dev/null +++ b/module/CLI/test/Command/Visit/UpdateDbCommandTest.php @@ -0,0 +1,65 @@ +dbUpdater = $this->prophesize(DbUpdaterInterface::class); + + $command = new UpdateDbCommand($this->dbUpdater->reveal(), Translator::factory([])); + $app = new Application(); + $app->add($command); + + $this->commandTester = new CommandTester($command); + } + + /** + * @test + */ + public function successMessageIsPrintedIfEverythingWorks() + { + $download = $this->dbUpdater->downloadFreshCopy()->will(function () { + }); + + $this->commandTester->execute([]); + $output = $this->commandTester->getDisplay(); + + $this->assertContains('GeoLite2 database properly updated', $output); + $download->shouldHaveBeenCalledOnce(); + } + + /** + * @test + */ + public function errorMessageIsPrintedIfAnExceptionIsThrown() + { + $download = $this->dbUpdater->downloadFreshCopy()->willThrow(RuntimeException::class); + + $this->commandTester->execute([]); + $output = $this->commandTester->getDisplay(); + + $this->assertContains('An error occurred while updating GeoLite2 database', $output); + $download->shouldHaveBeenCalledOnce(); + } +}