Passed
Push — master ( e347b7...6892ad )
by Woody
02:08
created

ClientLocatorTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 23
dl 0
loc 63
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanRegisterAdditionalClientsForLocation() 0 12 1
A testCannotUnregisterInvalidClientImplementation() 0 6 1
A dataClientInterfaces() 0 4 1
A testCannotUnregisterInvalidClient() 0 6 1
A testCannotLocateInvalidClient() 0 5 1
A testCannotRegisterInvalidClientImlementation() 0 6 1
A testCannotRegisterInvalidClient() 0 6 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Http\Factory\Discovery;
5
6
use PHPUnit\Framework\TestCase;
7
use Psr\Http\Client\ClientInterface;
8
9
class ClientLocatorTest extends TestCase
10
{
11
    public function dataClientInterfaces(): array
12
    {
13
        return [
14
            ClientInterface::class => [ClientInterface::class],
15
        ];
16
    }
17
18
    /**
19
     * @dataProvider dataClientInterfaces
20
     */
21
    public function testCanRegisterAdditionalClientsForLocation(string $interface): void
22
    {
23
        $client = $this->getMockBuilder($interface)->getMock();
24
        $clientClass = get_class($client);
25
26
        ClientLocator::register($interface, $clientClass);
27
28
        $this->assertSame($clientClass, ClientLocator::locate($interface));
29
30
        ClientLocator::unregister($interface, $clientClass);
31
32
        $this->assertNotSame($clientClass, ClientLocator::locate($interface));
33
    }
34
35
    public function testCannotRegisterInvalidClient(): void
36
    {
37
        $this->expectException(\InvalidArgumentException::class);
38
        $this->expectExceptionMessage('foo');
39
40
        ClientLocator::register('foo', self::class);
41
    }
42
43
    public function testCannotRegisterInvalidClientImlementation(): void
44
    {
45
        $this->expectException(\InvalidArgumentException::class);
46
        $this->expectExceptionMessage(self::class);
47
48
        ClientLocator::register(ClientInterface::class, self::class);
49
    }
50
51
    public function testCannotUnregisterInvalidClient(): void
52
    {
53
        $this->expectException(\InvalidArgumentException::class);
54
        $this->expectExceptionMessage('foo');
55
56
        ClientLocator::unregister('foo', self::class);
57
    }
58
59
    public function testCannotUnregisterInvalidClientImplementation(): void
60
    {
61
        $this->expectException(\InvalidArgumentException::class);
62
        $this->expectExceptionMessage(self::class);
63
64
        ClientLocator::unregister(ClientInterface::class, self::class);
65
    }
66
67
    public function testCannotLocateInvalidClient(): void
68
    {
69
        $this->expectException(\RuntimeException::class);
70
71
        ClientLocator::locate('foo');
72
    }
73
}
74