public function testCall() { $request = $this->createRequestMock(); $request->method('execute')->willReturn($this->createResponseMock()); $request->method('getQueryParams')->willReturn($this->createParametersMock()); $request->method('getBodyParams')->willReturn($this->createParametersMock()); $request->expects($this->exactly(2))->method('setMethod')->with($this->logicalOr(RequestInterface::METHOD_GET, RequestInterface::METHOD_POST)); $request->expects($this->exactly(2))->method('setGraphVersion')->with($this->equalTo($this->createApi()->getDefaultGraphVersion())); $request->expects($this->exactly(2))->method('setPath')->with($this->equalTo('/<PATH>')); $client = $this->createClientMock(); $client->method('createRequest')->willReturn($request); $session = $this->createSessionMock(); $session->method('getAppSecretProof')->willReturn('<APP_SECRET_PROOF>'); $logger = $this->createLoggerMock(); $logger->expects($this->exactly(2))->method('logRequest'); $logger->expects($this->exactly(2))->method('logResponse'); $api = new Api($client, $session); $api->setLogger($logger); // HTTP GET request $request->expects($this->exactly(1))->method('getQueryParams'); $response = $api->call('/<PATH>'); $this->assertTrue($response instanceof ResponseInterface); // HTTP POST request $request->expects($this->exactly(1))->method('getBodyParams'); $api->call('/<PATH>', RequestInterface::METHOD_POST, array('param' => 'value')); $this->assertTrue($response instanceof ResponseInterface); }
$response = $api->call('/me/accounts'); $data = $response->getContent(); $page_token = ''; foreach ($data['data'] as $page) { if ($page['id'] == $page_id) { $page_token = $page['access_token']; break; } } if ($page_token === '') { throw new \InvalidArgumentException('Page access token for the page id ' . $page_id . ' cannot be found.'); } $page_session = new Session($config->appId, $config->appSecret, $page_token); $page_api = new Api($api->getHttpClient(), $page_session); $page_api->setLogger($api->getLogger()); $data = $page_api->call('/' . $page_id . '/promotable_posts', RequestInterface::METHOD_GET)->getContent(); if (is_null($data) || !is_array($data['data']) || count($data['data']) === 0) { throw new \RuntimeException("no promotable posts available for page " . $page_id); } $post_id = $data['data'][0]['id']; // create Ad Image $zip_path = $config->testZippedImagesPath; $images = AdImage::createFromZip($zip_path, $ad_account_id); $image_1_hash = $images[0]->{AdImageFields::HASH}; $image_2_hash = $images[1]->{AdImageFields::HASH}; $image_3_hash = $images[1]->{AdImageFields::HASH}; // create Ad Video $retry_delay = 3; $max_retry = 4; $video_name = $config->testRunId; $video_path = $config->testVideoPath;