mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-29 13:03:52 +03:00
Created UpdateDbCommandTest
This commit is contained in:
parent
e915b7e499
commit
bf56e6adaf
2 changed files with 68 additions and 3 deletions
|
@ -23,15 +23,15 @@ class ProcessVisitsCommandTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @var CommandTester
|
* @var CommandTester
|
||||||
*/
|
*/
|
||||||
protected $commandTester;
|
private $commandTester;
|
||||||
/**
|
/**
|
||||||
* @var ObjectProphecy
|
* @var ObjectProphecy
|
||||||
*/
|
*/
|
||||||
protected $visitService;
|
private $visitService;
|
||||||
/**
|
/**
|
||||||
* @var ObjectProphecy
|
* @var ObjectProphecy
|
||||||
*/
|
*/
|
||||||
protected $ipResolver;
|
private $ipResolver;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
|
|
65
module/CLI/test/Command/Visit/UpdateDbCommandTest.php
Normal file
65
module/CLI/test/Command/Visit/UpdateDbCommandTest.php
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace ShlinkioTest\Shlink\CLI\Command\Visit;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Prophecy\Prophecy\ObjectProphecy;
|
||||||
|
use Shlinkio\Shlink\CLI\Command\Visit\UpdateDbCommand;
|
||||||
|
use Shlinkio\Shlink\Common\Exception\RuntimeException;
|
||||||
|
use Shlinkio\Shlink\Common\IpGeolocation\GeoLite2\DbUpdaterInterface;
|
||||||
|
use Symfony\Component\Console\Application;
|
||||||
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
|
use Zend\I18n\Translator\Translator;
|
||||||
|
|
||||||
|
class UpdateDbCommandTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var CommandTester
|
||||||
|
*/
|
||||||
|
private $commandTester;
|
||||||
|
/**
|
||||||
|
* @var ObjectProphecy
|
||||||
|
*/
|
||||||
|
private $dbUpdater;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue