GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

MeasureConverterSpec   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 4
Bugs 1 Features 0
Metric Value
c 4
b 1
f 0
dl 0
loc 75
wmc 8
lcom 0
cbo 6
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 10 2
A it_allows_to_define_the_family() 0 4 1
A it_throws_an_exception_if_an_unknown_family_is_set() 0 8 1
A it_converts_a_value_from_a_base_unit_to_a_final_unit() 0 9 1
A it_converts_a_value_to_a_standard_unit() 0 8 1
A it_converts_a_standard_value_to_a_final_unit() 0 8 1
A it_throws_an_exception_if_the_unit_measure_does_not_exist() 0 19 1
1
<?php
2
3
namespace spec\Akeneo\Bundle\MeasureBundle\Convert;
4
5
use Akeneo\Bundle\MeasureBundle\Exception\UnknownFamilyMeasureException;
6
use Akeneo\Bundle\MeasureBundle\Exception\UnknownMeasureException;
7
use Akeneo\Bundle\MeasureBundle\Family\WeightFamilyInterface;
8
use PhpSpec\ObjectBehavior;
9
use Prophecy\Argument;
10
use Symfony\Component\Yaml\Yaml;
11
12
class MeasureConverterSpec extends ObjectBehavior
13
{
14
    public function let()
15
    {
16
        $filename = realpath(dirname(__FILE__) .'/../Resources/config/measure-test.yml');
17
        if (!file_exists($filename)) {
18
            throw new \Exception(sprintf('Config file "%s" does not exist', $filename));
19
        }
20
21
        $config = Yaml::parse(file_get_contents($filename));
22
        $this->beConstructedWith($config);
23
    }
24
25
    public function it_allows_to_define_the_family()
26
    {
27
        $this->setFamily('Length')->shouldReturnAnInstanceOf('Akeneo\Bundle\MeasureBundle\Convert\MeasureConverter');
28
    }
29
30
    public function it_throws_an_exception_if_an_unknown_family_is_set()
31
    {
32
        $this
33
            ->shouldThrow(
34
                new UnknownFamilyMeasureException()
35
            )
36
            ->during('setFamily', ['foo']);
37
    }
38
39
    public function it_converts_a_value_from_a_base_unit_to_a_final_unit()
40
    {
41
        $this->setFamily('Weight');
42
        $this->convert(
43
            WeightFamilyInterface::KILOGRAM,
44
            WeightFamilyInterface::MILLIGRAM,
45
            1
46
        )->shouldReturn((double) 1000000);
47
    }
48
49
    public function it_converts_a_value_to_a_standard_unit()
50
    {
51
        $this->setFamily('Weight');
52
        $this->convertBaseToStandard(
53
            WeightFamilyInterface::MILLIGRAM,
54
            1000
55
        )->shouldReturn((double) 1);
56
    }
57
58
    public function it_converts_a_standard_value_to_a_final_unit()
59
    {
60
        $this->setFamily('Weight');
61
        $this->convertStandardToResult(
62
            WeightFamilyInterface::KILOGRAM,
63
            10
64
        )->shouldReturn((double) 0.01);
65
    }
66
67
    public function it_throws_an_exception_if_the_unit_measure_does_not_exist()
68
    {
69
        $this->setFamily('Weight');
70
        $this
71
            ->shouldThrow(
72
                new UnknownMeasureException(
73
                    'Could not find metric unit "foo" in family "Weight"'
74
                )
75
            )
76
            ->during('convertBaseToStandard', ['foo', Argument::any()]);
77
78
        $this
79
            ->shouldThrow(
80
                new UnknownMeasureException(
81
                    'Could not find metric unit "foo" in family "Weight"'
82
                )
83
            )
84
            ->during('convertStandardToResult', ['foo', Argument::any()]);
85
    }
86
}
87