1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spinen\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Console\Kernel; |
6
|
|
|
use Illuminate\Support\Facades\File; |
7
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
8
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
9
|
|
|
use Spinen\Transformers\TestCase; |
10
|
|
|
|
11
|
|
|
class TransformerMakeCommandTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @test |
15
|
|
|
* @group unit |
16
|
|
|
*/ |
17
|
|
|
public function it_requires_a_name_for_the_transformer() |
18
|
|
|
{ |
19
|
|
|
$input = new ArrayInput([ |
20
|
|
|
'command' => 'make:transformer', |
21
|
|
|
]); |
22
|
|
|
$output = new BufferedOutput(); |
23
|
|
|
|
24
|
|
|
app(Kernel::class)->handle($input, $output); |
25
|
|
|
|
26
|
|
|
$this->assertContains('missing: "name"', $output->fetch()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @test |
31
|
|
|
* @group unit |
32
|
|
|
*/ |
33
|
|
|
public function it_builds_correct_transformer_file() |
34
|
|
|
{ |
35
|
|
|
$stub = app_path('Console/Commands/stubs/transformer.stub'); |
36
|
|
|
$path = app_path('Transformers/TestTransformer.php'); |
37
|
|
|
$content = <<<EOT |
38
|
|
|
<?php |
39
|
|
|
|
40
|
|
|
namespace App\Transformers; |
41
|
|
|
|
42
|
|
|
use App\Support\Transformation\Transformer; |
43
|
|
|
use Illuminate\Database\Eloquent\Model; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Class TestTransformer |
47
|
|
|
* |
48
|
|
|
* @package App\Transformers |
49
|
|
|
*/ |
50
|
|
|
class TestTransformer extends Transformer |
51
|
|
|
{ |
52
|
|
|
/** |
53
|
|
|
* @param Model \$model |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
public function transform(Model \$model) |
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
|
|
// TODO: Layout transformation here |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
EOT; |
66
|
|
|
// var_export('**********'); |
|
|
|
|
67
|
|
|
// var_export($content, false); |
68
|
|
|
// var_export('**********'); |
69
|
|
|
|
70
|
|
|
File::shouldReceive('get') |
71
|
|
|
->once() |
72
|
|
|
->with($stub) |
73
|
|
|
->andReturn(file_get_contents($stub)); |
74
|
|
|
|
75
|
|
|
File::shouldReceive('put') |
|
|
|
|
76
|
|
|
->once() |
77
|
|
|
->withArgs([ |
78
|
|
|
$path, |
79
|
|
|
$content, |
80
|
|
|
]) |
81
|
|
|
->andReturnNull(); |
82
|
|
|
|
83
|
|
|
File::shouldIgnoreMissing(); |
84
|
|
|
|
85
|
|
|
$input = new ArrayInput([ |
86
|
|
|
'command' => 'make:transformer', |
87
|
|
|
'name' => 'TestTransformer', |
88
|
|
|
]); |
89
|
|
|
$output = new BufferedOutput(); |
90
|
|
|
|
91
|
|
|
app(Kernel::class)->handle($input, $output); |
92
|
|
|
|
93
|
|
|
$this->assertContains('successfully', $output->fetch()); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.