File: //www/exchange2/tests/Bin/ArrayTest.php
<?php
/**
* Created by PhpStorm.
* User: MisterX
* Date: 26.04.2016
* Time: 13:15
*/
class Bin_ArrayTest extends PHPUnit_Framework_TestCase{
/**
* Provides test data for test_get()
*
* @return array
*/
public function provider_get()
{
return array(
/**
* Test with array
*/
array(array('uno', 'dos', 'tress'), 1, NULL, 'dos'),
array(array('we' => 'can', 'make' => 'change'), 'we', NULL, 'can'),
array(array('we' => 'can', 'make' => 'change'), 1, 'default', 'default'),
array(array('uno', 'dos', 'tress'), 10, NULL, NULL),
array(array('we' => 'can', 'make' => 'change'), 'he', NULL, NULL),
array(array('we' => 'can', 'make' => 'change'), 'he', 'who', 'who'),
array(array('we' => 'can', 'make' => 'change'), 'he', array('arrays'), array('arrays')),
array(array('we' => NULL, 'make' => 'change'), 'we', NULL, NULL),
array(array('we' => NULL, 'make' => 'change'), 'we', 'default', NULL),
);
}
/**
* Tests Arr::get()
*
* @test
* @dataProvider provider_get()
* @param array|ArrayAccess $array Array to look in
* @param string|integer $key Key to look for
* @param mixed $default What to return if $key isn't set
* @param mixed $expected The expected value returned
*/
public function test_get($array, $key, $default, $expected)
{
$this->assertSame(
$expected,
Bin_Array::get($array, $key, $default)
);
}
/**
* Provides test data for test_extract
*
* @return array
*/
public function provider_extract()
{
return array(
array(
array('chocolate cake' => 'in stock', 'carrot cake' => 'in stock'),
array('carrot cake', 'humble pie'),
'not in stock',
array('carrot cake' => 'in stock', 'humble pie' => 'not in stock'),
),
);
}
/**
* Tests Arr::extract()
*
* @test
* @dataProvider provider_extract
* @param array $array
* @param array $paths
* @param mixed $default
* @param array $expected
*/
public function test_extract(array $array, array $paths, $default, $expected)
{
$array = Bin_Array::extract($array, $paths, $default);
$this->assertSame(count($expected), count($array));
$this->assertSame($expected, $array);
}
}