/** * Filter workout list. * * @param array $filters array of filters * @return array array of Workouts objects */ public function filter($filters) { $base = ['expand' => 'workout']; $workouts = $this->api->get('workouts/history', array_merge($base, $filters)); $list = []; foreach ($workouts->data as $workout) { $list[] = new Workout($workout); } return $list; }
public function testGetRides() { $mock = $this->getMockBuilder('EndomondoApi')->setMethods(array('get'))->getMock(); $endomondo = new Endomondo("", "", "UTC", array($this, 'myEcho'), $mock); // no rides returned $mock->expects($this->at(0))->method('get')->with('api/workouts', $this->captureArg($params))->willReturn('{"data":[]}'); $this->assertEquals([], $endomondo->getRides(null, null)); $before = strtotime($params['before']); $this->assertTrue(time() - $before <= 1); // the time of the before parameter should be about now, so in the last second $this->assertEquals(500, $params['maxResults']); $this->assertEquals('simple,basic', $params['fields']); //one ride returned $result = '{"data":[{"owner":{"premium_type":"pro","name":"joan m","last_name":"m","id":2859253,"first_name":"joan","picture":848122},"distance":1.9844679832458496,"speed_avg":0.887574200482676,"privacy_map":2,"owner_id":2859253,"privacy_workout":2,"calories":302,"duration":8049,"start_time":"2015-12-27 21:56:00 UTC","is_valid":true,"id":655334427,"burgers_burned":0.55925924,"sport":1,"live":false}]}'; $mock->expects($this->at(0))->method('get')->with('api/workouts', $this->captureArg($params))->willReturn($result); $expected = array('2015-12-27' => array(array('elapsed_time' => 8049, 'distance' => 1984.4679832458496, 'endo_id' => 655334427, 'start_time' => '2015-12-27 21:56:00 UTC', 'name' => '', 'moving_time' => 8049))); $this->assertEquals($expected, $endomondo->getRides(null, null)); //all possible data included $result = '{"data":[{"owner":{"premium_type":"pro","name":"joan m","last_name":"m","id":2859253,"first_name":"joan","picture":848122},"distance":1.9844679832458496,"speed_avg":0.887574200482676,"privacy_map":2,"owner_id":2859253,"privacy_workout":2,"calories":302,"duration":8049,"start_time":"2015-12-27 21:56:00 UTC","is_valid":true,"id":655334427,"speed_max": 23.0271,"name": "My Ride","burgers_burned":0.55925924,"sport":1,"live":false,"ascent": 69.4}]}'; $mock->expects($this->at(0))->method('get')->with('api/workouts', $this->captureArg($params))->willReturn($result); $expected = array('2015-12-27' => array(array('elapsed_time' => 8049, 'distance' => 1984.4679832458496, 'endo_id' => 655334427, 'start_time' => '2015-12-27 21:56:00 UTC', 'name' => 'My Ride', 'max_speed' => 6.39641666666667, 'total_elevation_gain' => 69.40000000000001, 'moving_time' => 8049))); $this->assertEquals($expected, $endomondo->getRides(null, null)); }