|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the phpspec-behavior package. |
|
4
|
|
|
* (c) 2017 Timo Michna <timomichna/yahoo.de> |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace features\Behavior\Console; |
|
11
|
|
|
|
|
12
|
|
|
use PhpSpec\Locator\ResourceManager; |
|
13
|
|
|
use PhpSpec\Locator\Resource; |
|
14
|
|
|
use PhpSpec\CodeGenerator\GeneratorManager; |
|
15
|
|
|
use PhpSpec\ServiceContainer; |
|
16
|
|
|
|
|
17
|
|
|
use Tidal\PhpSpec\ConsoleExtension\Writer; |
|
18
|
|
|
use Tidal\PhpSpec\ConsoleExtension\Command\InlineConfigurator as Configurator; |
|
19
|
|
|
use spec\Tidal\PhpSpec\ConsoleExtension\Behavior\Prophecy\HasWriterMockTrait; |
|
20
|
|
|
|
|
21
|
|
|
use Prophecy\Prophet; |
|
22
|
|
|
use Prophecy\Argument; |
|
23
|
|
|
use Prophecy\Prophecy\ProphecyInterface; |
|
24
|
|
|
|
|
25
|
|
|
use Tidal\PhpSpec\BehaviorExtension\Console\Command\ImplementCommand; |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
trait CommandDependencyMockTrait |
|
29
|
|
|
{ |
|
30
|
|
|
use HasWriterMockTrait; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var ProphecyInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $writerProphecy; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var Writer |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $writer; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @return ImplementCommand |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function getPhpspecBehaviorImplementCommand(): ImplementCommand |
|
46
|
|
|
{ |
|
47
|
|
|
$command = new ImplementCommand( |
|
48
|
|
|
$this |
|
49
|
|
|
->getWriter(), |
|
50
|
|
|
new Configurator(), |
|
51
|
|
|
[] |
|
52
|
|
|
); |
|
53
|
|
|
$command->setContainer( |
|
54
|
|
|
$this |
|
55
|
|
|
->createContainerProphecy() |
|
56
|
|
|
->reveal() |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
return $command; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return ProphecyInterface |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function getWriterProphecy(): ProphecyInterface |
|
66
|
|
|
{ |
|
67
|
|
|
if (!isset($this->writerProphecy)) { |
|
68
|
|
|
$this->writerProphecy = $this->createWriterProphecy(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return isset($this->writerProphecy) |
|
72
|
|
|
? $this->writerProphecy |
|
73
|
|
|
: $this->writerProphecy = $this->createWriterProphecy(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return object|Writer |
|
78
|
|
|
*/ |
|
79
|
|
|
protected function getWriter(): Writer |
|
80
|
|
|
{ |
|
81
|
|
|
return isset($this->writer) |
|
82
|
|
|
? $this->writer |
|
83
|
|
|
: $this->writer = $this->getWriterProphecy()->reveal(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return ProphecyInterface |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function createGeneratorManagerProphecy(): ProphecyInterface |
|
90
|
|
|
{ |
|
91
|
|
|
$prophecy = (new Prophet) |
|
92
|
|
|
->prophesize(); |
|
93
|
|
|
$prophecy |
|
94
|
|
|
->willExtend( |
|
95
|
|
|
GeneratorManager::class |
|
96
|
|
|
) |
|
97
|
|
|
->generate( |
|
98
|
|
|
Argument::any(), |
|
99
|
|
|
Argument::any(), |
|
100
|
|
|
Argument::any() |
|
101
|
|
|
) |
|
102
|
|
|
->willReturn( |
|
103
|
|
|
$this->createResourceProphecy() |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
|
|
return $prophecy; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @return ProphecyInterface |
|
111
|
|
|
*/ |
|
112
|
|
|
protected function createContainerProphecy(): ProphecyInterface |
|
113
|
|
|
{ |
|
114
|
|
|
$prophecy = (new Prophet) |
|
115
|
|
|
->prophesize() |
|
116
|
|
|
->willImplement( |
|
117
|
|
|
ServiceContainer::class |
|
118
|
|
|
); |
|
119
|
|
|
$prophecy |
|
120
|
|
|
->get( |
|
121
|
|
|
'code_generator' |
|
122
|
|
|
) |
|
123
|
|
|
->willReturn( |
|
124
|
|
|
$this->createGeneratorManagerProphecy()->reveal() |
|
125
|
|
|
); |
|
126
|
|
|
$prophecy |
|
127
|
|
|
->get( |
|
128
|
|
|
'locator.resource_manager' |
|
129
|
|
|
) |
|
130
|
|
|
->willReturn( |
|
131
|
|
|
$this->createResourceManagerProphecy()->reveal() |
|
132
|
|
|
); |
|
133
|
|
|
|
|
134
|
|
|
return $prophecy; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @return ProphecyInterface |
|
139
|
|
|
*/ |
|
140
|
|
|
protected function createResourceManagerProphecy(): ProphecyInterface |
|
141
|
|
|
{ |
|
142
|
|
|
$prophecy = (new Prophet) |
|
143
|
|
|
->prophesize(); |
|
144
|
|
|
$prophecy |
|
145
|
|
|
->willImplement(ResourceManager::class) |
|
146
|
|
|
->createResource( |
|
147
|
|
|
Argument::type('string') |
|
148
|
|
|
) |
|
149
|
|
|
->willReturn( |
|
150
|
|
|
$this->createResourceProphecy()->reveal() |
|
151
|
|
|
); |
|
152
|
|
|
|
|
153
|
|
|
return $prophecy; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @return ProphecyInterface |
|
158
|
|
|
*/ |
|
159
|
|
|
protected function createResourceProphecy(): ProphecyInterface |
|
160
|
|
|
{ |
|
161
|
|
|
return (new Prophet) |
|
162
|
|
|
->prophesize() |
|
163
|
|
|
->willImplement( |
|
164
|
|
|
Resource::class |
|
165
|
|
|
); |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
|