Completed
Push — master ( 63d3c0...3a8a58 )
by Korotkov
02:41 queued 12s
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  : Jagepard <[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\DeviceInterface;
17
use PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase;
18
19
class CommandTest extends PHPUnit_Framework_TestCase
20
{
21
    /**
22
     * @var DeviceInterface
23
     */
24
    private $device;
25
26
    protected function setUp(): void
27
    {
28
        $this->device = new Lamp();
29
        $this->device->setCommand('on', new TurnOnCommand());
30
        $this->device->setCommand('off', new TurnOffCommand());
31
        $this->device->setCommand('toggle', new ToggleCommand());
32
    }
33
34
    public function testExecute(): void
35
    {
36
        ob_start();
37
        $this->device->execute('on');
38
        $on = ob_get_clean();
39
        $this->assertEquals($on, sprintf("The Light turns %s \n", 'on'));
40
41
        ob_start();
42
        $this->device->execute('off');
43
        $off = ob_get_clean();
44
        $this->assertEquals($off, sprintf("The Light turns %s \n", 'off'));
45
46
        ob_start();
47
        $this->device->execute('toggle');
48
        $toggle = ob_get_clean();
49
        $this->assertEquals($toggle, sprintf("The Light turns %s \n", 'on'));
50
51
        ob_start();
52
        $this->device->execute('toggle');
53
        $toggle = ob_get_clean();
54
        $this->assertEquals($toggle, sprintf("The Light turns %s \n", 'off'));
55
    }
56
}
57