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

AverageRatingUpdaterSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 40
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_implements_product_average_rating_updater_interface() 0 4 1
A it_updates_review_subject_average_rating() 0 12 1
A it_updates_review_subject_average_rating_from_review() 0 14 1
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