This repository was archived by the owner on Apr 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransformerMakeCommandTest.php
95 lines (79 loc) · 2.1 KB
/
TransformerMakeCommandTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace Spinen\Commands;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\Facades\File;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Spinen\Transformers\TestCase;
class TransformerMakeCommandTest extends TestCase
{
/**
* @test
* @group unit
*/
public function it_requires_a_name_for_the_transformer()
{
$input = new ArrayInput([
'command' => 'make:transformer',
]);
$output = new BufferedOutput();
app(Kernel::class)->handle($input, $output);
$this->assertContains('missing: "name"', $output->fetch());
}
/**
* @test
* @group unit
*/
public function it_builds_correct_transformer_file()
{
$stub = app_path('Console/Commands/stubs/transformer.stub');
$path = app_path('Transformers/TestTransformer.php');
$content = <<<EOT
<?php
namespace App\Transformers;
use App\Support\Transformation\Transformer;
use Illuminate\Database\Eloquent\Model;
/**
* Class TestTransformer
*
* @package App\Transformers
*/
class TestTransformer extends Transformer
{
/**
* @param Model \$model
*
* @return array
*/
public function transform(Model \$model)
{
return [
// TODO: Layout transformation here
];
}
}
EOT;
// var_export('**********');
// var_export($content, false);
// var_export('**********');
File::shouldReceive('get')
->once()
->with($stub)
->andReturn(file_get_contents($stub));
File::shouldReceive('put')
->once()
->withArgs([
$path,
$content,
])
->andReturnNull();
File::shouldIgnoreMissing();
$input = new ArrayInput([
'command' => 'make:transformer',
'name' => 'TestTransformer',
]);
$output = new BufferedOutput();
app(Kernel::class)->handle($input, $output);
$this->assertContains('successfully', $output->fetch());
}
}