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_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);
 }
 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));
 }
 /**
  * @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);
 }
 function it_builds_url()
 {
     $path = sprintf(self::URL_PATTERN, self::PUBLICATION_ID, self::SECTION_NAME, self::EMPTY_QUERY);
     $path = rtrim($path, '?');
     $this->buildApiHttpPathAndQuery()->shouldBeLike(ApiHttpPathAndQuery::createForPath($path));
 }
 function it_builds_url()
 {
     $path = sprintf(self::URL_PATTERN, PublicationId::SA, self::DEFAULT_DESKED_SECTION);
     $this->buildApiHttpPathAndQuery()->shouldBeLike(ApiHttpPathAndQuery::createForPath($path));
 }
 /**
  * {@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());
 }
 /**
  * {@inheritdoc}
  */
 public function buildApiHttpPathAndQuery()
 {
     $path = sprintf(self::ARTICLES_PATH_PATTERN, $this->publicationId, $this->articleId);
     return ApiHttpPathAndQuery::createForPath($path);
 }