Example:
$array = array('a' => 1, 'b' => 2, 'c' => 3);
$filtered = Arrays::filterByAllowedKeys($array, array('a', 'b'));
Result:
Array
(
[a] => 1
[b] => 2
)
public function matches($argument) { if (get_class($this->expected) !== get_class($argument)) { return false; } $actualAttributes = Arrays::filterByAllowedKeys($argument->attributes(), $this->expected->getFields()); return $this->expectedAttributes == $actualAttributes; }
private function _assertSamePersistentAttributes(Model $expected) { $expectedAttributes = Arrays::filterByAllowedKeys($expected->attributes(), $expected->getFields()); $actualAttributes = Arrays::filterByAllowedKeys($this->_actual->attributes(), $this->_actual->getFields()); AssertAdapter::assertEquals($expectedAttributes, $actualAttributes, 'Models have different attributes '); }
public function filterByAllowedKeys($allowedKeys) { $this->_array = Arrays::filterByAllowedKeys($this->_array, $allowedKeys); return $this; }
/** * @test */ public function shouldFilterByAllowedKeys() { //given $array = array('a' => 1, 'b' => 2, 'c' => 3); //when $filtered = Arrays::filterByAllowedKeys($array, array('a', 'b')); //then $this->assertEquals(array('a' => 1, 'b' => 2), $filtered); }