/** * Tests reject * * @return void */ public function testReject() { $items = ['a' => 1, 'b' => 2, 'c' => 3]; $collection = new Collection($items); $result = $collection->reject(function ($v, $k, $items) use($collection) { $this->assertSame($collection->getInnerIterator(), $items); return $v > 2; }); $this->assertEquals(['a' => 1, 'b' => 2], iterator_to_array($result)); $this->assertInstanceOf('Cake\\Collection\\Collection', $result); }
/** * Tests reject * * @return void */ public function testReject() { $this->assertFalse(defined('HHVM_VERSION'), 'Broken on HHVM'); $items = ['a' => 1, 'b' => 2, 'c' => 3]; $collection = new Collection($items); $result = $collection->reject(function ($v, $k, $items) use($collection) { $this->assertSame($collection, $items); return $v > 2; }); $this->assertEquals(['a' => 1, 'b' => 2], iterator_to_array($result)); $this->assertInstanceOf('\\Cake\\Collection\\Collection', $result); }
public function getOpponent($user_id) { $gm_collection = new Collection($this->game_memberships); $opponents = $gm_collection->reject(function ($gm, $key) use($user_id) { return $user_id == $gm->member_id; }); if (!($opponent = $opponents->first())) { return false; } if (!($opponent->member or $opponent->temp_member)) { return false; } return $opponent; }