1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ShlinkioTest\Shlink\IpGeolocation\Exception; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use RuntimeException; |
9
|
|
|
use Shlinkio\Shlink\IpGeolocation\Exception\DbUpdateException; |
10
|
|
|
use Throwable; |
11
|
|
|
|
12
|
|
|
use function sprintf; |
13
|
|
|
|
14
|
|
|
class DbUpdateExceptionTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
private Throwable $prev; |
17
|
|
|
private string $theFile = '/the/file'; |
18
|
|
|
|
19
|
|
|
protected function setUp(): void |
20
|
|
|
{ |
21
|
|
|
$this->prev = new RuntimeException('Error'); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** @test */ |
25
|
|
|
public function forFailedDownloadReturnsExpectedException(): void |
26
|
|
|
{ |
27
|
|
|
$e = DbUpdateException::forFailedDownload($this->prev); |
28
|
|
|
|
29
|
|
|
$this->assertEquals( |
30
|
|
|
'An error occurred while trying to download a fresh copy of the GeoLite2 database', |
31
|
|
|
$e->getMessage(), |
32
|
|
|
); |
33
|
|
|
$this->assertEquals($this->prev, $e->getPrevious()); |
34
|
|
|
$this->assertEquals(0, $e->getCode()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** @test */ |
38
|
|
|
public function forFailedExtractionReturnsExpectedException(): void |
39
|
|
|
{ |
40
|
|
|
$e = DbUpdateException::forFailedExtraction($this->theFile, $this->prev); |
41
|
|
|
|
42
|
|
|
$this->assertEquals( |
43
|
|
|
sprintf('An error occurred while trying to extract the GeoLite2 database from %s', $this->theFile), |
44
|
|
|
$e->getMessage(), |
45
|
|
|
); |
46
|
|
|
$this->assertEquals($this->prev, $e->getPrevious()); |
47
|
|
|
$this->assertEquals(0, $e->getCode()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** @test */ |
51
|
|
|
public function forFailedCopyToDestinationReturnsExpectedException(): void |
52
|
|
|
{ |
53
|
|
|
$e = DbUpdateException::forFailedCopyToDestination($this->theFile, $this->prev); |
54
|
|
|
|
55
|
|
|
$this->assertEquals( |
56
|
|
|
sprintf('An error occurred while trying to copy GeoLite2 db file to %s folder', $this->theFile), |
57
|
|
|
$e->getMessage(), |
58
|
|
|
); |
59
|
|
|
$this->assertEquals($this->prev, $e->getPrevious()); |
60
|
|
|
$this->assertEquals(0, $e->getCode()); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|