GeolocationDbUpdateFailedExceptionTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A provideCreateArgs() 0 6 1
A createBuildsException() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioTest\Shlink\CLI\Exception;
6
7
use Exception;
8
use PHPUnit\Framework\TestCase;
9
use RuntimeException;
10
use Shlinkio\Shlink\CLI\Exception\GeolocationDbUpdateFailedException;
11
use Throwable;
12
13
class GeolocationDbUpdateFailedExceptionTest extends TestCase
14
{
15
    /**
16
     * @test
17
     * @dataProvider provideCreateArgs
18
     */
19
    public function createBuildsException(bool $olderDbExists, ?Throwable $prev): void
20
    {
21
        $e = GeolocationDbUpdateFailedException::create($olderDbExists, $prev);
22
23
        self::assertEquals($olderDbExists, $e->olderDbExists());
24
        self::assertEquals(
25
            'An error occurred while updating geolocation database, and an older version could not be found',
26
            $e->getMessage(),
27
        );
28
        self::assertEquals(0, $e->getCode());
29
        self::assertEquals($prev, $e->getPrevious());
30
    }
31
32
    public function provideCreateArgs(): iterable
33
    {
34
        yield 'older DB and no prev' => [true, null];
35
        yield 'older DB and prev' => [true, new RuntimeException('prev')];
36
        yield 'no older DB and no prev' => [false, null];
37
        yield 'no older DB and prev' => [false, new Exception('prev')];
38
    }
39
}
40