public function testExtractCurrentUser() { $sources = array(0 => array("first-name" => "Obi Wan", "email" => "*****@*****.**"), 1 => array("first-name" => "Luke", "email" => "*****@*****.**"), 2 => array("first-name" => "Darth", "email" => "*****@*****.**")); $expected_user = $sources[1]; //it returns the extracted user $this->assertEquals($expected_user, extract_current_user($sources, "*****@*****.**")); //the array no longer contains the extracted user $this->assertEquals(2, count($sources)); //array_values was called on the array, leaving index 0 and 1 $this->assertEquals("*****@*****.**", $sources[0]['email']); $this->assertEquals("*****@*****.**", $sources[1]['email']); }
function get_all_friends($config) { $client = ClientBuilder::create()->build(); $params = []; $params['index'] = 'friends'; $params['type'] = 'friends'; $params['size'] = 1000; $params['body']['query']['match_all'] = [$_GET['search']]; $params['body']['sort'] = ['_score']; $result = $client->search($params)['hits']['hits']; $sources = array_map(function ($arr) { return $arr['_source']; }, $result); $current_user_location = get_address_from_source(extract_current_user($sources, $_SESSION['user_email'])); $config = parse_ini_file('/../../../config.ini'); return array(friends => new ArrayIterator($sources), key => $config['maps_key'], origin => $current_user_location); }