function it_builds_api_http_path_and_query() { $this->setLimit(10)->setOffset(100); $path = sprintf(self::URL_PATTERN, PublicationId::SA, self::DEFAULT_DESKED_SECTION); $query = 'limit=10&offset=100'; $this->buildApiHttpPathAndQuery()->shouldBeLike(ApiHttpPathAndQuery::createForPathAndQuery($path, $query)); }
function it_builds_api_http_path_and_query() { $this->beConstructedThrough('createForPublicationId', [PublicationId::SA]); $path = sprintf('publication/%s/sections', PublicationId::SA); $expectedApiHttpPathAndQuery = ApiHttpPathAndQuery::createForPath($path); $this->buildApiHttpPathAndQuery()->shouldBeLike($expectedApiHttpPathAndQuery); }
function it_builds_api_http_path_and_query() { $this->beConstructedThrough('createForPublicationIdAndArticleIds', [PublicationId::SA, [1, 2, 3, 4]]); $path = sprintf('publication/%s/articles/%s', PublicationId::SA, '1,2,3,4'); $expectedApiHttpPathAndQuery = ApiHttpPathAndQuery::createForPath($path); $this->buildApiHttpPathAndQuery()->shouldBeLike($expectedApiHttpPathAndQuery); }
function it_builds_api_http_path_and_query() { $this->setLimit(10)->setOffset(100)->setHotnessFrom(50)->setHotnessTo(100)->setLifetimeFrom(10)->setLifetimeTo(30)->setSince('2016-01-01')->setUntil('2016-11-11'); $path = sprintf(self::URL_PATTERN, self::PUBLICATION_ID, self::SECTION_NAME); $query = 'limit=10&offset=100&hotnessFrom=50&hotnessTo=100&lifetimeFrom=10&lifetimeTo=30&since=2016-01-01&until=2016-11-11'; $this->buildApiHttpPathAndQuery()->shouldBeLike(ApiHttpPathAndQuery::createForPathAndQuery($path, $query)); }
function it_finds_articles_by_section_for_publication_id(ApiHttpClientInterface $apiHttpClient) { $expectedArticles = ['teasers' => [['id' => 1], ['id' => 2], ['id' => 3]]]; $path = sprintf(self::ARTICLES_FROM_SECTION_PATH_PATTERN, PublicationId::SA, self::SECTION_NAME); $apiHttpPathAndQuery = ApiHttpPathAndQuery::createForPath($path); $apiHttpClient->get($apiHttpPathAndQuery)->willReturn('{"teasers":[{"id":1},{"id":2},{"id":3}]}'); $findParameters = FindBySectionParameters::createForPublicationIdAndSections(PublicationId::SA, [self::SECTION_NAME]); $this->findBySections($findParameters)->shouldBeLike(Response::createFrom($expectedArticles)); }
function it_finds_all_sections_for_publication_id(ApiHttpClientInterface $apiHttpClient) { $expectedResponse = ['sections' => [['title' => 'sport'], ['title' => 'kultur']]]; $path = sprintf(self::SECTION_PATH_PATTERN, PublicationId::SA); $apiHttpPathAndQuery = ApiHttpPathAndQuery::createForPath($path); $findParameters = FindAllParameters::createForPublicationId(PublicationId::SA); $apiHttpClient->get($apiHttpPathAndQuery)->shouldBeCalled()->willReturn('{"sections": [{"title":"sport"},{"title":"kultur"}]}'); $this->findAll($findParameters)->shouldBeLike(Response::createFrom($expectedResponse)); }
function it_builds_api_http_path_and_query() { $timeRange = new TimeRangeParameter(new DateTime('2016-03-01'), new DateTime('2016-04-01')); $limit = 5; $this->beConstructedThrough('createForPublicationIdWithTimeRangeAndLimit', [PublicationId::AP, $timeRange, $limit]); $path = sprintf('changelog/%s/search', PublicationId::AP); $expectedApiHttpPathAndQuery = ApiHttpPathAndQuery::createForPathAndQuery($path, 'limit=5&since=2016-03-01+00%3A00%3A00&until=2016-04-01+00%3A00%3A00'); $this->buildApiHttpPathAndQuery()->shouldBeLike($expectedApiHttpPathAndQuery); }
function it_throws_exception_when_request_returns_not_found_error(HttpClientInterface $httpClient, RequestFactoryInterface $requestFactory, RequestInterface $request, ResponseInterface $response, HttpException $httpException) { $apiHttpPathAndQuery = ApiHttpPathAndQuery::createForPath(self::API_PATH); $response->getStatusCode()->willReturn(404); $requestFactory->createRequest(Argument::any(), Argument::any(), Argument::any())->willReturn($request); $httpException->getResponse()->willReturn($response); $httpClient->sendRequest($request)->willThrow($httpException->getWrappedObject()); $this->shouldThrow(ApiHttpClientNotFoundException::class)->duringGet($apiHttpPathAndQuery); }
/** * @Given there are sections for :publicationId publication in API: * * @param string $publicationId * @param PyStringNode $sectionsFromApi */ public function thereAreSectionsForPublicationInAPI($publicationId, PyStringNode $sectionsFromApi) { $sectionsFromApiWithPublication = str_replace('PUBLICATION_ID', $publicationId, $sectionsFromApi->getRaw()); $sectionsApiResponse = json_decode($sectionsFromApiWithPublication, true); $this->sectionsFromApi[$publicationId] = $sectionsApiResponse['sections']; $path = sprintf(self::SECTION_PATH_PATTERN, $publicationId); $this->apiHttpClient->shouldReceive('get')->with(Mockery::on(function (ApiHttpPathAndQuery $apiHttpPathAndQuery) use($path) { return $apiHttpPathAndQuery == ApiHttpPathAndQuery::createForPath($path); }))->andReturn($sectionsFromApiWithPublication); }
/** * {@inheritdoc} */ public function buildApiHttpPathAndQuery() { $path = sprintf(self::ARTICLES_PATH_PATTERN, $this->publicationId, implode(self::DEFAULT_SEPARATOR, $this->articleIds)); return ApiHttpPathAndQuery::createForPath($path); }
/** * {@inheritdoc} */ public function buildApiHttpPathAndQuery() { $path = sprintf(static::URL_PATTERN, $this->publicationId, implode(',', $this->sections)); $query = http_build_query($this->parameters); return ApiHttpPathAndQuery::createForPathAndQuery($path, $query); }
function it_builds_api_client_uri() { $expectedUri = sprintf('%s/%s?%s', self::API_ENDPOINT, self::API_PATH, self::API_QUERY); $apiHttpPathAndQuery = ApiHttpPathAndQuery::createForPathAndQuery(self::API_PATH, self::API_QUERY); $this->buildUri($apiHttpPathAndQuery)->shouldReturn($expectedUri); }
/** * {@inheritdoc} */ public function buildApiHttpPathAndQuery() { $path = sprintf(self::ARTICLES_PATH_PATTERN, $this->publicationId, $this->articleId); return ApiHttpPathAndQuery::createForPath($path); }
/** * {@inheritdoc} */ public function buildApiHttpPathAndQuery() { $path = sprintf(self::ARTICLES_CHANGELOG_PATTERN, $this->publicationId); return ApiHttpPathAndQuery::createForPathAndQuery($path, $this->buildQuery()); }
/** * @param ApiHttpPathAndQuery $apiHttpPathAndQuery * * @return string */ public function buildUri(ApiHttpPathAndQuery $apiHttpPathAndQuery) { return sprintf('%s/%s', $this->endpoint, $apiHttpPathAndQuery->getPathAndQuery()); }
/** * {@inheritdoc} */ public function buildApiHttpPathAndQuery() { $path = sprintf(self::SECTION_PATH_PATTERN, $this->publicationId); return ApiHttpPathAndQuery::createForPath($path); }
/** * @Given there are articles for :publicationId publication for desked section :section: * * @param string $publicationId * @param string $section * @param PyStringNode $apiResponse */ public function thereAreArticlesForPublicationForDeskedSection($publicationId, $section, PyStringNode $apiResponse) { $articlesApiResponse = json_decode($apiResponse->getRaw(), true); foreach ($articlesApiResponse['teasers'] as $article) { $this->articlesFromApi[$publicationId][$article['id']] = $article; } $path = sprintf(self::ARTICLES_FROM_DESKED_SECTION_PATH_PATTERN, $publicationId, $section); $this->apihttpClient->shouldReceive('get')->with(Mockery::on(function (ApiHttpPathAndQuery $apiHttpPathAndQuery) use($path) { return $apiHttpPathAndQuery == ApiHttpPathAndQuery::createForPath($path); }))->andReturn($apiResponse->getRaw()); }