forked from thephpleague/factory-muffin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayTest.php
50 lines (43 loc) · 1.3 KB
/
ArrayTest.php
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
<?php
use League\FactoryMuffin\Arr;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* @group array
*/
class ArrayTest extends AbstractTestCase
{
public function testGet()
{
$array = array('foo' => 'bar', 'baz' => 'hello');
$this->assertSame('bar', Arr::get($array, 'foo'));
$this->assertSame('hello', Arr::get($array, 'baz'));
$this->assertNull(Arr::get($array, 'bar'));
}
public function testHas()
{
$array = array('foo' => 'bar', 'baz' => 'hello');
$this->assertTrue(Arr::has($array, 'bar'));
$this->assertTrue(Arr::has($array, 'hello'));
$this->assertFalse(Arr::has($array, 'foo'));
}
/**
* @depends testHas
*/
public function testAddAndRemove()
{
$array = array();
$new = (object) array('baz' => 'hello');
$this->assertCount(0, $array);
$this->assertFalse(Arr::has($array, $new));
Arr::add($array, $new);
$this->assertCount(1, $array);
$this->assertTrue(Arr::has($array, $new));
$new->bar = 'baz';
$this->assertCount(1, $array);
$this->assertTrue(Arr::has($array, $new));
Arr::add($array, $new);
$this->assertCount(1, $array);
Arr::remove($array, $new);
$this->assertCount(0, $array);
}
}