Completed
Push — master ( 084e6b...eff98c )
by Guillaume
05:15
created

CsvRendererTest::testCsvRendererError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 13
loc 13
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace Hogosha\Monitor\Renderer;
4
5
use Hogosha\Monitor\Model\Result;
6
use Hogosha\Monitor\Model\ResultCollection;
7
use Hogosha\Monitor\Model\UrlInfo;
8
use Webmozart\Console\Api\IO\IO;
9
use Webmozart\Console\IO\BufferedIO;
10
11
/**
12
 * @author Guillaume Cavana <[email protected]>
13
 */
14 View Code Duplication
class CsvRendererTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    /**
17
     * @var BufferedIO
18
     */
19
    private $io;
20
21
    protected function setUp()
22
    {
23
        $this->io = new BufferedIO();
24
    }
25
26
    /**
27
     * testCsvRendererError.
28
     */
29
    public function testCsvRendererError()
30
    {
31
        $renderer = RendererFactory::create('csv', $this->io);
32
        $renderer->render($this->createResultCollection(true));
33
34
        $output = <<<CSV
35
"Global Status","Status Code",Name,"Reponse Time","Error Log"
36
FAIL,400,Example,0.42,"Couldn't resolve proxy name"
37
38
CSV;
39
        $this->assertInstanceOf(RendererInterface::class, $renderer);
40
        $this->assertSame($output, $this->io->fetchOutput());
41
    }
42
43
    /**
44
     * testCsvRenderer.
45
     */
46
    public function testCsvRenderer()
47
    {
48
        $renderer = RendererFactory::create('csv', $this->io);
49
        $renderer->render($this->createResultCollection());
50
51
        $output = <<<CSV
52
"Global Status","Status Code",Name,"Reponse Time","Error Log"
53
OK,200,Example,0.42,
54
55
CSV;
56
57
        $this->assertInstanceOf(RendererInterface::class, $renderer);
58
        $this->assertSame($output, $this->io->fetchOutput());
59
    }
60
61
    /**
62
     * createResultCollection.
63
     * @param boolean $hasError
64
     */
65
    public function createResultCollection($hasError = false)
66
    {
67
        $errorLog = null;
68
        if ($hasError) {
69
            $errorLog = curl_strerror(5);
70
        }
71
        $result = new Result($this->createUrlInfo(), $hasError ? 400 : 200, 0.42, $errorLog);
72
73
        $resultCollection = new ResultCollection();
74
        $resultCollection->append($result);
75
76
        return $resultCollection;
77
    }
78
79
    private function createUrlInfo()
80
    {
81
        return new UrlInfo(
82
            'Example',
83
            'http://example.com',
84
            'GET',
85
            [],
86
            1,
87
            200,
88
            null,
89
            null
90
        );
91
    }
92
}
93