Passed
Pull Request — master (#9)
by mon
02:42
created

MapUpdaterTest::testWriteMapToCodeFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A MapUpdaterTest::testGetDefaultOverrideFile() 0 4 1
1
<?php
2
3
namespace FileEye\MimeMap\test;
4
5
use Symfony\Component\Filesystem\Filesystem;
6
use FileEye\MimeMap\MapHandler;
7
use FileEye\MimeMap\MapUpdater;
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * @coversDefaultClass \FileEye\MimeMap\MapUpdater
12
 * @backupStaticAttributes enabled
13
 */
14
class MapUpdaterTest extends TestCase
15
{
16
    protected $updater;
17
    protected $fileSystem;
18
19
    public function setUp()
20
    {
21
        $this->updater = new MapUpdater();
22
        $this->fileSystem = new Filesystem();
23
    }
24
25
    public function testCreateMapFromSourceFile()
26
    {
27
        $map = $this->updater->createMapFromSourceFile(dirname(__FILE__) . '/../fixtures/min.mime-types.txt');
28
        $expected = [
29
            'types' => [
30
                'image/jpeg' => ['jpeg', 'jpg', 'jpe'],
31
                'text/plain' => ['txt'],
32
            ],
33
            'extensions' => [
34
                'jpeg' => ['image/jpeg'],
35
                'jpg' => ['image/jpeg'],
36
                'jpe' => ['image/jpeg'],
37
                'txt' => ['text/plain'],
38
            ],
39
        ];
40
        $this->assertSame($expected, $map->getMapArray());
0 ignored issues
show
Bug introduced by
The method getMapArray cannot be called on $map (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
41
        $this->assertSame(['image/jpeg', 'text/plain'], $map->listTypes());
0 ignored issues
show
Bug introduced by
The method listTypes cannot be called on $map (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
42
        $this->assertSame(['jpeg', 'jpg', 'jpe', 'txt'], $map->listExtensions());
0 ignored issues
show
Bug introduced by
The method listExtensions cannot be called on $map (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
43
        $map->reset();
0 ignored issues
show
Bug introduced by
The method reset cannot be called on $map (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
44
    }
45
46
    /**
47
     * @expectedException \RuntimeException
48
     */
49
    public function testCreateMapFromSourceFileZeroLines()
50
    {
51
        $map = $this->updater->createMapFromSourceFile(dirname(__FILE__) . '/../fixtures/zero.mime-types.txt');
52
        $this->assertNull($map->getMapArray());
0 ignored issues
show
Bug introduced by
The method getMapArray cannot be called on $map (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
53
        $map->reset();
0 ignored issues
show
Bug introduced by
The method reset cannot be called on $map (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
54
    }
55
56
    public function testWriteMapToPhpClassFile()
57
    {
58
        $this->fileSystem->copy(__DIR__ . '/../../src/Map/MiniMap.php.test', __DIR__ . '/../../src/Map/MiniMap.php');
59
        MapHandler::setDefaultMapClass('\FileEye\MimeMap\Map\MiniMap');
60
        $map_a = MapHandler::map();
61
        $content = file_get_contents($map_a->getFileName());
0 ignored issues
show
Bug introduced by
The method getFileName cannot be called on $map_a (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
62
        $this->assertNotContains('text/plain', $content);
63
        $map_b = $this->updater->createMapFromSourceFile(dirname(__FILE__) . '/../fixtures/min.mime-types.txt');
64
        $this->updater->applyOverrides($map_b, [['addMapping', ['bing/bong', 'binbon']]]);
0 ignored issues
show
Documentation introduced by
$map_b is of type string, but the function expects a object<FileEye\MimeMap\Map\AbstractMap>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
65
        $this->updater->writeMapToPhpClassFile($map_b, $map_a->getFileName());
0 ignored issues
show
Bug introduced by
The method getFileName cannot be called on $map_a (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Documentation introduced by
$map_b is of type string, but the function expects a object<FileEye\MimeMap\Map\AbstractMap>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
66
        $content = file_get_contents($map_a->getFileName());
0 ignored issues
show
Bug introduced by
The method getFileName cannot be called on $map_a (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
67
        $this->assertContains('text/plain', $content);
68
        $this->assertContains('bing/bong', $content);
69
        $this->assertContains('binbon', $content);
70
        $this->fileSystem->remove(__DIR__ . '/../../src/Map/MiniMap.php');
71
        $map_b->reset();
0 ignored issues
show
Bug introduced by
The method reset cannot be called on $map_b (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
72
    }
73
74
    public function testGetDefaultOverrideFile()
75
    {
76
        $this->assertContains('overrides.yml', MapUpdater::getDefaultOverrideFile());
77
    }
78
}
79