Completed
Push — master ( 47ba96...4fd14e )
by Gerrit
02:18
created

shouldRejectGettingUnknownVariable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright (C) 2017  Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 * @license GPL-3.0
8
 * @author Gerrit Addiks <[email protected]>
9
 */
10
11
namespace Addiks\SymfonyGenerics\Tests\Unit\Arguments;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\SymfonyGenerics\Arguments\ArgumentContext;
15
use stdClass;
16
use InvalidArgumentException;
17
18
final class ArgumentContextTest extends TestCase
19
{
20
21
    /**
22
     * @test
23
     */
24
    public function shouldContainContextualData()
25
    {
26
        $context = new ArgumentContext();
27
28
        $this->assertFalse($context->has("foo"));
29
        $this->assertFalse($context->has("bar"));
30
        $this->assertFalse($context->has("baz"));
31
32
        $context->set("foo", 1234);
33
34
        $this->assertTrue($context->has("foo"));
35
        $this->assertFalse($context->has("bar"));
36
        $this->assertFalse($context->has("baz"));
37
        $this->assertEquals(1234, $context->get("foo"));
38
39
        $context->set("bar", ['lorem' => 'ipsum', 'dolor' => 'amet']);
40
41
        $this->assertTrue($context->has("foo"));
42
        $this->assertTrue($context->has("bar"));
43
        $this->assertFalse($context->has("baz"));
44
        $this->assertEquals(1234, $context->get("foo"));
45
        $this->assertEquals(['lorem' => 'ipsum', 'dolor' => 'amet'], $context->get("bar"));
46
47
        $context->set("baz", new stdClass());
48
49
        $this->assertTrue($context->has("foo"));
50
        $this->assertTrue($context->has("bar"));
51
        $this->assertTrue($context->has("baz"));
52
        $this->assertEquals(1234, $context->get("foo"));
53
        $this->assertEquals(['lorem' => 'ipsum', 'dolor' => 'amet'], $context->get("bar"));
54
        $this->assertEquals(new stdClass(), $context->get("baz"));
55
    }
56
57
    /**
58
     * @test
59
     */
60
    public function shouldRejectGettingUnknownVariable()
61
    {
62
        $this->expectException(InvalidArgumentException::class);
63
64
        (new ArgumentContext())->get("foo");
65
    }
66
67
}
68