Skip to content

Commit

Permalink
#21200: Static test fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
p-bystritsky authored and Den4ik committed Jun 1, 2019
1 parent 643ea4f commit a29bbec
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 16 deletions.
3 changes: 2 additions & 1 deletion app/code/Magento/Review/Block/Customer/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Review\Block\Customer;

use Magento\Catalog\Model\Product;
Expand Down Expand Up @@ -202,7 +203,7 @@ public function dateFormat($date)
}

/**
* @return string
* @inheritDoc
*/
protected function _toHtml()
{
Expand Down
7 changes: 4 additions & 3 deletions app/code/Magento/Review/Block/Product/ReviewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class ReviewRenderer extends \Magento\Framework\View\Element\Template implements
/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Review\Model\ReviewFactory $reviewFactory
* @param ReviewSummaryFactory $reviewSummaryFactory
* @param array $data
* @param ReviewSummaryFactory $reviewSummaryFactory
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
Expand All @@ -54,7 +54,8 @@ public function __construct(
ReviewSummaryFactory $reviewSummaryFactory = null
) {
$this->_reviewFactory = $reviewFactory;
$this->reviewSummaryFactory = $reviewSummaryFactory ?? ObjectManager::getInstance()->get(ReviewSummaryFactory::class);
$this->reviewSummaryFactory = $reviewSummaryFactory ??
ObjectManager::getInstance()->get(ReviewSummaryFactory::class);
parent::__construct($context, $data);
}

Expand Down Expand Up @@ -94,7 +95,7 @@ public function getReviewsSummaryHtml(
);
}

if (!$product->getRatingSummary() && !$displayIfNoReviews) {
if (null === $product->getRatingSummary() && !$displayIfNoReviews) {
return '';
}
// pick template among available
Expand Down
13 changes: 8 additions & 5 deletions app/code/Magento/Review/Model/ResourceModel/Review/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ public function reAggregate($summary)
* Append review summary fields to product collection
*
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection
* @param $storeId
* @param $entityCode
* @param string $storeId
* @param string $entityCode
* @return Summary
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function appendSummaryFieldsToCollection(
\Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection,
$storeId,
$entityCode
string $storeId,
string $entityCode
) {
if (!$productCollection->isLoaded()) {
$summaryEntitySubSelect = $this->getConnection()->select();
Expand All @@ -99,7 +99,10 @@ public function appendSummaryFieldsToCollection(
'entity_code = ?',
$entityCode
);
$joinCond = new \Zend_Db_Expr("e.entity_id = review_summary.entity_pk_value AND review_summary.store_id = {$storeId} AND review_summary.entity_type = ({$summaryEntitySubSelect})");
$joinCond = new \Zend_Db_Expr(
"e.entity_id = review_summary.entity_pk_value AND review_summary.store_id = {$storeId}"
. " AND review_summary.entity_type = ({$summaryEntitySubSelect})"
);
$productCollection->getSelect()
->joinLeft(
['review_summary' => $this->getMainTable()],
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Review/Model/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public function appendSummary($collection)
$entityIds[] = $item->getEntityId();
}

if (sizeof($entityIds) == 0) {
if (count($entityIds) === 0) {
return $this;
}

Expand Down
20 changes: 14 additions & 6 deletions app/code/Magento/Review/Model/ReviewSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
use Magento\Framework\Model\AbstractModel;
use Magento\Review\Model\ResourceModel\Review\Summary\CollectionFactory as SummaryCollectionFactory;

/**
* ReviewSummary model.
*/
class ReviewSummary
{
/**
* @var SummaryCollectionFactory
*/
private $summaryCollectionFactory;

/**
* @param SummaryCollectionFactory $sumColFactory
*/
public function __construct(
SummaryCollectionFactory $sumColFactory
) {
Expand All @@ -27,18 +33,20 @@ public function __construct(
* Append review summary data to product
*
* @param AbstractModel $object
* @param $storeId
* @param int $storeId
* @param int $entityType
*/
public function appendSummaryDataToObject(AbstractModel $object, $storeId, $entityType = 1): void
public function appendSummaryDataToObject(AbstractModel $object, int $storeId, int $entityType = 1): void
{
$summary = $this->summaryCollectionFactory->create()
->addEntityFilter($object->getId(), $entityType)
->addStoreFilter($storeId)
->getFirstItem();
$object->addData([
'reviews_count' => $summary->getData('reviews_count'),
'rating_summary' => $summary->getData('rating_summary')
]);
$object->addData(
[
'reviews_count' => $summary->getData('reviews_count'),
'rating_summary' => $summary->getData('rating_summary')
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
use Magento\Review\Model\ResourceModel\Review\SummaryFactory;
use Magento\Store\Model\StoreManagerInterface;

/**
* Append review summary to product list collection.
*/
class CatalogProductListCollectionAppendSummaryFieldsObserver implements ObserverInterface
{
/**
Expand Down Expand Up @@ -53,6 +56,7 @@ public function execute(EventObserver $observer)
$this->storeManager->getStore()->getId(),
\Magento\Review\Model\Review::ENTITY_PRODUCT_CODE
);

return $this;
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/Review/Test/Unit/Model/ReviewSummaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use PHPUnit\Framework\MockObject\MockObject;

/**
* Test for Magento\Review\Model\ReviewSummary class.
*/
class ReviewSummaryTest extends \PHPUnit\Framework\TestCase
{
/**
Expand Down

0 comments on commit a29bbec

Please sign in to comment.