|
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); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
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
|
|
|
} |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
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.