Passed
Push — master ( 29fb2d...445708 )
by Steffen
10:50
created

DataStorageConverterTest::testConversion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 6
1
<?php
2
/*
3
 * This file is part of the unicorn project
4
 *
5
 * (c) Philipp Braeutigam <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Xynnn\Unicorn\Tests\Converter;
11
12
use PHPUnit_Framework_TestCase;
13
use Xynnn\Unicorn\Converter\DataStorageConverter;
14
use Xynnn\Unicorn\Model\ConvertibleValue;
15
use Xynnn\Unicorn\Model\Unit;
16
17
class DataStorageConverterTest extends PHPUnit_Framework_TestCase
18
{
19
    public function testIsInstantiable()
20
    {
21
        $converter = $this->getConverter();
22
23
        $this->assertInstanceOf(DataStorageConverter::class, $converter);
24
    }
25
26
    public function testGetName()
27
    {
28
        $converter = $this->getConverter();
29
30
        $this->assertEquals('unicorn.converter.datastorage', $converter->getName());
31
    }
32
33
    /**
34
     * @return array
35
     */
36
    public function dataProvider()
37
    {
38
        $converter = $this->getConverter();
39
40
        return [
41
            [$converter, new ConvertibleValue('1', $converter::$gigabyte), $converter::$megabyte, '1000', $converter::$megabyte->getName(), $converter::$megabyte->getAbbreviation()],
42
            [$converter, new ConvertibleValue('1', $converter::$gibibyte), $converter::$mebibyte, '1024', $converter::$mebibyte->getName(), $converter::$mebibyte->getAbbreviation()],
43
            [$converter, new ConvertibleValue('1', $converter::$tebibyte), $converter::$gibibyte, '1024', $converter::$gibibyte->getName(), $converter::$gibibyte->getAbbreviation()],
44
            [$converter, new ConvertibleValue('1', $converter::$tebibyte), $converter::$mebibyte, '1048576', $converter::$mebibyte->getName(), $converter::$mebibyte->getAbbreviation()],
45
            [$converter, new ConvertibleValue('1', $converter::$gibibyte), $converter::$megabyte, '1073.741824', $converter::$megabyte->getName(), $converter::$megabyte->getAbbreviation()],
46
            [$converter, new ConvertibleValue('1', $converter::$gibibyte), $converter::$megabyte, '1073.741824', $converter::$megabyte->getName(), $converter::$megabyte->getAbbreviation()],
47
            [$converter, new ConvertibleValue('1', $converter::$pebibyte), $converter::$gigabyte, '1125899.906842624', $converter::$gigabyte->getName(), $converter::$gigabyte->getAbbreviation()],
48
            [$converter, new ConvertibleValue('1', $converter::$gigabit), $converter::$megabit, '1000', $converter::$megabit->getName(), $converter::$megabit->getAbbreviation()],
49
            [$converter, new ConvertibleValue('1', $converter::$gigabit), $converter::$megabyte, '125', $converter::$megabyte->getName(), $converter::$megabyte->getAbbreviation()],
50
            [$converter, new ConvertibleValue('1', $converter::$gibibit), $converter::$mebibit, '1024', $converter::$mebibit->getName(), $converter::$mebibit->getAbbreviation()],
51
            [$converter, new ConvertibleValue('1', $converter::$gibibit), $converter::$megabyte, '134.217728', $converter::$megabyte->getName(), $converter::$megabyte->getAbbreviation()]
52
        ];
53
    }
54
55
    /**
56
     * @dataProvider dataProvider
57
     * @param DataStorageConverter $converter
58
     * @param ConvertibleValue $from
59
     * @param Unit $to
60
     * @param string $expectedValue
61
     * @param string $expectedUnitName
62
     * @param string $expectedUnitAbbreviation
63
     */
64 View Code Duplication
    public function testConversion(DataStorageConverter $converter, ConvertibleValue $from, Unit $to, string $expectedValue, string $expectedUnitName, string $expectedUnitAbbreviation)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
    {
66
        $result = $converter->convert($from, $to);
67
68
        $this->assertEquals($expectedValue, $result->getValue());
69
        $this->assertEquals($expectedUnitName, $result->getUnit()->getName());
70
        $this->assertEquals($expectedUnitAbbreviation, $result->getUnit()->getAbbreviation());
71
    }
72
73
    /**
74
     * @return DataStorageConverter
75
     */
76
    private function getConverter() : DataStorageConverter
77
    {
78
        return new DataStorageConverter();
79
    }
80
}
81