Skip to content

Commit 797e923

Browse files
committed
Upgrade to phpunit 11
1 parent c4f9938 commit 797e923

18 files changed

+120
-157
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515
],
1616
"require-dev": {
17-
"phpunit/phpunit": "^9.0",
17+
"phpunit/phpunit": "^11.5",
1818
"squizlabs/php_codesniffer": "^3.2",
1919
"phpstan/phpstan": "^1.2.0"
2020
},

test/Action/GoBackActionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testGoBackActionClosesMenuAndOpensParentIfMenuHasAParent() : voi
2727
$menu
2828
->expects($this->once())
2929
->method('getParent')
30-
->will($this->returnValue($parent));
30+
->willReturn($parent);
3131

3232
$menu
3333
->expects($this->once())

test/Builder/CliMenuBuilderTest.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PhpSchool\CliMenu\MenuItem\StaticItem;
1717
use PhpSchool\CliMenu\Style\DefaultStyle;
1818
use PhpSchool\Terminal\Terminal;
19+
use PHPUnit\Framework\Attributes\DataProvider;
1920
use PHPUnit\Framework\TestCase;
2021

2122
/**
@@ -60,7 +61,7 @@ public function testModifyStyles() : void
6061
$terminal
6162
->expects($this->any())
6263
->method('getWidth')
63-
->will($this->returnValue(200));
64+
->willReturn(200);
6465

6566
$builder = new CliMenuBuilder($terminal);
6667
$builder->setBackgroundColour('red');
@@ -90,7 +91,7 @@ public function testSetBorderShorthandFunction() : void
9091
$terminal
9192
->expects($this->any())
9293
->method('getWidth')
93-
->will($this->returnValue(200));
94+
->willReturn(200);
9495

9596
$style = (new CliMenuBuilder($terminal))
9697
->setBorder(2)
@@ -641,7 +642,7 @@ public function testSubMenuInheritsParentsStyle() : void
641642
$terminal
642643
->expects($this->any())
643644
->method('getWidth')
644-
->will($this->returnValue(200));
645+
->willReturn(200);
645646

646647
$menu = (new CliMenuBuilder($terminal))
647648
->setBackgroundColour('green')
@@ -671,7 +672,7 @@ public function testSplitItemSubMenuInheritsParentsStyle() : void
671672
$terminal
672673
->expects($this->any())
673674
->method('getWidth')
674-
->will($this->returnValue(200));
675+
->willReturn(200);
675676

676677
$menu = (new CliMenuBuilder($terminal))
677678
->setBackgroundColour('green')
@@ -704,7 +705,7 @@ public function testSubMenuIgnoresParentsStyleIfCustomAndPassesToChildren() : vo
704705
$terminal
705706
->expects($this->any())
706707
->method('getWidth')
707-
->will($this->returnValue(200));
708+
->willReturn(200);
708709

709710
$menu = (new CliMenuBuilder($terminal))
710711
->setBackgroundColour('green')
@@ -809,9 +810,7 @@ public function testThrowsExceptionWhenDisablingRootMenu() : void
809810
(new CliMenuBuilder)->disableMenu();
810811
}
811812

812-
/**
813-
* @dataProvider marginBelowZeroProvider
814-
*/
813+
#[DataProvider('marginBelowZeroProvider')]
815814
public function testSetMarginThrowsExceptionIfValueIsNotZeroOrAbove(int $value) : void
816815
{
817816
self::expectException(\Assert\InvalidArgumentException::class);
@@ -820,28 +819,26 @@ public function testSetMarginThrowsExceptionIfValueIsNotZeroOrAbove(int $value)
820819
(new CliMenuBuilder)->setMargin($value)->build();
821820
}
822821

823-
public function marginBelowZeroProvider() : array
822+
public static function marginBelowZeroProvider() : array
824823
{
825824
return [[-1], [-2], [-10]];
826825
}
827826

828-
/**
829-
* @dataProvider marginAboveZeroProvider
830-
*/
827+
#[DataProvider('marginAboveZeroProvider')]
831828
public function testSetMarginAcceptsZeroAndPositiveIntegers(int $value) : void
832829
{
833830
$terminal = self::createMock(Terminal::class);
834831
$terminal
835832
->expects($this->any())
836833
->method('getWidth')
837-
->will($this->returnValue(200));
834+
->willReturn(200);
838835

839836
$menu = (new CliMenuBuilder($terminal))->setMargin($value)->build();
840837

841838
self::assertSame($value, $menu->getStyle()->getMargin());
842839
}
843840

844-
public function marginAboveZeroProvider() : array
841+
public static function marginAboveZeroProvider() : array
845842
{
846843
return [[0], [1], [10], [50]];
847844
}
@@ -852,7 +849,7 @@ public function testSetMarginAutoAutomaticallyCalculatesMarginToCenter() : void
852849
$terminal
853850
->expects($this->any())
854851
->method('getWidth')
855-
->will($this->returnValue(200));
852+
->willReturn(200);
856853

857854
$builder = new CliMenuBuilder($terminal);
858855
$menu = $builder
@@ -869,7 +866,7 @@ public function testSetMarginAutoOverwritesSetMargin() : void
869866
$terminal
870867
->expects($this->any())
871868
->method('getWidth')
872-
->will($this->returnValue(200));
869+
->willReturn(200);
873870

874871
$builder = new CliMenuBuilder($terminal);
875872
$menu = $builder
@@ -887,7 +884,7 @@ public function testSetMarginManuallyOverwritesSetMarginAuto() : void
887884
$terminal
888885
->expects($this->any())
889886
->method('getWidth')
890-
->will($this->returnValue(200));
887+
->willReturn(200);
891888

892889
$builder = new CliMenuBuilder($terminal);
893890
$menu = $builder

test/CliMenuTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public function setUp() : void
4545

4646
$this->terminal->expects($this->any())
4747
->method('write')
48-
->will($this->returnCallback(function ($buffer) {
48+
->willReturnCallback(function ($buffer) {
4949
$this->output->write($buffer);
50-
}));
50+
});
5151
}
5252

5353
public function testGetMenuStyle() : void
@@ -239,9 +239,9 @@ public function testRedrawClearsTerminalFirstIfOptionIsPassed() : void
239239

240240
$terminal->expects($this->any())
241241
->method('write')
242-
->will($this->returnCallback(function ($buffer) {
242+
->willReturnCallback(function ($buffer) {
243243
$this->output->write($buffer);
244-
}));
244+
});
245245

246246
$terminal->expects($this->exactly(3))
247247
->method('read')
@@ -1044,7 +1044,7 @@ public function testGetItemByIndex() : void
10441044

10451045
private function getTestFile() : string
10461046
{
1047-
return sprintf('%s/res/%s.txt', __DIR__, $this->getName());
1047+
return sprintf('%s/res/%s.txt', __DIR__, $this->name());
10481048
}
10491049

10501050
private function getStyle(Terminal $terminal) : MenuStyle

test/Dialogue/ConfirmTest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ public function setUp() : void
4040

4141
$this->terminal->expects($this->any())
4242
->method('write')
43-
->will($this->returnCallback(function ($buffer) {
43+
->willReturnCallback(function ($buffer) {
4444
$this->output->write($buffer);
45-
}));
45+
});
4646
}
4747

4848
public function testConfirmWithOddLengthConfirmAndButton() : void
4949
{
5050
$this->terminal
5151
->method('read')
52-
->will($this->onConsecutiveCalls(
52+
->willReturnOnConsecutiveCalls(
5353
"\n",
5454
"\n"
55-
));
55+
);
5656

5757
$style = $this->getStyle($this->terminal);
5858

@@ -73,10 +73,10 @@ public function testConfirmWithEvenLengthConfirmAndButton() : void
7373
{
7474
$this->terminal
7575
->method('read')
76-
->will($this->onConsecutiveCalls(
76+
->willReturnOnConsecutiveCalls(
7777
"\n",
7878
"\n"
79-
));
79+
);
8080

8181
$style = $this->getStyle($this->terminal);
8282

@@ -97,10 +97,10 @@ public function testConfirmWithEvenLengthConfirmAndOddLengthButton() : void
9797
{
9898
$this->terminal
9999
->method('read')
100-
->will($this->onConsecutiveCalls(
100+
->willReturnOnConsecutiveCalls(
101101
"\n",
102102
"\n"
103-
));
103+
);
104104

105105
$style = $this->getStyle($this->terminal);
106106

@@ -121,10 +121,10 @@ public function testConfirmWithOddLengthConfirmAndEvenLengthButton() : void
121121
{
122122
$this->terminal
123123
->method('read')
124-
->will($this->onConsecutiveCalls(
124+
->willReturnOnConsecutiveCalls(
125125
"\n",
126126
"\n"
127-
));
127+
);
128128

129129
$style = $this->getStyle($this->terminal);
130130

@@ -145,10 +145,10 @@ public function testConfirmCancellableWithShortPrompt(): void
145145
{
146146
$this->terminal
147147
->method('read')
148-
->will($this->onConsecutiveCalls(
148+
->willReturnOnConsecutiveCalls(
149149
"\n",
150150
"\n"
151-
));
151+
);
152152

153153
$style = $this->getStyle($this->terminal);
154154

@@ -169,10 +169,10 @@ public function testConfirmCancellableWithLongPrompt(): void
169169
{
170170
$this->terminal
171171
->method('read')
172-
->will($this->onConsecutiveCalls(
172+
->willReturnOnConsecutiveCalls(
173173
"\n",
174174
"\n"
175-
));
175+
);
176176

177177
$style = $this->getStyle($this->terminal);
178178

@@ -193,12 +193,12 @@ public function testConfirmCanOnlyBeClosedWithEnter() : void
193193
{
194194
$this->terminal
195195
->method('read')
196-
->will($this->onConsecutiveCalls(
196+
->willReturnOnConsecutiveCalls(
197197
"\n",
198198
'up',
199199
'down',
200200
"\n"
201-
));
201+
);
202202

203203
$style = $this->getStyle($this->terminal);
204204

@@ -219,11 +219,11 @@ public function testConfirmOkNonCancellableReturnsTrue()
219219
{
220220
$this->terminal
221221
->method('read')
222-
->will($this->onConsecutiveCalls(
222+
->willReturnOnConsecutiveCalls(
223223
"\n",
224224
'tab',
225225
"\n"
226-
));
226+
);
227227

228228
$style = $this->getStyle($this->terminal);
229229

@@ -290,7 +290,7 @@ public function testConfirmCancelCancellableReturnsFalse()
290290

291291
private function getTestFile() : string
292292
{
293-
return sprintf('%s/../res/%s.txt', __DIR__, $this->getName());
293+
return sprintf('%s/../res/%s.txt', __DIR__, $this->name());
294294
}
295295

296296
private function getStyle(Terminal $terminal) : MenuStyle

test/Dialogue/FlashTest.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpSchool\CliMenu\MenuStyle;
99
use PhpSchool\Terminal\IO\BufferedOutput;
1010
use PhpSchool\Terminal\Terminal;
11+
use PHPUnit\Framework\Attributes\DataProvider;
1112
use PHPUnit\Framework\TestCase;
1213

1314
/**
@@ -40,19 +41,19 @@ public function setUp() : void
4041

4142
$this->terminal->expects($this->any())
4243
->method('write')
43-
->will($this->returnCallback(function ($buffer) {
44+
->willReturnCallback(function ($buffer) {
4445
$this->output->write($buffer);
45-
}));
46+
});
4647
}
4748

4849
public function testFlashWithOddLength() : void
4950
{
5051
$this->terminal
5152
->method('read')
52-
->will($this->onConsecutiveCalls(
53+
->willReturnOnConsecutiveCalls(
5354
"\n",
5455
"\n"
55-
));
56+
);
5657

5758
$style = $this->getStyle($this->terminal);
5859

@@ -73,10 +74,10 @@ public function testFlashWithEvenLength() : void
7374
{
7475
$this->terminal
7576
->method('read')
76-
->will($this->onConsecutiveCalls(
77+
->willReturnOnConsecutiveCalls(
7778
"\n",
7879
"\n"
79-
));
80+
);
8081

8182
$style = $this->getStyle($this->terminal);
8283

@@ -93,14 +94,12 @@ public function testFlashWithEvenLength() : void
9394
static::assertStringEqualsFile($this->getTestFile(), $this->output->fetch());
9495
}
9596

96-
/**
97-
* @dataProvider keyProvider
98-
*/
97+
#[DataProvider('keyProvider')]
9998
public function testFlashCanBeClosedWithAnyKey(string $key) : void
10099
{
101100
$this->terminal
102101
->method('read')
103-
->will($this->onConsecutiveCalls("\n", $key));
102+
->willReturnOnConsecutiveCalls("\n", $key);
104103

105104
$style = $this->getStyle($this->terminal);
106105

@@ -117,7 +116,7 @@ public function testFlashCanBeClosedWithAnyKey(string $key) : void
117116
static::assertStringEqualsFile($this->getTestFile(), $this->output->fetch());
118117
}
119118

120-
public function keyProvider() : array
119+
public static function keyProvider() : array
121120
{
122121
return [
123122
["\n"],
@@ -129,7 +128,7 @@ public function keyProvider() : array
129128

130129
private function getTestFile() : string
131130
{
132-
return sprintf('%s/../res/%s.txt', __DIR__, $this->getName(false));
131+
return sprintf('%s/../res/%s.txt', __DIR__, $this->name());
133132
}
134133

135134
private function getStyle(Terminal $terminal) : MenuStyle

0 commit comments

Comments
 (0)