Skip to content

Commit

Permalink
Fixed error with Foreign review
Browse files Browse the repository at this point in the history
  • Loading branch information
tim hall committed Nov 11, 2020
1 parent 9ea431a commit 774e39f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
C:37:"PHPUnit\Runner\DefaultTestResultCache":4998:{a:2:{s:7:"defects";a:5:{s:85:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_response";i:3;s:96:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_image_response";i:3;s:104:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_early_reviewer_rewards";i:3;s:76:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_use_dom_html";i:4;s:85:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_bug";i:3;}s:5:"times";a:36:{s:122:"EolabsIo\AmazonMwsClient\Tests\AmazonMwsResponseParserTest::it_throws_an_exception_if_an_invalid_response_type_is_provided";d:0.034;s:83:"EolabsIo\AmazonMwsClient\Tests\ErrorResponseParserTest::it_can_parse_error_response";d:0.004;s:95:"EolabsIo\AmazonMwsClient\Tests\GetMatchingProductResponseParserTest::it_can_get_result_accessor";d:0.003;s:111:"EolabsIo\AmazonMwsClient\Tests\GetMatchingProductResponseParserTest::it_can_parse_get_matching_product_response";d:0.003;s:112:"EolabsIo\AmazonMwsClient\Tests\GetMatchingProductResponseParserTest::it_can_parse_get_matching_products_response";d:0.003;s:119:"EolabsIo\AmazonMwsClient\Tests\InventoryServiceStatusResponseParserTest::it_can_parse_inventory_service_status_response";d:0.004;s:112:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventGroupsByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.003;s:143:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventGroupsByNextTokenResponseParserTest::it_can_parse_list_inventory_supply_by_next_token_response";d:0.003;s:101:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventGroupsResponseParserTest::it_can_get_result_accessor";d:0.003;s:107:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventGroupsResponseParserTest::it_can_parse_order_list_response";d:0.003;s:107:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventsByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.005;s:138:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventsByNextTokenResponseParserTest::it_can_parse_list_financial_events_by_next_token_response";d:0.003;s:96:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventsResponseParserTest::it_can_get_result_accessor";d:0.013;s:113:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventsResponseParserTest::it_can_parse_financial_events_list_response";d:0.01;s:107:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.003;s:138:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyByNextTokenResponseParserTest::it_can_parse_list_inventory_supply_by_next_token_response";d:0.003;s:96:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyResponseParserTest::it_can_get_result_accessor";d:0.003;s:113:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyResponseParserTest::it_can_parse_list_inventory_supply_response";d:0.003;s:124:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyResponseParserTest::it_can_parse_list_inventory_supply_with_token_response";d:0.002;s:106:"EolabsIo\AmazonMwsClient\Tests\ListMarketplaceParticipationsResponseParserTest::it_can_get_result_accessor";d:0.005;s:142:"EolabsIo\AmazonMwsClient\Tests\ListMarketplaceParticipationsResponseParserTest::it_can_parse_list_marketplace_participations_response_response";d:0.003;s:102:"EolabsIo\AmazonMwsClient\Tests\ListOrderItemsByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.004;s:123:"EolabsIo\AmazonMwsClient\Tests\ListOrderItemsByNextTokenResponseParserTest::it_can_parse_list_orders_by_next_token_response";d:0.003;s:91:"EolabsIo\AmazonMwsClient\Tests\ListOrderItemsResponseParserTest::it_can_get_result_accessor";d:0.004;s:97:"EolabsIo\AmazonMwsClient\Tests\ListOrderItemsResponseParserTest::it_can_parse_order_item_response";d:0.003;s:98:"EolabsIo\AmazonMwsClient\Tests\ListOrdersByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.005;s:119:"EolabsIo\AmazonMwsClient\Tests\ListOrdersByNextTokenResponseParserTest::it_can_parse_list_orders_by_next_token_response";d:0.003;s:87:"EolabsIo\AmazonMwsClient\Tests\ListOrdersResponseParserTest::it_can_get_result_accessor";d:0.004;s:93:"EolabsIo\AmazonMwsClient\Tests\ListOrdersResponseParserTest::it_can_parse_order_list_response";d:0.003;s:110:"EolabsIo\AmazonMwsClient\Tests\ListOrdersResponseParserTest::it_can_parse_order_list_removes_elements_response";d:0.004;s:85:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_response";d:0.413;s:98:"EolabsIo\AmazonMwsClient\Tests\ReviewRatingResponseParserTest::it_can_parse_review_rating_response";d:0.177;s:96:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_image_response";d:0.021;s:104:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_early_reviewer_rewards";d:0.355;s:76:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_use_dom_html";d:0.051;s:85:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_bug";d:0.025;}}}
C:37:"PHPUnit\Runner\DefaultTestResultCache":4998:{a:2:{s:7:"defects";a:5:{s:85:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_response";i:4;s:96:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_image_response";i:4;s:104:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_early_reviewer_rewards";i:4;s:76:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_use_dom_html";i:4;s:85:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_bug";i:3;}s:5:"times";a:36:{s:122:"EolabsIo\AmazonMwsClient\Tests\AmazonMwsResponseParserTest::it_throws_an_exception_if_an_invalid_response_type_is_provided";d:0.032;s:83:"EolabsIo\AmazonMwsClient\Tests\ErrorResponseParserTest::it_can_parse_error_response";d:0.005;s:95:"EolabsIo\AmazonMwsClient\Tests\GetMatchingProductResponseParserTest::it_can_get_result_accessor";d:0.003;s:111:"EolabsIo\AmazonMwsClient\Tests\GetMatchingProductResponseParserTest::it_can_parse_get_matching_product_response";d:0.003;s:112:"EolabsIo\AmazonMwsClient\Tests\GetMatchingProductResponseParserTest::it_can_parse_get_matching_products_response";d:0.004;s:119:"EolabsIo\AmazonMwsClient\Tests\InventoryServiceStatusResponseParserTest::it_can_parse_inventory_service_status_response";d:0.004;s:112:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventGroupsByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.005;s:143:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventGroupsByNextTokenResponseParserTest::it_can_parse_list_inventory_supply_by_next_token_response";d:0.004;s:101:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventGroupsResponseParserTest::it_can_get_result_accessor";d:0.004;s:107:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventGroupsResponseParserTest::it_can_parse_order_list_response";d:0.004;s:107:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventsByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.004;s:138:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventsByNextTokenResponseParserTest::it_can_parse_list_financial_events_by_next_token_response";d:0.003;s:96:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventsResponseParserTest::it_can_get_result_accessor";d:0.015;s:113:"EolabsIo\AmazonMwsClient\Tests\ListFinancialEventsResponseParserTest::it_can_parse_financial_events_list_response";d:0.01;s:107:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.006;s:138:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyByNextTokenResponseParserTest::it_can_parse_list_inventory_supply_by_next_token_response";d:0.004;s:96:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyResponseParserTest::it_can_get_result_accessor";d:0.005;s:113:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyResponseParserTest::it_can_parse_list_inventory_supply_response";d:0.004;s:124:"EolabsIo\AmazonMwsClient\Tests\ListInventorySupplyResponseParserTest::it_can_parse_list_inventory_supply_with_token_response";d:0.003;s:106:"EolabsIo\AmazonMwsClient\Tests\ListMarketplaceParticipationsResponseParserTest::it_can_get_result_accessor";d:0.005;s:142:"EolabsIo\AmazonMwsClient\Tests\ListMarketplaceParticipationsResponseParserTest::it_can_parse_list_marketplace_participations_response_response";d:0.004;s:102:"EolabsIo\AmazonMwsClient\Tests\ListOrderItemsByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.005;s:123:"EolabsIo\AmazonMwsClient\Tests\ListOrderItemsByNextTokenResponseParserTest::it_can_parse_list_orders_by_next_token_response";d:0.004;s:91:"EolabsIo\AmazonMwsClient\Tests\ListOrderItemsResponseParserTest::it_can_get_result_accessor";d:0.004;s:97:"EolabsIo\AmazonMwsClient\Tests\ListOrderItemsResponseParserTest::it_can_parse_order_item_response";d:0.004;s:98:"EolabsIo\AmazonMwsClient\Tests\ListOrdersByNextTokenResponseParserTest::it_can_get_result_accessor";d:0.005;s:119:"EolabsIo\AmazonMwsClient\Tests\ListOrdersByNextTokenResponseParserTest::it_can_parse_list_orders_by_next_token_response";d:0.004;s:87:"EolabsIo\AmazonMwsClient\Tests\ListOrdersResponseParserTest::it_can_get_result_accessor";d:0.005;s:93:"EolabsIo\AmazonMwsClient\Tests\ListOrdersResponseParserTest::it_can_parse_order_list_response";d:0.004;s:110:"EolabsIo\AmazonMwsClient\Tests\ListOrdersResponseParserTest::it_can_parse_order_list_removes_elements_response";d:0.004;s:85:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_response";d:0.419;s:98:"EolabsIo\AmazonMwsClient\Tests\ReviewRatingResponseParserTest::it_can_parse_review_rating_response";d:0.179;s:96:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_image_response";d:0.021;s:104:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_early_reviewer_rewards";d:0.367;s:76:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_use_dom_html";d:0.051;s:85:"EolabsIo\AmazonMwsClient\Tests\ReviewResponseParserTest::it_can_parse_review_with_bug";d:0.025;}}}
24 changes: 23 additions & 1 deletion src/Parsers/ReviewResponseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function getReviews(Crawler $domCrawler): Collection
'starRating' => $this->getStarRating($review),
'title' => $this->getTitle($review),
'date' => $this->getDate($review),
'location' => $this->getLocation($review),
'verifiedPurchase' => $this->getVerifiedPurchase($review),
'earlyReviewerRewards' => $this->getEarlyReviewerRewards($review),
'vineVoice' => $this->getVineVoice($review),
Expand All @@ -72,14 +73,24 @@ public function getStarRating(Crawler $review): string
{
$reviewStarRating = $review->filter('i[data-hook="review-star-rating"]')->text('');

if ($reviewStarRating == '') {
$reviewStarRating = $review->filter('i[data-hook="cmps-review-star-rating"]')->text('');
}

return Str::of($reviewStarRating)
->before('out of 5')
->trim();
}

public function getTitle(Crawler $review): string
{
return $review->filter('a[data-hook="review-title"]')->text('');
$title = $review->filter('a[data-hook="review-title"]')->text('');

if ($title == '') {
$title = $review->filter('span[data-hook="review-title"]')->text('');
}

return $title;
}

public function getDate(Crawler $review): string
Expand All @@ -91,6 +102,17 @@ public function getDate(Crawler $review): string
->trim();
}

public function getLocation(Crawler $review): string
{
$tagDateValue = $review->filter('span[data-hook="review-date"]')->text('');

return Str::of($tagDateValue)
->after('in')
->before('on')
->replace('the', '')
->trim();
}

public function getVerifiedPurchase(Crawler $review): bool
{
$span = $review->filter('span[data-hook="avp-badge"]');
Expand Down
10 changes: 9 additions & 1 deletion tests/ReviewResponseParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function it_can_parse_review_response()

$this->assertCount(10, $response['reviews']);
$this->assertEquals('R2J4Q876AFF4ID', $firstReview['reviewId']);
$this->assertEquals('5.0', $firstReview['starRating']);
$this->assertEquals(5.0, $firstReview['starRating']);
$this->assertEquals('This actually works -My first review of anything in over 15 years,', $firstReview['title']);
$this->assertEquals('June 17, 2019', $firstReview['date']);
$this->assertTrue($firstReview['verifiedPurchase']);
Expand Down Expand Up @@ -83,6 +83,14 @@ public function it_can_parse_review_with_bug()
$this->assertFalse($response['reviews'][1]['earlyReviewerRewards']);
$this->assertTrue($response['reviews'][4]['verifiedPurchase']);
$this->assertTrue($response['reviews'][4]['earlyReviewerRewards']);
$this->assertEquals('United States', $response['reviews'][4]['location']);


$this->assertEquals('Chris', $response['reviews'][8]['profileName']);
$this->assertEquals(1, $response['reviews'][8]['starRating']);
$this->assertEquals('Was inactive probiotic', $response['reviews'][8]['title']);
$this->assertEquals('Australia', $response['reviews'][8]['location']);

$this->assertEquals(79, $response['numberOfReviews']);
$this->assertEquals(244, $response['numberOfRatings']);
}
Expand Down

0 comments on commit 774e39f

Please sign in to comment.