1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @author : Jagepard <[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\Interpreter; |
14
|
|
|
use Behavioral\Interpreter\InterpreterInterface; |
15
|
|
|
use PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase; |
16
|
|
|
|
17
|
|
|
class InterpreterTest extends PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var InterpreterInterface |
21
|
|
|
*/ |
22
|
|
|
protected $interpreter; |
23
|
|
|
|
24
|
|
|
protected function setUp(): void |
25
|
|
|
{ |
26
|
|
|
$this->interpreter = new Interpreter(); |
27
|
|
|
$this->interpreter->addItem(new Album('Korn', 'Untouchables')); |
28
|
|
|
$this->interpreter->addItem(new Album('Deftones', 'Adrenaline')); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testAlbum(): void |
32
|
|
|
{ |
33
|
|
|
ob_start(); |
34
|
|
|
$this->interpreter->interpret('album 2'); |
35
|
|
|
$album = ob_get_clean(); |
36
|
|
|
$this->assertEquals($album, sprintf("%s \n", 'Deftones')); |
37
|
|
|
|
38
|
|
|
ob_start(); |
39
|
|
|
$this->interpreter->interpret('2 album'); |
40
|
|
|
$album = ob_get_clean(); |
41
|
|
|
$this->assertEquals($album, sprintf("%s \n", 'Deftones')); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testAuthor(): void |
45
|
|
|
{ |
46
|
|
|
ob_start(); |
47
|
|
|
$this->interpreter->interpret('author 2'); |
48
|
|
|
$album = ob_get_clean(); |
49
|
|
|
$this->assertEquals($album, sprintf("%s\n", 'Adrenaline')); |
50
|
|
|
|
51
|
|
|
ob_start(); |
52
|
|
|
$this->interpreter->interpret('2 author'); |
53
|
|
|
$album = ob_get_clean(); |
54
|
|
|
$this->assertEquals($album, sprintf("%s\n", 'Adrenaline')); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|