-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathDataBagTest.php
More file actions
115 lines (85 loc) · 2.97 KB
/
DataBagTest.php
File metadata and controls
115 lines (85 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Tests\Sylius\TwigHooks\Unit\Bag;
use PHPUnit\Framework\TestCase;
use Sylius\TwigHooks\Bag\DataBag;
final class DataBagTest extends TestCase
{
public function testItCanBeCreatedFromArray(): void
{
$dataBag = new DataBag(['foo' => 'bar']);
$this->assertSame(['foo' => 'bar'], $dataBag->all());
}
public function testItCreatesEmptyBagByDefault(): void
{
$dataBag = new DataBag();
$this->assertEmpty($dataBag->all());
}
public function testItReturnsWhetherGivenOffsetExists(): void
{
$dataBag = new DataBag(['foo' => 'bar', 'null_value' => null]);
$this->assertTrue(isset($dataBag['foo']));
$this->assertTrue(isset($dataBag['null_value']));
$this->assertFalse(isset($dataBag['bar']));
}
public function testItReturnsGivenOffset(): void
{
$dataBag = new DataBag(['foo' => 'bar']);
$this->assertSame('bar', $dataBag['foo']);
$this->assertNull($dataBag['bar']);
}
public function testItSetsGivenOffset(): void
{
$dataBag = new DataBag();
$dataBag['foo'] = 'bar';
$this->assertSame('bar', $dataBag['foo']);
}
public function testItThrowsExceptionIfOffsetIsNotString(): void
{
$dataBag = new DataBag();
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The offset must be a string.');
$dataBag[1] = 'bar';
}
public function testItThrowsExceptionIfOffsetIsEmptyString(): void
{
$dataBag = new DataBag();
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The offset must not be an empty string.');
$dataBag[''] = 'bar';
}
public function testItUnsetsGivenOffset(): void
{
$dataBag = new DataBag(['foo' => 'bar']);
unset($dataBag['foo']);
$this->assertNull($dataBag['foo']);
}
public function testItReturnsGivenProperty(): void
{
$dataBag = new DataBag(['foo' => 'bar']);
$this->assertSame('bar', $dataBag->foo);
$this->assertNull($dataBag->bar);
}
public function testItReturnsWhetherGivenPropertyExists(): void
{
$dataBag = new DataBag(['foo' => 'bar', 'null_value' => null]);
$this->assertTrue($dataBag->has('foo'));
$this->assertTrue($dataBag->has('null_value'));
$this->assertFalse($dataBag->has('bar'));
}
public function testItReturnsWhetherGivenPropertyIsSet(): void
{
$dataBag = new DataBag(['foo' => 'bar', 'null_value' => null]);
$this->assertTrue(isset($dataBag->foo));
$this->assertTrue(isset($dataBag->null_value));
$this->assertFalse(isset($dataBag->baz));
}
}