forked from InfyOmLabs/laravel-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestHelpers.php
75 lines (56 loc) · 1.74 KB
/
TestHelpers.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
<?php
use Illuminate\Console\Command;
use InfyOm\Generator\Common\GeneratorConfig;
use Mockery as m;
function mockShouldHaveCalledGenerateMethod(array $shouldHaveCalledGenerators): array
{
$mockedObjects = [];
foreach ($shouldHaveCalledGenerators as $generator) {
$mock = m::mock($generator);
$mock->shouldReceive('generate')
->once()
->andReturn(true);
app()->singleton($generator, function () use ($mock) {
return $mock;
});
$mockedObjects[] = $mock;
}
return $mockedObjects;
}
function mockShouldNotHaveCalledGenerateMethod(array $shouldNotHaveCalledGenerator): array
{
$mockedObjects = [];
foreach ($shouldNotHaveCalledGenerator as $generator) {
$mock = m::mock($generator);
$mock->shouldNotReceive('generate');
app()->singleton($generator, function () use ($mock) {
return $mock;
});
$mockedObjects[] = $mock;
}
return $mockedObjects;
}
function fakeGeneratorConfig()
{
$fakeConfig = new GeneratorConfig();
$command = fakeGeneratorCommand();
$fakeConfig->setCommand($command);
$fakeConfig->init();
app()->singleton(GeneratorConfig::class, function () use ($fakeConfig) {
return $fakeConfig;
});
return $fakeConfig;
}
function fakeGeneratorCommand($options = [])
{
$mock = m::mock(Command::class);
$mock->shouldReceive('argument')->withArgs(['model'])->andReturn('FakeModel');
if (empty($options)) {
$mock->shouldReceive('option')->withAnyArgs()->andReturn('');
} else {
foreach ($options as $option => $value) {
$mock->shouldReceive('option')->withArgs([$option])->andReturn($value);
}
}
return $mock;
}