Completed
Push — master ( f283e7...8452cb )
by Korotkov
02:56 queued 10s
created

InterpreterTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A getInterpreter() 0 3 1
A testAlbum() 0 11 1
A testAuthor() 0 11 1
A getDepository() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author    : Korotkov Danila <[email protected]>
7
 * @license   https://mit-license.org/ MIT
8
 */
9
10
namespace Behavioral\Interpreter\Tests;
11
12
use Behavioral\Interpreter\Album;
13
use Behavioral\Interpreter\Depository;
14
use Behavioral\Interpreter\DepositoryInterface;
15
use Behavioral\Interpreter\Interpreter;
16
use Behavioral\Interpreter\InterpreterInterface;
17
use PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase;
18
19
/**
20
 * Class InterpreterTest
21
 * @package Behavioral\Interpreter\Tests
22
 */
23
class InterpreterTest extends PHPUnit_Framework_TestCase
24
{
25
    /**
26
     * @var DepositoryInterface
27
     */
28
    protected $depository;
29
    /**
30
     * @var InterpreterInterface
31
     */
32
    protected $interpreter;
33
34
    protected function setUp(): void
35
    {
36
        $this->depository = new Depository();
37
        $this->getDepository()->setItem(new Album('Korn', 'Korn'));
38
        $this->getDepository()->setItem(new Album('Deftones', 'Adrenaline'));
39
40
        $this->interpreter = new Interpreter($this->getDepository());
41
    }
42
43
    public function testAlbum(): void
44
    {
45
        ob_start();
46
        $this->getInterpreter()->interpret('album 2');
47
        $album = ob_get_clean();
48
        $this->assertEquals($album, sprintf("%s \n",  'Deftones'));
49
50
        ob_start();
51
        $this->getInterpreter()->interpret('2 album');
52
        $album = ob_get_clean();
53
        $this->assertEquals($album, sprintf("%s \n",  'Deftones'));
54
    }
55
56
    public function testAuthor(): void
57
    {
58
        ob_start();
59
        $this->getInterpreter()->interpret('author 2');
60
        $album = ob_get_clean();
61
        $this->assertEquals($album, sprintf("%s\n",  'Adrenaline'));
62
63
        ob_start();
64
        $this->getInterpreter()->interpret('2 author');
65
        $album = ob_get_clean();
66
        $this->assertEquals($album, sprintf("%s\n",  'Adrenaline'));
67
    }
68
69
    /**
70
     * @return DepositoryInterface
71
     */
72
    public function getDepository(): DepositoryInterface
73
    {
74
        return $this->depository;
75
    }
76
77
    /**
78
     * @return InterpreterInterface
79
     */
80
    public function getInterpreter(): InterpreterInterface
81
    {
82
        return $this->interpreter;
83
    }
84
}
85