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

AverageRatingCalculatorSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A it_implements_average_price_calculator_interface() 0 4 1
A it_calculates_average_price() 0 15 1
A it_returns_zero_if_given_reviewable_object_has_no_reviews() 0 6 1
A it_returns_zero_if_given_reviewable_object_has_reviews_but_none_of_them_is_accepted() 0 9 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\Component\Review\Calculator;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use PhpSpec\ObjectBehavior;
18
use Sylius\Component\Review\Calculator\ReviewableRatingCalculatorInterface;
19
use Sylius\Component\Review\Model\ReviewableInterface;
20
use Sylius\Component\Review\Model\ReviewInterface;
21
22
/**
23
 * @author Mateusz Zalewski <[email protected]>
24
 */
25
final class AverageRatingCalculatorSpec extends ObjectBehavior
26
{
27
    function it_implements_average_price_calculator_interface(): void
28
    {
29
        $this->shouldImplement(ReviewableRatingCalculatorInterface::class);
30
    }
31
32
    function it_calculates_average_price(
33
        ReviewableInterface $reviewable,
34
        ReviewInterface $review1,
35
        ReviewInterface $review2
36
    ): void {
37
        $reviewable->getReviews()->willReturn(new ArrayCollection([$review1->getWrappedObject(), $review2->getWrappedObject()]));
38
39
        $review1->getStatus()->willReturn(ReviewInterface::STATUS_ACCEPTED);
40
        $review2->getStatus()->willReturn(ReviewInterface::STATUS_ACCEPTED);
41
42
        $review1->getRating()->willReturn(4);
43
        $review2->getRating()->willReturn(5);
44
45
        $this->calculate($reviewable)->shouldReturn(4.5);
46
    }
47
48
    function it_returns_zero_if_given_reviewable_object_has_no_reviews(ReviewableInterface $reviewable): void
49
    {
50
        $reviewable->getReviews()->willReturn(new ArrayCollection([]))->shouldBeCalled();
51
52
        $this->calculate($reviewable)->shouldReturn(0.0);
53
    }
54
55
    function it_returns_zero_if_given_reviewable_object_has_reviews_but_none_of_them_is_accepted(
56
        ReviewableInterface $reviewable,
57
        ReviewInterface $review
58
    ): void {
59
        $reviewable->getReviews()->willReturn(new ArrayCollection([$review->getWrappedObject()]));
60
        $review->getStatus()->willReturn(ReviewInterface::STATUS_NEW);
61
62
        $this->calculate($reviewable)->shouldReturn(0.0);
63
    }
64
}
65