FilenameParserTestCase   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 58
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A assertFileName() 0 4 1
A testParseFilenameWithFolders() 0 12 1
A testParseFilenameWithoutFolder() 0 10 1
A assertFolderName() 0 4 1
1
<?php
2
3
namespace Maestriam\Samurai\Tests\Unit\Foundation\FilenameParser;
4
5
use Maestriam\Samurai\Tests\TestCase;
6
use Maestriam\Samurai\Foundation\FilenameParser;
7
use stdClass;
8
9
class FilenameParserTestCase extends TestCase
10
{
11
    /**
12
     * Verifica se consegue recuperar o nome do arquivo e seu diretório,
13
     * dado um caminho contendo o nome do arquivo e seus sub-diretórios
14
     *
15
     * @bug O parser somente identificar caminhos com "/". 
16
     * Caso colocarmos, \ ele não consegue interpretar
17
     * 
18
     * @bug Quando retorna a string da pasta não está colocando a / no final.
19
     * Ex. 
20
     * Errado: diretorio/diretorio. 
21
     * Certo: diretorio/diretorio/
22
     * 
23
     * @return void
24
     */
25
    public function testParseFilenameWithFolders()
26
    {
27
        $folder = 'table/includes/';
28
        $name   = 'table-include.blade.php';
29
        $file   = $folder . $name;
30
        
31
        $parser = new FilenameParser();
32
        $info   = $parser->filename($file);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $info is correct as $parser->filename($file) targeting Maestriam\Samurai\Founda...enameParser::filename() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
33
        
34
        $this->assertInstanceOf(stdClass::class, $info);
35
        $this->assertFileName($info, $name);
36
        $this->assertFolderName($info, 'table\\includes'); //bug
37
    }
38
39
    /**
40
     * Verifica se consegue recuperar apenas o nome do arquivo,
41
     * dado um caminho contendo o apenas nome do arquivo
42
     *
43
     * @return void
44
     */
45
    public function testParseFilenameWithoutFolder()
46
    {
47
        $file = 'table-include.blade.php';
48
49
        $parser = new FilenameParser();
50
        $info   = $parser->filename($file);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $info is correct as $parser->filename($file) targeting Maestriam\Samurai\Founda...enameParser::filename() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
51
52
        $this->assertInstanceOf(stdClass::class, $info);
53
        $this->assertFileName($info, $file);
54
        $this->assertFolderName($info, '');
55
    }
56
57
    protected function assertFileName($info, string $name)
58
    {        
59
        $this->assertObjectHasAttribute('name', $info);
60
        $this->assertEquals($info->name, $name);
61
    }
62
    
63
    protected function assertFolderName($info, string $folder)
64
    {
65
        $this->assertObjectHasAttribute('folder', $info);
66
        $this->assertEquals($info->folder, $folder); 
67
    }
68
}