Skip to content

Commit 01c02a9

Browse files
Merge pull request #159 from wavenet-be/master
update synfony console
2 parents 7563ddc + 4a2721b commit 01c02a9

File tree

4 files changed

+70
-34
lines changed

4 files changed

+70
-34
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
}],
1919
"require": {
2020
"php": "^7.2 || ^8.0",
21-
"symfony/console": "^4.0||^5.0||^6.0",
21+
"symfony/console": "^6.0||^7.0",
2222
"symfony/config": "^4.0||^5.0||^6.0"
2323
},
2424
"require-dev": {

src/Phpmig/Console/Command/InitCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function configure()
4343
/**
4444
* {@inheritdoc}
4545
*/
46-
protected function execute(InputInterface $input, OutputInterface $output)
46+
protected function execute(InputInterface $input, OutputInterface $output): int
4747
{
4848
$cwd = getcwd();
4949
$bootstrap = $cwd . DIRECTORY_SEPARATOR . 'phpmig.php';

src/Phpmig/Migration/Migration.php

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
*/
66
namespace Phpmig\Migration;
77

8+
use Symfony\Component\Console\Input\InputInterface;
89
use Symfony\Component\Console\Output\OutputInterface;
9-
use Symfony\Component\Console\Helper\DialogHelper;
10+
use Symfony\Component\Console\Helper\QuestionHelper;
11+
use Symfony\Component\Console\Question\Question;
1012

1113
/**
1214
* This file is part of phpmig
@@ -42,7 +44,12 @@ class Migration
4244
protected $output = null;
4345

4446
/**
45-
* @var DialogHelper
47+
* @var InputInterface
48+
*/
49+
protected $input = null;
50+
51+
/**
52+
* @var QuestionHelper
4653
*/
4754
protected $dialogHelper = null;
4855

@@ -91,7 +98,7 @@ public function down()
9198
*
9299
* @return int
93100
*/
94-
public function getVersion()
101+
public function getVersion(): ?int
95102
{
96103
return $this->version;
97104
}
@@ -102,7 +109,7 @@ public function getVersion()
102109
* @param int $version
103110
* @return Migration
104111
*/
105-
public function setVersion($version)
112+
public function setVersion(int $version): Migration
106113
{
107114
$this->version = $version;
108115
return $this;
@@ -113,7 +120,7 @@ public function setVersion($version)
113120
*
114121
* @return string
115122
*/
116-
public function getName()
123+
public function getName(): string
117124
{
118125
return get_class($this);
119126
}
@@ -123,7 +130,7 @@ public function getName()
123130
*
124131
* @return \ArrayAccess
125132
*/
126-
public function getContainer()
133+
public function getContainer(): ?\ArrayAccess
127134
{
128135
return $this->container;
129136
}
@@ -132,9 +139,9 @@ public function getContainer()
132139
* Set Container
133140
*
134141
* @param \ArrayAccess $container
135-
* @return Migrator
142+
* @return Migration
136143
*/
137-
public function setContainer(\ArrayAccess $container)
144+
public function setContainer(\ArrayAccess $container): Migration
138145
{
139146
$this->container = $container;
140147
return $this;
@@ -145,45 +152,65 @@ public function setContainer(\ArrayAccess $container)
145152
*
146153
* @return OutputInterface
147154
*/
148-
public function getOutput()
155+
public function getOutput(): ?OutputInterface
149156
{
150157
return $this->output;
151158
}
152159

160+
/**
161+
* Get Input
162+
*
163+
* @return InputInterface
164+
*/
165+
public function getInput(): ?InputInterface
166+
{
167+
return $this->input;
168+
}
169+
153170
/**
154171
* Set Output
155172
*
156173
* @param OutputInterface $output
157-
* @return Migrator
174+
* @return Migration
158175
*/
159-
public function setOutput(OutputInterface $output)
176+
public function setOutput(OutputInterface $output): Migration
160177
{
161178
$this->output = $output;
162179
return $this;
163180
}
164181

182+
/**
183+
* Set Input
184+
*
185+
* @param InputInterface $input
186+
* @return Migration
187+
*/
188+
public function setInput(InputInterface $input): Migration
189+
{
190+
$this->input = $input;
191+
return $this;
192+
}
193+
165194
/**
166195
* Ask for input
167196
*
168-
* @param string $question
169-
* @param mixed $default
197+
* @param Question $question
170198
* @return string The users answer
171199
*/
172-
public function ask($question, $default = null)
200+
public function ask(Question $question): string
173201
{
174-
return $this->getDialogHelper()->ask($this->getOutput(), $question, $default);
202+
return $this->getDialogHelper()->ask($this->getInput(), $this->getOutput(), $question);
175203
}
176204

177205
/**
178206
* Ask for confirmation
179207
*
180-
* @param string $question
181-
* @param mixed $default
208+
* @param Question $question
182209
* @return string The users answer
183210
*/
184-
public function confirm($question, $default = true)
211+
public function confirm(Question $question): string
185212
{
186-
return $this->getDialogHelper()->askConfirmation($this->getOutput(), $question, $default);
213+
return $this->getDialogHelper()->ask($this->getInput(), $this->getOutput(), $question);
187214
}
188215

189216
/**
@@ -201,24 +228,24 @@ public function get($key)
201228
/**
202229
* Get Dialog Helper
203230
*
204-
* @return DialogHelper
231+
* @return QuestionHelper
205232
*/
206-
public function getDialogHelper()
233+
public function getDialogHelper(): ?QuestionHelper
207234
{
208235
if ($this->dialogHelper) {
209236
return $this->dialogHelper;
210237
}
211238

212-
return $this->dialogHelper = new DialogHelper();
239+
return $this->dialogHelper = new QuestionHelper();
213240
}
214241

215242
/**
216243
* Set Dialog Helper
217244
*
218-
* @param DialogHelper $dialogHelper
245+
* @param QuestionHelper $dialogHelper
219246
* @return Migration
220247
*/
221-
public function setDialogHelper(DialogHelper $dialogHelper)
248+
public function setDialogHelper(QuestionHelper $dialogHelper): Migration
222249
{
223250
$this->dialogHelper = $dialogHelper;
224251
return $this;

tests/Phpmig/Migration/MigrationTest.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
use Mockery as m;
66
use PHPUnit\Framework\TestCase;
7-
use Symfony\Component\Console\Helper\DialogHelper;
7+
use Symfony\Component\Console\Helper\QuestionHelper;
88
use Symfony\Component\Console\Output\OutputInterface;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Question\Question;
911

1012
class MigrationTest extends TestCase
1113
{
@@ -15,7 +17,12 @@ class MigrationTest extends TestCase
1517
private $migrationOutput;
1618

1719
/**
18-
* @var DialogHelper|m\MockInterface
20+
* @var InputInterface|m\MockInterface
21+
*/
22+
private $migrationInput;
23+
24+
/**
25+
* @var QuestionHelper|m\MockInterface
1926
*/
2027
private $migrationDialogHelper;
2128

@@ -27,10 +34,12 @@ class MigrationTest extends TestCase
2734
public function setUp(): void
2835
{
2936
$this->migrationOutput = m::mock('Symfony\Component\Console\Output\OutputInterface')->shouldIgnoreMissing();
30-
$this->migrationDialogHelper = m::mock('Symfony\Component\Console\Helper\DialogHelper')->shouldIgnoreMissing();
37+
$this->migrationInput = m::mock('Symfony\Component\Console\Input\InputInterface')->shouldIgnoreMissing();
38+
$this->migrationDialogHelper = m::mock('Symfony\Component\Console\Helper\QuestionHelper')->shouldIgnoreMissing();
3139

3240
$this->migration = new Migration(1);
3341
$this->migration->setOutput($this->migrationOutput);
42+
$this->migration->setInput($this->migrationInput);
3443
$this->migration->setDialogHelper($this->migrationDialogHelper);
3544
}
3645

@@ -40,24 +49,24 @@ public function setUp(): void
4049
public function shouldAskForInput()
4150
{
4251
$this->migrationDialogHelper->shouldReceive('ask')
43-
->with($this->migrationOutput, $question = 'Wat?', $default = 'huh?')
52+
->with($this->migrationInput, $this->migrationOutput, $question = new Question('Wat?','huh?'))
4453
->andReturn($ans = 'dave')
4554
->once();
4655

47-
$this->assertEquals($ans, $this->migration->ask($question, $default));
56+
$this->assertEquals($ans, $this->migration->ask($question));
4857
}
4958

5059
/**
5160
* @test
5261
*/
5362
public function shouldAskForConfirmation()
5463
{
55-
$this->migrationDialogHelper->shouldReceive('askConfirmation')
56-
->with($this->migrationOutput, $question = 'Wat?', $default = true)
64+
$this->migrationDialogHelper->shouldReceive('ask')
65+
->with($this->migrationInput, $this->migrationOutput, $question = new Question('Wat?',true))
5766
->andReturn($ans = 'dave')
5867
->once();
5968

60-
$this->assertEquals($ans, $this->migration->confirm($question, $default));
69+
$this->assertEquals($ans, $this->migration->confirm($question));
6170
}
6271

6372
/**

0 commit comments

Comments
 (0)