Exemplo n.º 1
0
 public function testFindBy()
 {
     $a = [['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456], ['id' => 456, 'name' => 'bar', 'group' => 'primary', 'value' => 1468], ['id' => 499, 'name' => 'baz', 'group' => 'secondary', 'value' => 2365], ['id' => 789, 'name' => 'ter', 'group' => 'primary', 'value' => 2468]];
     $b = Arr::findBy($a, 'name', 'baz');
     $this->assertTrue(is_array($b));
     $this->assertCount(4, $b);
     // this is counting the number of keys in the array (id,name,group,value)
     $this->assertEquals(2365, $b['value']);
     $this->assertArrayHasKey('name', $b);
     $this->assertArrayHasKey('group', $b);
     $this->assertArrayHasKey('value', $b);
     $c = Arr::findBy($a, 'value', 2468);
     $this->assertTrue(is_array($c));
     $this->assertCount(4, $c);
     $this->assertEquals('primary', $c['group']);
     $d = Arr::findBy($a, 'group', 'primary');
     $this->assertTrue(is_array($d));
     $this->assertCount(4, $d);
     $this->assertEquals('foo', $d['name']);
     $e = Arr::findBy($a, 'value', 2000, 'lt');
     $this->assertTrue(is_array($e));
     $this->assertCount(4, $e);
     $this->assertEquals(1468, $e['value']);
 }