ArrTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. class ArrTest extends PHPUnit_Framework_TestCase {
  3. /**
  4. * @dataProvider getArray
  5. */
  6. public function testGetMethodReturnsItemsFromArray($array)
  7. {
  8. $this->assertEquals(Arr::get($array, 'email'), $array['email']);
  9. $this->assertEquals(Arr::get($array, 'names.uncle'), $array['names']['uncle']);
  10. }
  11. /**
  12. * @dataProvider getArray
  13. */
  14. public function testGetMethodReturnsDefaultWhenItemDoesntExist($array)
  15. {
  16. $this->assertNull(Arr::get($array, 'names.aunt'));
  17. $this->assertEquals(Arr::get($array, 'names.aunt', 'Tammy'), 'Tammy');
  18. $this->assertEquals(Arr::get($array, 'names.aunt', function() {return 'Tammy';}), 'Tammy');
  19. }
  20. /**
  21. * @dataProvider getArray
  22. */
  23. public function testSetMethodSetsItemsInArray($array)
  24. {
  25. Arr::set($array, 'name', 'Taylor');
  26. Arr::set($array, 'names.aunt', 'Tammy');
  27. Arr::set($array, 'names.friends.best', 'Abigail');
  28. $this->assertEquals($array['name'], 'Taylor');
  29. $this->assertEquals($array['names']['aunt'], 'Tammy');
  30. $this->assertEquals($array['names']['friends']['best'], 'Abigail');
  31. }
  32. public function getArray()
  33. {
  34. return array(array(
  35. array(
  36. 'email' => 'taylorotwell@gmail.com',
  37. 'names' => array(
  38. 'uncle' => 'Mike',
  39. ),
  40. )
  41. ));
  42. }
  43. }