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\Item; |
13
|
|
|
use Behavioral\Interpreter\Depository; |
14
|
|
|
use Behavioral\Interpreter\Interpreter; |
15
|
|
|
use PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class InterpreterTest |
19
|
|
|
* @package Behavioral\Interpreter\Tests |
20
|
|
|
*/ |
21
|
|
|
class InterpreterTest extends PHPUnit_Framework_TestCase |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var Depository |
26
|
|
|
*/ |
27
|
|
|
protected $depository; |
28
|
|
|
/** |
29
|
|
|
* @var Interpreter |
30
|
|
|
*/ |
31
|
|
|
protected $interpreter; |
32
|
|
|
|
33
|
|
|
protected function setUp(): void |
34
|
|
|
{ |
35
|
|
|
$this->depository = new Depository(); |
36
|
|
|
$this->depository->setItem(new Item('Korn', 'Korn')); |
37
|
|
|
$this->depository->setItem(new Item('Deftones', 'Adrenaline')); |
38
|
|
|
|
39
|
|
|
$this->interpreter = new Interpreter($this->depository); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testAlbum(): void |
43
|
|
|
{ |
44
|
|
|
ob_start(); |
45
|
|
|
$this->interpreter->interpret('album 2'); |
46
|
|
|
$album = ob_get_clean(); |
47
|
|
|
$this->assertEquals($album, sprintf("%s: %s\n", ' Album', 'Adrenaline')); |
48
|
|
|
|
49
|
|
|
ob_start(); |
50
|
|
|
$this->interpreter->interpret('2 album'); |
51
|
|
|
$album = ob_get_clean(); |
52
|
|
|
$this->assertEquals($album, sprintf("%s: %s\n", ' Album', 'Adrenaline')); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testAuthor(): void |
56
|
|
|
{ |
57
|
|
|
ob_start(); |
58
|
|
|
$this->interpreter->interpret('author 2'); |
59
|
|
|
$album = ob_get_clean(); |
60
|
|
|
$this->assertEquals($album, sprintf("%s: %s\n", ' Author', 'Deftones')); |
61
|
|
|
|
62
|
|
|
ob_start(); |
63
|
|
|
$this->interpreter->interpret('2 author'); |
64
|
|
|
$album = ob_get_clean(); |
65
|
|
|
$this->assertEquals($album, sprintf("%s: %s\n", ' Author', 'Deftones')); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|