blob: f5d1fdb46d3f47b4be549e973b083b793069919d (
plain)
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
|
<?php
namespace OpenCloud\Test\Common;
use OpenCloud\Common\ArrayAccessTrait;
use OpenCloud\Test\TestCase;
class ArrayAccessTraitTest extends TestCase
{
private $aa;
public function setUp()
{
$this->aa = new ArrayAccess();
}
public function test_offset_is_set()
{
$this->aa->offsetSet('foo', 'bar');
$this->assertEquals(['foo' => 'bar'], $this->aa->getElements());
}
public function test_it_appends_if_no_key_is_set()
{
$this->aa->offsetSet(null, 'bar');
$this->assertEquals(['bar'], $this->aa->getElements());
}
public function test_if_checks_if_offset_exists()
{
$this->aa->offsetSet('bar', 'foo');
$this->assertTrue($this->aa->offsetExists('bar'));
$this->assertFalse($this->aa->offsetExists('baz'));
}
public function test_if_gets_offset()
{
$this->aa->offsetSet('bar', 'foo');
$this->assertEquals('foo', $this->aa->offsetGet('bar'));
$this->assertNull($this->aa->offsetGet('baz'));
}
public function test_it_unsets_offset()
{
$this->aa->offsetSet('bar', 'foo');
$this->aa->offsetUnset('bar');
$this->assertNull($this->aa->offsetGet('bar'));
}
}
class ArrayAccess
{
use ArrayAccessTrait;
public function getElements()
{
return $this->internalState;
}
}
|