From bf56e6adaf31856b31366a3995af4e6d633c4417 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 12 Nov 2018 20:37:30 +0100 Subject: [PATCH] Created UpdateDbCommandTest --- .../Visit/ProcessVisitsCommandTest.php | 6 +- .../Command/Visit/UpdateDbCommandTest.php | 65 +++++++++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 module/CLI/test/Command/Visit/UpdateDbCommandTest.php 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(); + } +}