Completed
Pull Request — master (#13)
by Korotkov
02:36
created

CommandTest::getRegistry()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\Command\Tests;
11
12
use Behavioral\Command\CommandType;
13
use Behavioral\Command\Lamp;
14
use Behavioral\Command\ToggleCommand;
15
use Behavioral\Command\TurnOnCommand;
16
use Behavioral\Command\TurnOffCommand;
17
use Behavioral\Command\Registry;
18
use PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase;
19
20
/**
21
 * Class CommandTest
22
 * @package Behavioral\Command\Tests
23
 */
24
class CommandTest extends PHPUnit_Framework_TestCase
25
{
26
    /**
27
     * @var Registry
28
     */
29
    private $registry;
30
31
    protected function setUp(): void
32
    {
33
        $this->registry = new Registry(new Lamp());
34
        $this->getRegistry()->setCommand(new TurnOnCommand(), new CommandType('on'));
35
        $this->getRegistry()->setCommand(new TurnOffCommand(), new CommandType('off'));
36
        $this->getRegistry()->setCommand(new ToggleCommand(), new CommandType('toggle'));
37
    }
38
39
    public function testExecute(): void
40
    {
41
        ob_start();
42
        $this->getRegistry()->execute(new CommandType('on'));
43
        $on = ob_get_clean();
44
        $this->assertEquals($on, sprintf("The Light turns %s \n", 'on'));
45
46
        ob_start();
47
        $this->getRegistry()->execute(new CommandType('off'));
48
        $off = ob_get_clean();
49
        $this->assertEquals($off, sprintf("The Light turns %s \n", 'off'));
50
51
        ob_start();
52
        $this->getRegistry()->execute(new CommandType('toggle'));
53
        $toggle = ob_get_clean();
54
        $this->assertEquals($toggle, sprintf("The Light turns %s \n", 'on'));
55
56
        ob_start();
57
        $this->getRegistry()->execute(new CommandType('toggle'));
58
        $toggle = ob_get_clean();
59
        $this->assertEquals($toggle, sprintf("The Light turns %s \n", 'off'));
60
    }
61
62
    /**
63
     * @return Registry
64
     */
65
    public function getRegistry(): Registry
66
    {
67
        return $this->registry;
68
    }
69
}
70