Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Mock-testing web services in Zend Framework
public function testGetTracks()
// Create mocks for the SoundCloud class for testing purposes
$webservice = $this->getMockBuilder('\Soundcloud\Services\Soundcloud')
->setMethods(array('get', 'setAccessToken'))
$myInfo = file_get_contents(FIXTURE_PATH . '/soundcloud_my_info.txt');
$playlists = file_get_contents(FIXTURE_PATH . '/soundcloud_playlists.txt');
$tracks = file_get_contents(FIXTURE_PATH . '/soundcloud_tracks.txt');
$inputs = array('me', 'playlists', 'tracks');
$outputs = array($myInfo, $playlists, $tracks);
$expectation = $webservice->expects($this->exactly(3))->method('get');
$this->setMultipleMatching($expectation, $inputs, $outputs);
$this->soundcloud = new \Soundcloud\Client(
$myInfo = $this->soundcloud->getMyInfo();
$mySoundcloudId = $myInfo['id'];
$playlists = $this->soundcloud->getPlaylists($this->config->soundcloud->consumer_key);
$this->assertTrue(count($playlists) > 0, 'Found one or more SoundCloud playlists');
$tracks = $this->soundcloud->getAllTracks($mySoundcloudId);
$this->assertTrue(count($tracks) > 0, 'Found one or more tracks from SoundCloud');
public function setMultipleMatching($expectation, array $inputs, array $outputs)
$testCase = $this;
$callback = function() use ($inputs, $outputs, $testCase) {
$args = func_get_args();
$testCase->assertContains($args[0], $inputs);
$index = array_search($args[0], $inputs);
return $outputs[$index];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.