GetValueTest::testReturnsNullWhenKeyDoesntExist()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of the Axstrad library.
4
 *
5
 * (c) Dan Kempster <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author Dan Kempster <[email protected]>
11
 * @package Axstrad\Common
12
 * @subpackage Tests
13
 */
14
namespace Axstrad\Common\Tests\Util\ArrayUtil;
15
16
use Axstrad\Common\Util\ArrayUtil;
17
18
/**
19
 * Axstrad\Common\Tests\Util\ArrayUtil\GetValueTest
20
 *
21
 * covers Axstrad\Common\Util\ArrayUtil::get
22
 * @group unittest
23
 * @uses Axstrad\Common\Util\ArrayUtil
24
 */
25
class GetValueTest extends \PHPUnit_Framework_TestCase
26
{
27
	/**
28
	 */
29
	public function testReturnsValueFromKey()
30
	{
31
		$key = 'foo';
32
		$array = array($key => 'bar');
33
		$this->assertEquals(
34
			$array[$key],
35
			ArrayUtil::get($key, $array)
36
		);
37
	}
38
39
	/**
40
	 * @depends Axstrad\Common\Tests\Util\ArrayUtil\DecompilePathTest::testCanParseDotNotation
41
	 */
42
	public function testReturnsValueByPath()
43
	{
44
		$array = array('one' => array('two'=>'three'));
45
		$this->assertEquals(
46
			'three',
47
			ArrayUtil::get('one.two', $array)
48
		);
49
	}
50
51
	/**
52
	 */
53
	public function testReturnsNullWhenKeyDoesntExist()
54
	{
55
		$this->assertNull(
56
			ArrayUtil::get('one', array('foo'=>'bar'))
57
		);
58
	}
59
60
	/**
61
	 */
62
	public function testReturnsDefaultValueWhenKeyDoesntExist()
63
	{
64
		$this->assertFalse(
65
			ArrayUtil::get('one', array('foo'=>'bar'), false)
66
		);
67
	}
68
}
69