Completed
Push — master ( 155c16...880d18 )
by Kamil
26:05
created

IntegerDistributorSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 31
rs 10
c 1
b 1
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A it_implements_integer_distributor_interface() 0 4 1
A it_distributes_simple_integers() 0 6 1
A it_distributes_integers_that_cannot_be_split_equally() 0 5 1
A it_throws_exception_if_number_of_targets_is_not_integer_or_below_1() 0 5 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
namespace spec\Sylius\Component\Core\Distributor;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Component\Core\Distributor\IntegerDistributorInterface;
16
17
/**
18
 * @author Mateusz Zalewski <[email protected]>
19
 */
20
class IntegerDistributorSpec extends ObjectBehavior
21
{
22
    function it_is_initializable()
23
    {
24
        $this->shouldHaveType('Sylius\Component\Core\Distributor\IntegerDistributor');
25
    }
26
27
    function it_implements_integer_distributor_interface()
28
    {
29
        $this->shouldImplement(IntegerDistributorInterface::class);
30
    }
31
32
    function it_distributes_simple_integers()
33
    {
34
        $this->distribute(0, 4)->shouldReturn([0, 0, 0, 0]);
35
        $this->distribute(1000, 4)->shouldReturn([250, 250, 250, 250]);
36
        $this->distribute(-1000, 4)->shouldReturn([-250, -250, -250, -250]);
37
    }
38
39
    function it_distributes_integers_that_cannot_be_split_equally()
40
    {
41
        $this->distribute(1000, 3)->shouldReturn([334, 333, 333]);
42
        $this->distribute(-1000, 3)->shouldReturn([-334, -333, -333]);
43
    }
44
45
    function it_throws_exception_if_number_of_targets_is_not_integer_or_below_1()
46
    {
47
        $this->shouldThrow(new \InvalidArgumentException('Number of targets must be an integer, bigger than 0.'))->during('distribute', [1000, 'test']);
48
        $this->shouldThrow(new \InvalidArgumentException('Number of targets must be an integer, bigger than 0.'))->during('distribute', [1000, 0]);
49
    }
50
}
51