HEX
Server: Apache/2.2.15 (CentOS)
System: Linux ip-10-0-2-146.eu-west-1.compute.internal 2.6.32-754.35.1.el6.centos.plus.x86_64 #1 SMP Sat Nov 7 11:33:42 UTC 2020 x86_64
User: root (0)
PHP: 5.6.40
Disabled: NONE
Upload Files
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);
	}
}