Skip to content

Upgrade to phpunit 11 #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ vendor/
.idea
/composer.lock
/.phpunit.result.cache
/.phpunit.cache
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require-dev": {
"phpunit/phpunit": "^9.0",
"phpunit/phpunit": "^11.5",
"squizlabs/php_codesniffer": "^3.2",
"phpstan/phpstan": "^1.2.0"
},
Expand Down
31 changes: 21 additions & 10 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
shortenArraysForExportThreshold="10"
beStrictAboutOutputDuringTests="true"
displayDetailsOnPhpunitDeprecations="true"
failOnPhpunitDeprecation="true"
failOnWarning="true">
<testsuites>
<testsuite name="default">
<directory>test</directory>
</testsuite>
</testsuites>

<phpunit colors="true">
<testsuite name="CLI Menu Test Suite">
<directory>./test</directory>
</testsuite>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion test/Action/GoBackActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testGoBackActionClosesMenuAndOpensParentIfMenuHasAParent() : voi
$menu
->expects($this->once())
->method('getParent')
->will($this->returnValue($parent));
->willReturn($parent);

$menu
->expects($this->once())
Expand Down
31 changes: 14 additions & 17 deletions test/Builder/CliMenuBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PhpSchool\CliMenu\MenuItem\StaticItem;
use PhpSchool\CliMenu\Style\DefaultStyle;
use PhpSchool\Terminal\Terminal;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -60,7 +61,7 @@ public function testModifyStyles() : void
$terminal
->expects($this->any())
->method('getWidth')
->will($this->returnValue(200));
->willReturn(200);

$builder = new CliMenuBuilder($terminal);
$builder->setBackgroundColour('red');
Expand Down Expand Up @@ -90,7 +91,7 @@ public function testSetBorderShorthandFunction() : void
$terminal
->expects($this->any())
->method('getWidth')
->will($this->returnValue(200));
->willReturn(200);

$style = (new CliMenuBuilder($terminal))
->setBorder(2)
Expand Down Expand Up @@ -641,7 +642,7 @@ public function testSubMenuInheritsParentsStyle() : void
$terminal
->expects($this->any())
->method('getWidth')
->will($this->returnValue(200));
->willReturn(200);

$menu = (new CliMenuBuilder($terminal))
->setBackgroundColour('green')
Expand Down Expand Up @@ -671,7 +672,7 @@ public function testSplitItemSubMenuInheritsParentsStyle() : void
$terminal
->expects($this->any())
->method('getWidth')
->will($this->returnValue(200));
->willReturn(200);

$menu = (new CliMenuBuilder($terminal))
->setBackgroundColour('green')
Expand Down Expand Up @@ -704,7 +705,7 @@ public function testSubMenuIgnoresParentsStyleIfCustomAndPassesToChildren() : vo
$terminal
->expects($this->any())
->method('getWidth')
->will($this->returnValue(200));
->willReturn(200);

$menu = (new CliMenuBuilder($terminal))
->setBackgroundColour('green')
Expand Down Expand Up @@ -809,9 +810,7 @@ public function testThrowsExceptionWhenDisablingRootMenu() : void
(new CliMenuBuilder)->disableMenu();
}

/**
* @dataProvider marginBelowZeroProvider
*/
#[DataProvider('marginBelowZeroProvider')]
public function testSetMarginThrowsExceptionIfValueIsNotZeroOrAbove(int $value) : void
{
self::expectException(\Assert\InvalidArgumentException::class);
Expand All @@ -820,28 +819,26 @@ public function testSetMarginThrowsExceptionIfValueIsNotZeroOrAbove(int $value)
(new CliMenuBuilder)->setMargin($value)->build();
}

public function marginBelowZeroProvider() : array
public static function marginBelowZeroProvider() : array
{
return [[-1], [-2], [-10]];
}

/**
* @dataProvider marginAboveZeroProvider
*/
#[DataProvider('marginAboveZeroProvider')]
public function testSetMarginAcceptsZeroAndPositiveIntegers(int $value) : void
{
$terminal = self::createMock(Terminal::class);
$terminal
->expects($this->any())
->method('getWidth')
->will($this->returnValue(200));
->willReturn(200);

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

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

public function marginAboveZeroProvider() : array
public static function marginAboveZeroProvider() : array
{
return [[0], [1], [10], [50]];
}
Expand All @@ -852,7 +849,7 @@ public function testSetMarginAutoAutomaticallyCalculatesMarginToCenter() : void
$terminal
->expects($this->any())
->method('getWidth')
->will($this->returnValue(200));
->willReturn(200);

$builder = new CliMenuBuilder($terminal);
$menu = $builder
Expand All @@ -869,7 +866,7 @@ public function testSetMarginAutoOverwritesSetMargin() : void
$terminal
->expects($this->any())
->method('getWidth')
->will($this->returnValue(200));
->willReturn(200);

$builder = new CliMenuBuilder($terminal);
$menu = $builder
Expand All @@ -887,7 +884,7 @@ public function testSetMarginManuallyOverwritesSetMarginAuto() : void
$terminal
->expects($this->any())
->method('getWidth')
->will($this->returnValue(200));
->willReturn(200);

$builder = new CliMenuBuilder($terminal);
$menu = $builder
Expand Down
10 changes: 5 additions & 5 deletions test/CliMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public function setUp() : void

$this->terminal->expects($this->any())
->method('write')
->will($this->returnCallback(function ($buffer) {
->willReturnCallback(function ($buffer) {
$this->output->write($buffer);
}));
});
}

public function testGetMenuStyle() : void
Expand Down Expand Up @@ -239,9 +239,9 @@ public function testRedrawClearsTerminalFirstIfOptionIsPassed() : void

$terminal->expects($this->any())
->method('write')
->will($this->returnCallback(function ($buffer) {
->willReturnCallback(function ($buffer) {
$this->output->write($buffer);
}));
});

$terminal->expects($this->exactly(3))
->method('read')
Expand Down Expand Up @@ -1044,7 +1044,7 @@ public function testGetItemByIndex() : void

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

private function getStyle(Terminal $terminal) : MenuStyle
Expand Down
38 changes: 19 additions & 19 deletions test/Dialogue/ConfirmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ public function setUp() : void

$this->terminal->expects($this->any())
->method('write')
->will($this->returnCallback(function ($buffer) {
->willReturnCallback(function ($buffer) {
$this->output->write($buffer);
}));
});
}

public function testConfirmWithOddLengthConfirmAndButton() : void
{
$this->terminal
->method('read')
->will($this->onConsecutiveCalls(
->willReturnOnConsecutiveCalls(
"\n",
"\n"
));
);

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

Expand All @@ -73,10 +73,10 @@ public function testConfirmWithEvenLengthConfirmAndButton() : void
{
$this->terminal
->method('read')
->will($this->onConsecutiveCalls(
->willReturnOnConsecutiveCalls(
"\n",
"\n"
));
);

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

Expand All @@ -97,10 +97,10 @@ public function testConfirmWithEvenLengthConfirmAndOddLengthButton() : void
{
$this->terminal
->method('read')
->will($this->onConsecutiveCalls(
->willReturnOnConsecutiveCalls(
"\n",
"\n"
));
);

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

Expand All @@ -121,10 +121,10 @@ public function testConfirmWithOddLengthConfirmAndEvenLengthButton() : void
{
$this->terminal
->method('read')
->will($this->onConsecutiveCalls(
->willReturnOnConsecutiveCalls(
"\n",
"\n"
));
);

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

Expand All @@ -145,10 +145,10 @@ public function testConfirmCancellableWithShortPrompt(): void
{
$this->terminal
->method('read')
->will($this->onConsecutiveCalls(
->willReturnOnConsecutiveCalls(
"\n",
"\n"
));
);

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

Expand All @@ -169,10 +169,10 @@ public function testConfirmCancellableWithLongPrompt(): void
{
$this->terminal
->method('read')
->will($this->onConsecutiveCalls(
->willReturnOnConsecutiveCalls(
"\n",
"\n"
));
);

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

Expand All @@ -193,12 +193,12 @@ public function testConfirmCanOnlyBeClosedWithEnter() : void
{
$this->terminal
->method('read')
->will($this->onConsecutiveCalls(
->willReturnOnConsecutiveCalls(
"\n",
'up',
'down',
"\n"
));
);

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

Expand All @@ -219,11 +219,11 @@ public function testConfirmOkNonCancellableReturnsTrue()
{
$this->terminal
->method('read')
->will($this->onConsecutiveCalls(
->willReturnOnConsecutiveCalls(
"\n",
'tab',
"\n"
));
);

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

Expand Down Expand Up @@ -290,7 +290,7 @@ public function testConfirmCancelCancellableReturnsFalse()

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

private function getStyle(Terminal $terminal) : MenuStyle
Expand Down
Loading