Completed
Push — master ( 4f2fad...dd1cd3 )
by Guillaume
07:10
created

RunnerTest::testRunner()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 40
rs 8.8571
cc 1
eloc 28
nc 1
nop 0
1
<?php
2
3
namespace Hogosha\Monitor\Client;
4
5
use GuzzleHttp\HandlerStack;
6
use GuzzleHttp\Handler\MockHandler;
7
use GuzzleHttp\Psr7\Response;
8
use Hogosha\Monitor\Client\GuzzleClient;
9
use Hogosha\Monitor\Configuration\ConfigurationLoader;
10
use Hogosha\Monitor\Model\Result;
11
use Hogosha\Monitor\Model\ResultCollection;
12
use Hogosha\Monitor\Model\UrlInfo;
13
use Hogosha\Monitor\Model\UrlProvider;
14
use Hogosha\Monitor\Runner\Runner;
15
16
/**
17
 * @author Guillaume Cavana <[email protected]>
18
 */
19
class RunnerTest extends \PHPUnit_Framework_TestCase
20
{
21
    /**
22
     * testRunner.
23
     */
24
    public function testRunner()
25
    {
26
        $configurationLoaderMock = $this->prophesize(ConfigurationLoader::class);
27
        $configurationLoaderMock
28
        ->loadConfiguration()
29
        ->shouldBeCalled()
30
        ->willReturn(
31
            [
32
                'server' => [
33
                    'hostname' => null,
34
                    'port' => null,
35
                    'use_ssl' => null,
36
                    'auth' => [
37
                        'username' => null,
38
                        'password' => null,
39
                    ],
40
                ],
41
                'urls' => [
42
                    'google' => [
43
                        'url' => 'https://www.google.fr',
44
                        'timeout' => 1,
45
                        'status_code' => 200,
46
                        'service_uid' => '',
47
                    ],
48
                ],
49
            ]
50
        );
51
52
        $urlProvider = new UrlProvider($configurationLoaderMock->reveal());
53
54
        $client = GuzzleClient::createClient(['handler' => $this->mockClient()]);
55
        $runner = new Runner($urlProvider, $client);
56
        $resultCollection = $runner->run();
57
58
        $this->assertCount(1, $urlProvider->getUrls());
59
        $this->assertInstanceOf(UrlInfo::class, $urlProvider->getUrls()[0]);
60
        $this->assertInstanceOf(ResultCollection::class, $resultCollection);
61
        $this->assertInstanceOf(Result::class, $resultCollection[0]);
62
        $this->assertEquals((new Result('google', 200, 0)), $resultCollection[0]);
63
    }
64
65
    /**
66
     * mockClient.
67
     * @return MockHandler
68
     */
69
    private function mockClient()
70
    {
71
        $mock = new MockHandler([
72
            new Response(200, [], 'test'),
73
        ]);
74
75
        return HandlerStack::create($mock);
76
    }
77
}
78