From 797e9235d149df777d0909a71837d11376179713 Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Tue, 29 Jul 2025 17:12:29 +0200 Subject: [PATCH 1/2] Upgrade to phpunit 11 --- composer.json | 2 +- test/Action/GoBackActionTest.php | 2 +- test/Builder/CliMenuBuilderTest.php | 31 +++++++++----------- test/CliMenuTest.php | 10 +++---- test/Dialogue/ConfirmTest.php | 38 ++++++++++++------------ test/Dialogue/FlashTest.php | 23 +++++++-------- test/Input/NumberTest.php | 7 ++--- test/Input/PasswordTest.php | 13 ++++----- test/Input/TextTest.php | 7 ++--- test/MenuItem/AsciiArtItemTest.php | 20 ++++++------- test/MenuItem/LineBreakItemTest.php | 10 +++---- test/MenuItem/MenuMenuItemTest.php | 2 +- test/MenuItem/SelectableItemTest.php | 4 +-- test/MenuItem/SplitItemTest.php | 43 +++++++++++----------------- test/MenuItem/StaticItemTest.php | 6 ++-- test/MenuStyleTest.php | 33 +++++++-------------- test/Style/LocatorTest.php | 13 ++++----- test/Util/ColourUtilTest.php | 13 ++++----- 18 files changed, 120 insertions(+), 157 deletions(-) diff --git a/composer.json b/composer.json index 89606a0b..fc604e2e 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require-dev": { - "phpunit/phpunit": "^9.0", + "phpunit/phpunit": "^11.5", "squizlabs/php_codesniffer": "^3.2", "phpstan/phpstan": "^1.2.0" }, diff --git a/test/Action/GoBackActionTest.php b/test/Action/GoBackActionTest.php index b18e3cdf..0a085442 100644 --- a/test/Action/GoBackActionTest.php +++ b/test/Action/GoBackActionTest.php @@ -27,7 +27,7 @@ public function testGoBackActionClosesMenuAndOpensParentIfMenuHasAParent() : voi $menu ->expects($this->once()) ->method('getParent') - ->will($this->returnValue($parent)); + ->willReturn($parent); $menu ->expects($this->once()) diff --git a/test/Builder/CliMenuBuilderTest.php b/test/Builder/CliMenuBuilderTest.php index 046e0637..ed8170b2 100644 --- a/test/Builder/CliMenuBuilderTest.php +++ b/test/Builder/CliMenuBuilderTest.php @@ -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; /** @@ -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'); @@ -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) @@ -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') @@ -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') @@ -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') @@ -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); @@ -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]]; } @@ -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 @@ -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 @@ -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 diff --git a/test/CliMenuTest.php b/test/CliMenuTest.php index 11b861be..619f11ac 100644 --- a/test/CliMenuTest.php +++ b/test/CliMenuTest.php @@ -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 @@ -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') @@ -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 diff --git a/test/Dialogue/ConfirmTest.php b/test/Dialogue/ConfirmTest.php index 3765d14e..8ba7aa8b 100644 --- a/test/Dialogue/ConfirmTest.php +++ b/test/Dialogue/ConfirmTest.php @@ -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); @@ -73,10 +73,10 @@ public function testConfirmWithEvenLengthConfirmAndButton() : void { $this->terminal ->method('read') - ->will($this->onConsecutiveCalls( + ->willReturnOnConsecutiveCalls( "\n", "\n" - )); + ); $style = $this->getStyle($this->terminal); @@ -97,10 +97,10 @@ public function testConfirmWithEvenLengthConfirmAndOddLengthButton() : void { $this->terminal ->method('read') - ->will($this->onConsecutiveCalls( + ->willReturnOnConsecutiveCalls( "\n", "\n" - )); + ); $style = $this->getStyle($this->terminal); @@ -121,10 +121,10 @@ public function testConfirmWithOddLengthConfirmAndEvenLengthButton() : void { $this->terminal ->method('read') - ->will($this->onConsecutiveCalls( + ->willReturnOnConsecutiveCalls( "\n", "\n" - )); + ); $style = $this->getStyle($this->terminal); @@ -145,10 +145,10 @@ public function testConfirmCancellableWithShortPrompt(): void { $this->terminal ->method('read') - ->will($this->onConsecutiveCalls( + ->willReturnOnConsecutiveCalls( "\n", "\n" - )); + ); $style = $this->getStyle($this->terminal); @@ -169,10 +169,10 @@ public function testConfirmCancellableWithLongPrompt(): void { $this->terminal ->method('read') - ->will($this->onConsecutiveCalls( + ->willReturnOnConsecutiveCalls( "\n", "\n" - )); + ); $style = $this->getStyle($this->terminal); @@ -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); @@ -219,11 +219,11 @@ public function testConfirmOkNonCancellableReturnsTrue() { $this->terminal ->method('read') - ->will($this->onConsecutiveCalls( + ->willReturnOnConsecutiveCalls( "\n", 'tab', "\n" - )); + ); $style = $this->getStyle($this->terminal); @@ -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 diff --git a/test/Dialogue/FlashTest.php b/test/Dialogue/FlashTest.php index 47aa56b3..91e4bc69 100644 --- a/test/Dialogue/FlashTest.php +++ b/test/Dialogue/FlashTest.php @@ -8,6 +8,7 @@ use PhpSchool\CliMenu\MenuStyle; use PhpSchool\Terminal\IO\BufferedOutput; use PhpSchool\Terminal\Terminal; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -40,19 +41,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 testFlashWithOddLength() : void { $this->terminal ->method('read') - ->will($this->onConsecutiveCalls( + ->willReturnOnConsecutiveCalls( "\n", "\n" - )); + ); $style = $this->getStyle($this->terminal); @@ -73,10 +74,10 @@ public function testFlashWithEvenLength() : void { $this->terminal ->method('read') - ->will($this->onConsecutiveCalls( + ->willReturnOnConsecutiveCalls( "\n", "\n" - )); + ); $style = $this->getStyle($this->terminal); @@ -93,14 +94,12 @@ public function testFlashWithEvenLength() : void static::assertStringEqualsFile($this->getTestFile(), $this->output->fetch()); } - /** - * @dataProvider keyProvider - */ + #[DataProvider('keyProvider')] public function testFlashCanBeClosedWithAnyKey(string $key) : void { $this->terminal ->method('read') - ->will($this->onConsecutiveCalls("\n", $key)); + ->willReturnOnConsecutiveCalls("\n", $key); $style = $this->getStyle($this->terminal); @@ -117,7 +116,7 @@ public function testFlashCanBeClosedWithAnyKey(string $key) : void static::assertStringEqualsFile($this->getTestFile(), $this->output->fetch()); } - public function keyProvider() : array + public static function keyProvider() : array { return [ ["\n"], @@ -129,7 +128,7 @@ public function keyProvider() : array private function getTestFile() : string { - return sprintf('%s/../res/%s.txt', __DIR__, $this->getName(false)); + return sprintf('%s/../res/%s.txt', __DIR__, $this->name()); } private function getStyle(Terminal $terminal) : MenuStyle diff --git a/test/Input/NumberTest.php b/test/Input/NumberTest.php index dae3e35f..2a0a2793 100644 --- a/test/Input/NumberTest.php +++ b/test/Input/NumberTest.php @@ -8,6 +8,7 @@ use PhpSchool\CliMenu\Input\Number; use PhpSchool\CliMenu\MenuStyle; use PhpSchool\Terminal\Terminal; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -64,15 +65,13 @@ public function testGetSetPlaceholderText() : void static::assertEquals('some placeholder text', $this->input->getPlaceholderText()); } - /** - * @dataProvider validateProvider - */ + #[DataProvider('validateProvider')] public function testValidate(string $value, bool $result) : void { static::assertEquals($this->input->validate($value), $result); } - public function validateProvider() : array + public static function validateProvider() : array { return [ ['10', true], diff --git a/test/Input/PasswordTest.php b/test/Input/PasswordTest.php index 22661ec7..bf806b05 100644 --- a/test/Input/PasswordTest.php +++ b/test/Input/PasswordTest.php @@ -8,6 +8,7 @@ use PhpSchool\CliMenu\Input\Password; use PhpSchool\CliMenu\MenuStyle; use PhpSchool\Terminal\Terminal; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -64,15 +65,13 @@ public function testGetSetPlaceholderText() : void static::assertEquals('***', $this->input->getPlaceholderText()); } - /** - * @dataProvider validateProvider - */ + #[DataProvider('validateProvider')] public function testValidate(string $value, bool $result) : void { static::assertEquals($this->input->validate($value), $result); } - public function validateProvider() : array + public static function validateProvider() : array { return [ ['10', false], @@ -96,9 +95,7 @@ public function testAskPassword() : void self::assertEquals('1234567891234567', $this->input->ask()->fetch()); } - /** - * @dataProvider customValidateProvider - */ + #[DataProvider('customValidateProvider')] public function testValidateWithCustomValidator(string $value, bool $result) : void { $customValidate = function ($input) { @@ -110,7 +107,7 @@ public function testValidateWithCustomValidator(string $value, bool $result) : v static::assertEquals($this->input->validate($value), $result); } - public function customValidateProvider() : array + public static function customValidateProvider() : array { return [ ['10', false], diff --git a/test/Input/TextTest.php b/test/Input/TextTest.php index 5d3eabad..3f3241ef 100644 --- a/test/Input/TextTest.php +++ b/test/Input/TextTest.php @@ -8,6 +8,7 @@ use PhpSchool\CliMenu\Input\Text; use PhpSchool\CliMenu\MenuStyle; use PhpSchool\Terminal\Terminal; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -64,15 +65,13 @@ public function testGetSetPlaceholderText() : void static::assertEquals('My Title', $this->input->getPlaceholderText()); } - /** - * @dataProvider validateProvider - */ + #[DataProvider('validateProvider')] public function testValidate(string $value, bool $result) : void { static::assertEquals($this->input->validate($value), $result); } - public function validateProvider() : array + public static function validateProvider() : array { return [ ['', false], diff --git a/test/MenuItem/AsciiArtItemTest.php b/test/MenuItem/AsciiArtItemTest.php index 8c94fb24..17a4b771 100644 --- a/test/MenuItem/AsciiArtItemTest.php +++ b/test/MenuItem/AsciiArtItemTest.php @@ -49,7 +49,7 @@ public function testGetRowsLeftAligned() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(10)); + ->willReturn(10); $item = new AsciiArtItem("//\n//", AsciiArtItem::POSITION_LEFT); $this->assertEquals( @@ -68,7 +68,7 @@ public function testGetRowsRightAligned() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(10)); + ->willReturn(10); $item = new AsciiArtItem("//\n//", AsciiArtItem::POSITION_RIGHT); $this->assertEquals( @@ -87,7 +87,7 @@ public function testGetRowsCenterAligned() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(10)); + ->willReturn(10); $item = new AsciiArtItem("//\n//", AsciiArtItem::POSITION_CENTER); $this->assertEquals( @@ -106,7 +106,7 @@ public function testGetRowsCenterAlignedWithOddWidth() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(11)); + ->willReturn(11); $item = new AsciiArtItem("//\n//", AsciiArtItem::POSITION_CENTER); $this->assertEquals( @@ -136,7 +136,7 @@ public function testGetRowsReturnsStaticAltItemWhenWidthIsTooSmall() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(10)); + ->willReturn(10); $item = new AsciiArtItem('TOO LONG. SO SO LONG.', AsciiArtItem::POSITION_CENTER, 'my alt'); @@ -150,7 +150,7 @@ public function testGetRowsDoesNotReturnsStaticAltItemWhenOnlySpacesOverflow() : $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(15)); + ->willReturn(15); $item = new AsciiArtItem('NOT TOO LONG ', AsciiArtItem::POSITION_LEFT, 'my alt'); @@ -164,7 +164,7 @@ public function testWithRealAsciiArtCenterAligned() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(30)); + ->willReturn(30); $art = <<expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(30)); + ->willReturn(30); $art = <<expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(30)); + ->willReturn(30); $art = <<expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(30)); + ->willReturn(30); $art = <<expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(10)); + ->willReturn(10); $item = new LineBreakItem('*'); $this->assertEquals(['**********'], $item->getRows($menuStyle)); @@ -56,7 +56,7 @@ public function testGetRowsRepeatsCharForMenuWidthMultiLines() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(10)); + ->willReturn(10); $item = new LineBreakItem('*', 3); $this->assertEquals(['**********', '**********', '**********'], $item->getRows($menuStyle)); @@ -69,7 +69,7 @@ public function testGetRowsWithPhraseThatDoesNotFitInWidthEvenlyIsTrimmed() : vo $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(5)); + ->willReturn(5); //ABC should be repeated but ABCABC is 6 and the allowed length is 5 //so ABCABC is trimmed to ABCAB @@ -85,7 +85,7 @@ public function testGetRowsWithMultiByteChars() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(5)); + ->willReturn(5); $item = new LineBreakItem('❅', 2); $this->assertEquals(['❅❅❅❅❅', '❅❅❅❅❅'], $item->getRows($menuStyle)); @@ -98,7 +98,7 @@ public function testSetText() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(5)); + ->willReturn(5); $item = new LineBreakItem('ABC', 2); $item->setText('❅-'); diff --git a/test/MenuItem/MenuMenuItemTest.php b/test/MenuItem/MenuMenuItemTest.php index d538b9a0..7d6eb25a 100644 --- a/test/MenuItem/MenuMenuItemTest.php +++ b/test/MenuItem/MenuMenuItemTest.php @@ -90,7 +90,7 @@ public function testGetRowsWithSelectedMarker() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(10)); + ->willReturn(10); $subMenu = $this->getMockBuilder(CliMenu::class) ->disableOriginalConstructor() diff --git a/test/MenuItem/SelectableItemTest.php b/test/MenuItem/SelectableItemTest.php index 2bf9bcd9..0ed4d578 100644 --- a/test/MenuItem/SelectableItemTest.php +++ b/test/MenuItem/SelectableItemTest.php @@ -86,7 +86,7 @@ public function testGetRowsWithUnSelectedMarker() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(10)); + ->willReturn(10); $item = new SelectableItem('Item', function () { }); @@ -103,7 +103,7 @@ public function testGetRowsWithSelectedMarker() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(10)); + ->willReturn(10); $item = new SelectableItem('Item', function () { }); diff --git a/test/MenuItem/SplitItemTest.php b/test/MenuItem/SplitItemTest.php index 1e690fd9..78305e59 100644 --- a/test/MenuItem/SplitItemTest.php +++ b/test/MenuItem/SplitItemTest.php @@ -15,6 +15,7 @@ use PhpSchool\CliMenu\MenuStyle; use PhpSchool\CliMenu\Style\SelectableStyle; use PhpSchool\Terminal\Terminal; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -22,10 +23,8 @@ */ class SplitItemTest extends TestCase { - - /** - * @dataProvider blacklistedItemProvider - */ + + #[DataProvider('blacklistedItemProvider')] public function testConstructWithBlacklistedItemTypeThrowsException(MenuItemInterface $menuItem) : void { self::expectExceptionMessage(\InvalidArgumentException::class); @@ -34,9 +33,7 @@ public function testConstructWithBlacklistedItemTypeThrowsException(MenuItemInte new SplitItem([$menuItem]); } - /** - * @dataProvider blacklistedItemProvider - */ + #[DataProvider('blacklistedItemProvider')] public function testAddItemsWithBlacklistedItemTypeThrowsException(MenuItemInterface $menuItem) : void { self::expectExceptionMessage(\InvalidArgumentException::class); @@ -45,9 +42,7 @@ public function testAddItemsWithBlacklistedItemTypeThrowsException(MenuItemInter (new SplitItem([]))->addItems([$menuItem]); } - /** - * @dataProvider blacklistedItemProvider - */ + #[DataProvider('blacklistedItemProvider')] public function testAddItemWithBlacklistedItemTypeThrowsException(MenuItemInterface $menuItem) : void { self::expectExceptionMessage(\InvalidArgumentException::class); @@ -56,9 +51,7 @@ public function testAddItemWithBlacklistedItemTypeThrowsException(MenuItemInterf (new SplitItem([]))->addItem($menuItem); } - /** - * @dataProvider blacklistedItemProvider - */ + #[DataProvider('blacklistedItemProvider')] public function testSetItemsWithBlacklistedItemTypeThrowsException(MenuItemInterface $menuItem) : void { self::expectExceptionMessage(\InvalidArgumentException::class); @@ -67,7 +60,7 @@ public function testSetItemsWithBlacklistedItemTypeThrowsException(MenuItemInter (new SplitItem([]))->setItems([$menuItem]); } - public function blacklistedItemProvider() : array + public static function blacklistedItemProvider() : array { return [ [new AsciiArtItem('( ︶︿︶)_╭∩╮')], @@ -147,7 +140,7 @@ public function testGetRowsWithStaticItems() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(30)); + ->willReturn(30); $item = new SplitItem([new StaticItem('One'), new StaticItem('Two')]); @@ -161,7 +154,7 @@ public function testSetGutter() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(20)); + ->willReturn(20); $item = new SplitItem([new StaticItem('One Two'), new StaticItem('Three')]); @@ -172,16 +165,14 @@ public function testSetGutter() : void self::assertEquals(['One Three ', 'Two '], $item->getRows($menuStyle)); } - /** - * @dataProvider belowZeroProvider - */ + #[DataProvider('belowZeroProvider')] public function testSetGutterThrowsExceptionIfValueIsNotZeroOrAbove(int $value) : void { self::expectException(\Assert\InvalidArgumentException::class); $item = new SplitItem(); $item->setGutter($value); } - public function belowZeroProvider() : array + public static function belowZeroProvider() : array { return [[-1], [-2], [-10]]; } @@ -193,7 +184,7 @@ public function testGetRowsWithOneItemSelected() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(30)); + ->willReturn(30); $selectableStyle = (new SelectableStyle()) ->setSelectedMarker('= ') @@ -221,7 +212,7 @@ public function testGetRowsWithMultipleLineStaticItems() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(30)); + ->willReturn(30); $item = new SplitItem([new StaticItem("Item\nOne"), new StaticItem("Item\nTwo")]); @@ -241,7 +232,7 @@ public function testGetRowsWithMultipleLinesWithUnSelectedMarker() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(30)); + ->willReturn(30); $selectableStyle = (new SelectableStyle()) ->setUnselectedMarker('* '); @@ -272,7 +263,7 @@ public function testGetRowsWithMultipleLinesWithOneItemSelected() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(30)); + ->willReturn(30); $selectableStyle = (new SelectableStyle()) ->setSelectedMarker('= ') @@ -486,7 +477,7 @@ public function testCheckboxItem() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(30)); + ->willReturn(30); $checkboxItem1 = new CheckboxItem('Item One', function () { }); @@ -523,7 +514,7 @@ public function testRadioItem() : void $menuStyle ->expects($this->any()) ->method('getContentWidth') - ->will($this->returnValue(30)); + ->willReturn(30); $radioItem1 = new RadioItem('Item One', function () { }); diff --git a/test/MenuItem/StaticItemTest.php b/test/MenuItem/StaticItemTest.php index 05b081fb..5222bb27 100644 --- a/test/MenuItem/StaticItemTest.php +++ b/test/MenuItem/StaticItemTest.php @@ -43,7 +43,7 @@ public function testGetRowsWithContentWhichFitsOnOneLine() : void $menuStyle ->expects($this->once()) ->method('getContentWidth') - ->will($this->returnValue(20)); + ->willReturn(20); $item = new StaticItem('CONTENT 1 LINE'); @@ -60,7 +60,7 @@ public function testGetRowsWithContentWhichDoesNotFitOnOneLineIsWrapped() : void $menuStyle ->expects($this->once()) ->method('getContentWidth') - ->will($this->returnValue(10)); + ->willReturn(10); $item = new StaticItem('CONTENT 1 LINE'); @@ -77,7 +77,7 @@ public function testSetText() : void $menuStyle ->expects($this->once()) ->method('getContentWidth') - ->will($this->returnValue(10)); + ->willReturn(10); $item = new StaticItem('CONTENT'); $item->setText('CONTENT 2 LINES'); diff --git a/test/MenuStyleTest.php b/test/MenuStyleTest.php index 64b0c156..0da53c1f 100644 --- a/test/MenuStyleTest.php +++ b/test/MenuStyleTest.php @@ -8,6 +8,7 @@ use PhpSchool\CliMenu\Exception\InvalidInstantiationException; use PhpSchool\CliMenu\MenuStyle; use PhpSchool\Terminal\UnixTerminal; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -552,9 +553,7 @@ public function testSetBorderColourRecalculatesPaddingTopAndBottomRows() : void ); } - /** - * @dataProvider belowZeroProvider - */ + #[DataProvider('belowZeroProvider')] public function testSetWidthThrowsExceptionIfValueIsNotZeroOrAbove(int $value) : void { self::expectException(\Assert\InvalidArgumentException::class); @@ -562,7 +561,7 @@ public function testSetWidthThrowsExceptionIfValueIsNotZeroOrAbove(int $value) : $this->getMenuStyle()->setWidth($value); } - public function belowZeroProvider() : array + public static function belowZeroProvider() : array { return [[-1], [-2], [-10]]; } @@ -615,9 +614,7 @@ public function testSetPaddingLeftAndRight() : void self::assertEquals(4, $style->getPaddingLeftRight()); } - /** - * @dataProvider belowZeroProvider - */ + #[DataProvider('belowZeroProvider')] public function testSetPaddingTopAndBottomThrowsExceptionIfValueIsNotZeroOrAbove(int $value) : void { self::expectException(\Assert\InvalidArgumentException::class); @@ -625,9 +622,7 @@ public function testSetPaddingTopAndBottomThrowsExceptionIfValueIsNotZeroOrAbove $this->getMenuStyle()->setPaddingTopBottom($value); } - /** - * @dataProvider belowZeroProvider - */ + #[DataProvider('belowZeroProvider')] public function testSetPaddingLeftAndRightThrowsExceptionIfValueIsNotZeroOrAbove(int $value) : void { self::expectException(\Assert\InvalidArgumentException::class); @@ -635,9 +630,7 @@ public function testSetPaddingLeftAndRightThrowsExceptionIfValueIsNotZeroOrAbove $this->getMenuStyle()->setPaddingLeftRight($value); } - /** - * @dataProvider belowZeroProvider - */ + #[DataProvider('belowZeroProvider')] public function testSetPaddingThrowsExceptionIfTopBottomValueIsNotZeroOrAbove(int $value) : void { self::expectException(\Assert\InvalidArgumentException::class); @@ -645,9 +638,7 @@ public function testSetPaddingThrowsExceptionIfTopBottomValueIsNotZeroOrAbove(in $this->getMenuStyle()->setPadding($value, 1); } - /** - * @dataProvider belowZeroProvider - */ + #[DataProvider('belowZeroProvider')] public function testSetPaddingThrowsExceptionIfLeftRightValueIsNotZeroOrAbove(int $value) : void { self::expectException(\Assert\InvalidArgumentException::class); @@ -655,9 +646,7 @@ public function testSetPaddingThrowsExceptionIfLeftRightValueIsNotZeroOrAbove(in $this->getMenuStyle()->setPadding(1, $value); } - /** - * @dataProvider belowZeroProvider - */ + #[DataProvider('belowZeroProvider')] public function testSetMarginThrowsExceptionIfValueIsNotZeroOrAbove(int $value) : void { self::expectException(\Assert\InvalidArgumentException::class); @@ -715,9 +704,7 @@ public function testDebugMode() : void ); } - /** - * @dataProvider cannotShrinkProvider - */ + #[DataProvider('cannotShrinkProvider')] public function testSetWidthThrowsExceptionIfMenuTooWideAndMarginConsumesTerminal(int $margin) : void { $this->expectException(CannotShrinkMenuException::class); @@ -730,7 +717,7 @@ public function testSetWidthThrowsExceptionIfMenuTooWideAndMarginConsumesTermina $style->setWidth(10); } - public function cannotShrinkProvider() : array + public static function cannotShrinkProvider() : array { return [[50], [51], [100]]; } diff --git a/test/Style/LocatorTest.php b/test/Style/LocatorTest.php index 5d79e312..e8778275 100644 --- a/test/Style/LocatorTest.php +++ b/test/Style/LocatorTest.php @@ -19,6 +19,7 @@ use PhpSchool\CliMenu\Style\Locator; use PhpSchool\CliMenu\Style\RadioStyle; use PhpSchool\CliMenu\Style\SelectableStyle; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class LocatorTest extends TestCase @@ -104,7 +105,7 @@ public function testGetStyleForMenuItemThrowsExceptionIfItemNotRegistered() : vo $locator->getStyleForMenuItem($myItem); } - public function itemStyleProvider() : array + public static function itemStyleProvider() : array { $action = function () { }; @@ -120,9 +121,7 @@ public function itemStyleProvider() : array ]; } - /** - * @dataProvider itemStyleProvider - */ + #[DataProvider('itemStyleProvider')] public function testGetStyleForMenuItem(string $expectedStyleClass, MenuItemInterface $menuItem) : void { $locator = new Locator(); @@ -138,7 +137,7 @@ public function testGetStyleThrowsExceptionIfStyleClassNotRegistered() : void $locator->getStyle('NonExistingStyleClass'); } - public function styleProvider() : array + public static function styleProvider() : array { return [ [DefaultStyle::class], @@ -149,9 +148,7 @@ public function styleProvider() : array ]; } - /** - * @dataProvider styleProvider - */ + #[DataProvider('styleProvider')] public function testGetStyle(string $styleClass) : void { $locator = new Locator(); diff --git a/test/Util/ColourUtilTest.php b/test/Util/ColourUtilTest.php index 85e52e0f..9305b5d8 100644 --- a/test/Util/ColourUtilTest.php +++ b/test/Util/ColourUtilTest.php @@ -5,6 +5,7 @@ use PhpSchool\CliMenu\Util\ColourUtil; use PhpSchool\Terminal\Terminal; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -88,9 +89,7 @@ public function testValidateColourPicksFallbackFromPreComputedListWhenTerminalDo self::assertEquals('yellow', ColourUtil::validateColour($terminal, '148')); } - /** - * @dataProvider invalidColourCodeProvider - */ + #[DataProvider('invalidColourCodeProvider')] public function testValidateColourThrowsExceptionIfInvalid256ColourCodeUsed(string $colourCode) : void { self::expectException(\Assert\InvalidArgumentException::class); @@ -98,7 +97,7 @@ public function testValidateColourThrowsExceptionIfInvalid256ColourCodeUsed(stri ColourUtil::validateColour($this->createMock(Terminal::class), $colourCode); } - public function invalidColourCodeProvider() : array + public static function invalidColourCodeProvider() : array { return [ ['-1'], @@ -107,9 +106,7 @@ public function invalidColourCodeProvider() : array ]; } - /** - * @dataProvider validColourCodeProvider - */ + #[DataProvider('validColourCodeProvider')] public function testValidateColourWith256ColoursWhenTerminalSupports256Colours(string $colourCode) : void { $terminal = $this->createMock(Terminal::class); @@ -120,7 +117,7 @@ public function testValidateColourWith256ColoursWhenTerminalSupports256Colours(s self::assertEquals($colourCode, ColourUtil::validateColour($terminal, $colourCode)); } - public function validColourCodeProvider() : array + public static function validColourCodeProvider() : array { return [ ['0'], From 9594c836453cd7f387101ab7d57c2eb12285e8c7 Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Tue, 29 Jul 2025 17:29:27 +0200 Subject: [PATCH 2/2] fix coverage --- .gitignore | 1 + phpunit.xml | 31 +++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 4a3db6b2..99b8f988 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor/ .idea /composer.lock /.phpunit.result.cache +/.phpunit.cache diff --git a/phpunit.xml b/phpunit.xml index e527bfbe..0d9949cc 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,12 +1,23 @@ + + + + test + + - - - ./test - - - - ./src - - - \ No newline at end of file + + + src + + +