Test Failed
Pull Request — master (#7)
by mon
02:27 queued 34s
created

MapUpdaterTest::testWriteMapToCodeFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace FileEye\MimeMap\test;
4
5
use Symfony\Component\Filesystem\Filesystem;
6
use FileEye\MimeMap\Extension;
7
use FileEye\MimeMap\MapHandler;
8
use FileEye\MimeMap\MapUpdater;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * @coversDefaultClass \FileEye\MimeMap\MapUpdater
13
 * @backupStaticAttributes enabled
14
 */
15
class MapUpdaterTest extends TestCase
16
{
17
    protected $updater;
18
    protected $fileSystem;
19
20
    public function setUp()
21
    {
22
        $this->updater = new MapUpdater();
23
        $this->fileSystem = new Filesystem();
24
    }
25
26
    public function testCreateMapFromSourceFile()
27
    {
28
        $map = $this->updater->createMapFromSourceFile(dirname(__FILE__) . '/../fixtures/min.mime-types.txt');
29
        $expected = [
30
            'types' => [
31
                'image/jpeg' => ['jpeg', 'jpg', 'jpe'],
32
                'text/plain' => ['txt'],
33
            ],
34
            'extensions' => [
35
                'jpeg' => ['image/jpeg'],
36
                'jpg' => ['image/jpeg'],
37
                'jpe' => ['image/jpeg'],
38
                'txt' => ['text/plain'],
39
            ],
40
        ];
41
        $this->assertSame($expected, $map->get());
42
    }
43
44
    /**
45
     * @expectedException \RuntimeException
46
     */
47
    public function testCreateMapFromSourceFileZeroLines()
48
    {
49
        $map = $this->updater->createMapFromSourceFile(dirname(__FILE__) . '/../fixtures/zero.mime-types.txt');
50
        $this->assertNull($map->get());
51
    }
52
53
    public function testCompareMapsEqual()
54
    {
55
        $map_a = $this->updater->createMapFromSourceFile(dirname(__FILE__) . '/../fixtures/min.mime-types.txt');
56
        $map_b = $this->updater->createMapFromSourceFile(dirname(__FILE__) . '/../fixtures/min.mime-types.txt');
57
        $this->assertTrue($this->updater->compareMaps($map_a, $map_b, 'types'));
58
        $this->assertTrue($this->updater->compareMaps($map_a, $map_b, 'extensions'));
59
    }
60
61
    /**
62
     * @expectedException \RuntimeException
63
     */
64
    public function testCompareMapsNotEqual()
65
    {
66
        $map_a = $this->updater->createMapFromSourceFile(dirname(__FILE__) . '/../fixtures/min.mime-types.txt');
67
        $map_b = $this->updater->createMapFromSourceFile(dirname(__FILE__) . '/../fixtures/some.mime-types.txt');
68
        $this->updater->compareMaps($map_a, $map_b, 'types');
69
    }
70
71
    public function testWriteMapToCodeFile()
72
    {
73
        $this->fileSystem->copy(__DIR__ . '/../../src/Tests/MiniMap.php.test', __DIR__ . '/../../src/Tests/MiniMap.php');
74
        MapHandler::setDefaultMapClass('\FileEye\MimeMap\Tests\MiniMap');
75
        $map_a = new MapHandler();
76
        $this->assertNotContains('text/plain', file_get_contents($map_a->getMapFileName()));
77
        $map_b = $this->updater->createMapFromSourceFile(dirname(__FILE__) . '/../fixtures/min.mime-types.txt');
78
        $this->updater->applyOverrides($map_b, [['addMapping'], ['bing/bong', 'binbon']]);
79
        $this->updater->writeMapToCodeFile($map_b, $map_a->getMapFileName());
80
        $content = file_get_contents($map_a->getMapFileName());
81
        $this->assertContains('text/plain', $content);
82
        $this->assertContains('bing/bong', $content);
83
        $this->assertContains('binbon', $content);
84
        $map_a = null;
0 ignored issues
show
Unused Code introduced by
$map_a is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
85
        $map_b = null;
0 ignored issues
show
Unused Code introduced by
$map_b is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
86
        $this->fileSystem->remove(__DIR__ . '/../../src/Tests/MiniMap.php');
87
    }
88
}
89