Passed
Pull Request — master (#4)
by Korotkov
02:42
created

CommandTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
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\Lamp;
13
use Behavioral\Command\ToggleCommand;
14
use Behavioral\Command\TurnOnCommand;
15
use Behavioral\Command\TurnOffCommand;
16
use Behavioral\Command\CommandRegistry;
17
use PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase;
18
19
class CommandTest extends PHPUnit_Framework_TestCase
20
{
21
22
    /**
23
     * @var CommandRegistry
24
     */
25
    protected $registry;
26
27
    protected function setUp(): void
28
    {
29
        $this->registry = new CommandRegistry(new Lamp());
30
        $this->registry->setCommand(new TurnOnCommand(), 'on');
31
        $this->registry->setCommand(new TurnOffCommand(), 'off');
32
        $this->registry->setCommand(new ToggleCommand(), 'toggle');
33
    }
34
35
    public function testExecute(): void
36
    {
37
        ob_start();
38
        $this->registry->getCommand('on');
39
        $on = ob_get_clean();
40
        $this->assertEquals($on, sprintf("The Light turns %s \n", 'on'));
41
42
        ob_start();
43
        $this->registry->getCommand('off');
44
        $off = ob_get_clean();
45
        $this->assertEquals($off, sprintf("The Light turns %s \n", 'off'));
46
47
        ob_start();
48
        $this->registry->getCommand('toggle');
49
        $toggle = ob_get_clean();
50
        $this->assertEquals($toggle, sprintf("The Light turns %s \n", 'on'));
51
52
        ob_start();
53
        $this->registry->getCommand('toggle');
54
        $toggle = ob_get_clean();
55
        $this->assertEquals($toggle, sprintf("The Light turns %s \n", 'off'));
56
    }
57
}