Completed
Push — taxon-ancestor ( 0755ef )
by Kamil
119:50 queued 87:37
created

AverageRatingUpdaterSpec::it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
eloc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace spec\Sylius\Bundle\ReviewBundle\Updater;
15
16
use Doctrine\Common\Persistence\ObjectManager;
17
use PhpSpec\ObjectBehavior;
18
use Sylius\Bundle\ReviewBundle\Updater\ReviewableRatingUpdaterInterface;
19
use Sylius\Component\Review\Calculator\ReviewableRatingCalculatorInterface;
20
use Sylius\Component\Review\Model\ReviewableInterface;
21
use Sylius\Component\Review\Model\ReviewInterface;
22
23
/**
24
 * @author Mateusz Zalewski <[email protected]>
25
 */
26
final class AverageRatingUpdaterSpec extends ObjectBehavior
27
{
28
    function let(ReviewableRatingCalculatorInterface $averageRatingCalculator, ObjectManager $reviewSubjectManager): void
29
    {
30
        $this->beConstructedWith($averageRatingCalculator, $reviewSubjectManager);
31
    }
32
33
    function it_implements_product_average_rating_updater_interface(): void
34
    {
35
        $this->shouldImplement(ReviewableRatingUpdaterInterface::class);
36
    }
37
38
    function it_updates_review_subject_average_rating(
39
        $averageRatingCalculator,
40
        $reviewSubjectManager,
41
        ReviewableInterface $reviewSubject
42
    ): void {
43
        $averageRatingCalculator->calculate($reviewSubject)->willReturn(4.5);
44
45
        $reviewSubject->setAverageRating(4.5)->shouldBeCalled();
46
        $reviewSubjectManager->flush($reviewSubject)->shouldBeCalled();
47
48
        $this->update($reviewSubject);
49
    }
50
51
    function it_updates_review_subject_average_rating_from_review(
52
        $averageRatingCalculator,
53
        $reviewSubjectManager,
54
        ReviewableInterface $reviewSubject,
55
        ReviewInterface $review
56
    ): void {
57
        $review->getReviewSubject()->willReturn($reviewSubject);
58
        $averageRatingCalculator->calculate($reviewSubject)->willReturn(4.5);
59
60
        $reviewSubject->setAverageRating(4.5)->shouldBeCalled();
61
        $reviewSubjectManager->flush($reviewSubject)->shouldBeCalled();
62
63
        $this->updateFromReview($review);
64
    }
65
}
66