Completed
Push — master ( bc831c...e6e5a9 )
by Alejandro
16s queued 11s
created

forFailedCopyToDestinationReturnsExpectedException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 10
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