From bda07dfc5cd12a14688e10398cf4b704798ff3b5 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Wed, 4 Oct 2023 07:18:02 -0300 Subject: [PATCH] Raise min version to `PHP 7.3`, check compatibility `PHP 8.3`. --- .editorconfig | 3 ++ composer.json | 4 +- phpunit.xml.dist | 37 +++++++++----- tests/AccordionTest.php | 26 ++++++---- tests/ActiveFieldDefaultFormCheckTest.php | 8 +-- tests/ActiveFieldTest.php | 6 +-- tests/ActiveFormTest.php | 49 +++++++++--------- tests/ButtonDropdownTest.php | 2 +- tests/CarouselTest.php | 2 +- tests/LinkPagerTest.php | 50 ++++++++++++------ tests/ModalTest.php | 4 +- tests/NavBarTest.php | 9 ++-- tests/NavTest.php | 2 +- tests/OffcanvasTest.php | 4 +- tests/PopoverTest.php | 20 ++++---- tests/TabsTest.php | 62 +++++++++++------------ tests/TestCase.php | 4 +- tests/ToastTest.php | 11 ++-- tests/ToggleButtonGroupTest.php | 10 +++- tests/TranslationTest.php | 2 +- 20 files changed, 183 insertions(+), 132 deletions(-) diff --git a/.editorconfig b/.editorconfig index 257221d..5e9a93e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,6 @@ trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false + +[*.yml] +indent_size = 2 diff --git a/composer.json b/composer.json index 3e666fe..15949f1 100644 --- a/composer.json +++ b/composer.json @@ -24,14 +24,14 @@ ], "minimum-stability": "stable", "require": { - "php": ">=7.0", + "php": ">=7.3", "ext-json": "*", "yiisoft/yii2": "^2.0.42", "bower-asset/bootstrap": "^5.1.0" }, "require-dev": { "yiisoft/yii2-coding-standards": "~2.0", - "phpunit/phpunit": "^6.5.14", + "phpunit/phpunit": "^9.6", "twbs/bootstrap-icons": "^1.7.2" }, "suggest": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5311924..524759f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,14 +1,27 @@ - - - - ./tests - - + + + + + + + + + ./tests + + + + + + ./src + + diff --git a/tests/AccordionTest.php b/tests/AccordionTest.php index a5ba014..7521f93 100644 --- a/tests/AccordionTest.php +++ b/tests/AccordionTest.php @@ -215,13 +215,13 @@ public function invalidItemsProvider() /** * @dataProvider invalidItemsProvider - * @expectedException \yii\base\InvalidConfigException */ public function testMissingLabel($items) { - Accordion::widget([ - 'items' => $items, - ]); + $this->expectException(InvalidConfigException::class); + $this->expectExceptionMessage("The 'label' option is required."); + + Accordion::widget(['items' => $items]); } /** @@ -278,12 +278,12 @@ public function testAutoCloseItems() $output = Accordion::widget([ 'items' => $items ]); - $this->assertContains('data-bs-parent="', $output); + $this->assertStringContainsString('data-bs-parent="', $output); $output = Accordion::widget([ 'autoCloseItems' => false, 'items' => $items ]); - $this->assertNotContains('data-bs-parent="', $output); + $this->assertStringNotContainsString('data-bs-parent="', $output); } /** @@ -310,8 +310,11 @@ public function testItemToggleTag() 'class' => 'custom-toggle', ], ]); - $this->assertContains('
assertNotContains('assertStringContainsString( + '
assertStringNotContainsString(' $items, @@ -320,7 +323,10 @@ public function testItemToggleTag() 'class' => ['widget' => 'custom-toggle'], ], ]); - $this->assertContains('
assertNotContains('collapse-toggle', $output); + $this->assertStringContainsString( + '
assertStringNotContainsString('collapse-toggle', $output); } } diff --git a/tests/ActiveFieldDefaultFormCheckTest.php b/tests/ActiveFieldDefaultFormCheckTest.php index f03aaf6..95b2b0d 100644 --- a/tests/ActiveFieldDefaultFormCheckTest.php +++ b/tests/ActiveFieldDefaultFormCheckTest.php @@ -184,12 +184,12 @@ public function testHorizontalLayout() HTML; - $this->assertContainsWithoutLE($expected, $out); - $this->assertContainsWithoutLE($expected2, $out); - $this->assertContainsWithoutLE($expected3, $out); + $this->assertStringContainsString($expected, $out); + $this->assertStringContainsString($expected2, $out); + $this->assertStringContainsString($expected3, $out); } - protected function setUp() + protected function setUp(): void { // dirty way to have Request object not throwing exception when running testHomeLinkNull() $_SERVER['SCRIPT_FILENAME'] = 'index.php'; diff --git a/tests/ActiveFieldTest.php b/tests/ActiveFieldTest.php index 6d82135..a89357a 100644 --- a/tests/ActiveFieldTest.php +++ b/tests/ActiveFieldTest.php @@ -291,7 +291,7 @@ public function testRadioListItemOptions() ] ])->render(); - $this->assertContains('data-attribute="test"', $content); + $this->assertStringContainsString('data-attribute="test"', $content); } /** @@ -306,10 +306,10 @@ public function testCheckboxListItemOptions() ] ])->render(); - $this->assertContains('data-attribute="test"', $content); + $this->assertStringContainsString('data-attribute="test"', $content); } - protected function setUp() + protected function setUp(): void { // dirty way to have Request object not throwing exception when running testHomeLinkNull() $_SERVER['SCRIPT_FILENAME'] = "index.php"; diff --git a/tests/ActiveFormTest.php b/tests/ActiveFormTest.php index 2b1458b..bc6c5f2 100644 --- a/tests/ActiveFormTest.php +++ b/tests/ActiveFormTest.php @@ -37,8 +37,7 @@ public function testDefaultLayout() HTML; - - $this->assertContainsWithoutLE($expected, $out); + $this->assertStringContainsString($expected, $out); } public function testHorizontalLayout() @@ -109,9 +108,9 @@ public function testHorizontalLayout() HTML; - $this->assertContainsWithoutLE($expected, $out); - $this->assertContainsWithoutLE($expected2, $out); - $this->assertContainsWithoutLE($expected3, $out); + $this->assertStringContainsString($expected, $out); + $this->assertStringContainsString($expected2, $out); + $this->assertStringContainsString($expected3, $out); } /** @@ -138,7 +137,7 @@ public function testHorizontalLayoutTemplateOverride() HTML; - $this->assertContainsWithoutLE($expected, $out); + $this->assertStringContainsString($expected, $out); } public function testInlineLayout() @@ -192,10 +191,10 @@ public function testInlineLayout() HTML; - $this->assertContainsWithoutLE('
assertContainsWithoutLE($expected, $out); - $this->assertContainsWithoutLE($expected2, $out); - $this->assertContainsWithoutLE($expected3, $out); + $this->assertStringContainsString('assertStringContainsString($expected, $out); + $this->assertStringContainsString($expected2, $out); + $this->assertStringContainsString($expected3, $out); } public function testFloatingLayout() @@ -249,10 +248,10 @@ public function testFloatingLayout() HTML; - $this->assertContainsWithoutLE('assertContainsWithoutLE($expected, $out); - $this->assertContainsWithoutLE($expected2, $out); - $this->assertContainsWithoutLE($expected3, $out); + $this->assertStringContainsString('assertStringContainsString($expected, $out); + $this->assertStringContainsString($expected2, $out); + $this->assertStringContainsString($expected3, $out); } public function testHintRendering() @@ -304,10 +303,10 @@ public function testHintRendering() HTML; - $this->assertContainsWithoutLE($expected, $out); - $this->assertContainsWithoutLE($expected2, $out); - $this->assertContainsWithoutLE($expected3, $out); - $this->assertContainsWithoutLE($expected4, $out); + $this->assertStringContainsString($expected, $out); + $this->assertStringContainsString($expected2, $out); + $this->assertStringContainsString($expected3, $out); + $this->assertStringContainsString($expected4, $out); } public function testStaticControlRendering() @@ -357,9 +356,9 @@ public function testStaticControlRendering() HTML; - $this->assertContainsWithoutLE($expected, $out); - $this->assertContainsWithoutLE($expected2, $out); - $this->assertContainsWithoutLE($expected3, $out); + $this->assertStringContainsString($expected, $out); + $this->assertStringContainsString($expected2, $out); + $this->assertStringContainsString($expected3, $out); } /** @@ -387,7 +386,7 @@ public function testInputTemplate() HTML; - $this->assertContainsWithoutLE($expected, $out); + $this->assertStringContainsString($expected, $out); } /** @@ -397,7 +396,7 @@ public function testFormNoRoleAttribute() { $form = ActiveForm::widget(); - $this->assertNotContains('role="form"', $form); + $this->assertStringNotContainsString('role="form"', $form); } public function testErrorSummaryRendering() @@ -415,10 +414,10 @@ public function testErrorSummaryRendering() $out = ob_get_clean(); - $this->assertContainsWithoutLE('
assertStringContainsString('
assertContains("$containerClass dropup btn-group", $out); + $this->assertStringContainsString("$containerClass dropup btn-group", $out); } public function testDirection() diff --git a/tests/CarouselTest.php b/tests/CarouselTest.php index f086636..93a3290 100644 --- a/tests/CarouselTest.php +++ b/tests/CarouselTest.php @@ -90,6 +90,6 @@ public function testCrossfade() ] ]); - $this->assertContains('class="carousel slide carousel-fade"', $out); + $this->assertStringContainsString('class="carousel slide carousel-fade"', $out); } } diff --git a/tests/LinkPagerTest.php b/tests/LinkPagerTest.php index 25ab380..cdc3b96 100644 --- a/tests/LinkPagerTest.php +++ b/tests/LinkPagerTest.php @@ -12,6 +12,8 @@ use yii\helpers\ReplaceArrayValue; use yii\helpers\StringHelper; +use function PHPUnit\Framework\assertStringNotContainsString; + /** * @group bootstrap5 */ @@ -25,22 +27,34 @@ public function testFirstLastPageLabels() 'firstPageLabel' => true, 'lastPageLabel' => true, ]); - $this->assertContains('
  • 1
  • ', $output); - $this->assertContains('
  • 25
  • ', $output); + $this->assertStringContainsString( + '
  • 1
  • ', + $output, + ); + $this->assertStringContainsString( + '
  • 25
  • ', + $output, + ); $output = LinkPager::widget([ 'pagination' => $pagination, 'firstPageLabel' => 'First', 'lastPageLabel' => 'Last', ]); - $this->assertContains('
  • First
  • ', $output); - $this->assertContains('
  • Last
  • ', $output); + $this->assertStringContainsString( + '
  • First
  • ', + $output, + ); + $this->assertStringContainsString( + '
  • Last
  • ', + $output, + ); $output = LinkPager::widget([ 'pagination' => $pagination, 'firstPageLabel' => false, 'lastPageLabel' => false, ]); - $this->assertNotContains('
  • ', $output); - $this->assertNotContains('
  • ', $output); + $this->assertStringNotContainsString('
  • ', $output); + $this->assertStringNotContainsString('
  • ', $output); } public function testDisabledPageElementOptions() @@ -49,7 +63,7 @@ public function testDisabledPageElementOptions() 'pagination' => $this->getPagination(0), 'disabledListItemSubTagOptions' => ['class' => ['foo-bar']], ]); - $this->assertContains('
  • 6
  • ', $output); + $this->assertStringContainsString( + '
  • 6
  • ', + $output, + ); $output = LinkPager::widget([ 'pagination' => $pagination, 'disableCurrentPageButton' => true, ]); - $this->assertContains('
  • 6
  • ', $output); + $this->assertStringContainsString( + '
  • 6
  • ', + $output, + ); } public function testOptionsWithTagOption() @@ -100,13 +120,13 @@ public function testLinkWrapOptions() 'class' => 'my-class', ], ]); - $this->assertContains( + $this->assertStringContainsString( '', - $output + $output, ); - $this->assertContains( + $this->assertStringContainsString( '', - $output + $output, ); } @@ -125,7 +145,7 @@ public function testShouldTriggerInitEvent() $this->assertTrue($initTriggered); } - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->mockWebApplication([ diff --git a/tests/ModalTest.php b/tests/ModalTest.php index ff05f08..07cc899 100644 --- a/tests/ModalTest.php +++ b/tests/ModalTest.php @@ -108,9 +108,9 @@ public function testTriggerButton() Modal::end(); $out = ob_get_clean(); - $this->assertContains( + $this->assertStringContainsString( '', - $out + $out, ); } diff --git a/tests/NavBarTest.php b/tests/NavBarTest.php index e9caaf9..975981e 100644 --- a/tests/NavBarTest.php +++ b/tests/NavBarTest.php @@ -46,7 +46,10 @@ public function testBrandImage() 'brandUrl' => '/', ]); - $this->assertContains('', $out); + $this->assertStringContainsString( + '', + $out, + ); } public function testBrandLink() @@ -56,7 +59,7 @@ public function testBrandLink() 'brandUrl' => false, ]); - $this->assertContains('Yii Framework', $out); + $this->assertStringContainsString('Yii Framework', $out); } public function testBrandSpan() @@ -66,7 +69,7 @@ public function testBrandSpan() 'brandUrl' => null, ]); - $this->assertContains('Yii Framework', $out); + $this->assertStringContainsString('Yii Framework', $out); } /** diff --git a/tests/NavTest.php b/tests/NavTest.php index 630a6da..f632bdf 100644 --- a/tests/NavTest.php +++ b/tests/NavTest.php @@ -347,7 +347,7 @@ public function testDeepActivateParents() $this->assertEqualsWithoutLE($expected, $out); } - protected function setUp() + protected function setUp(): void { $this->mockWebApplication([ 'components' => [ diff --git a/tests/OffcanvasTest.php b/tests/OffcanvasTest.php index dad015b..4e0a368 100644 --- a/tests/OffcanvasTest.php +++ b/tests/OffcanvasTest.php @@ -86,9 +86,9 @@ public function testTriggerButton() Offcanvas::end(); $out = ob_get_clean(); - $this->assertContains( + $this->assertStringContainsString( '', - $out + $out, ); } } diff --git a/tests/PopoverTest.php b/tests/PopoverTest.php index 681b3a8..c3aaf2e 100644 --- a/tests/PopoverTest.php +++ b/tests/PopoverTest.php @@ -2,7 +2,6 @@ namespace yiiunit\extensions\bootstrap5; -use PHPUnit\Framework\Constraint\IsType; use Yii; use yii\bootstrap5\Html; use yii\bootstrap5\Popover; @@ -36,14 +35,14 @@ public function testClientOptions() $js = Yii::$app->view->js[View::POS_READY]; - $this->assertInternalType(IsType::TYPE_ARRAY, $js); + $this->assertIsArray($js); $options = array_shift($js); - $this->assertContainsWithoutLE("(new bootstrap.Popover('#w0', {", $options); - $this->assertContainsWithoutLE("id=\u0022w0-popover\u0022", $options); - $this->assertContainsWithoutLE("class=\u0022test-header popover-header\u0022", $options); - $this->assertContainsWithoutLE('"placement":"bottom"', $options); - $this->assertContainsWithoutLE('"title":"Test Popover"', $options); + $this->assertStringContainsString("(new bootstrap.Popover('#w0', {", $options); + $this->assertStringContainsString("id=\u0022w0-popover\u0022", $options); + $this->assertStringContainsString("class=\u0022test-header popover-header\u0022", $options); + $this->assertStringContainsString('"placement":"bottom"', $options); + $this->assertStringContainsString('"title":"Test Popover"', $options); } public function testContent() @@ -55,9 +54,12 @@ public function testContent() $js = Yii::$app->view->js[View::POS_READY]; - $this->assertInternalType(IsType::TYPE_ARRAY, $js); + $this->assertIsArray($js); $options = array_shift($js); - $this->assertContainsWithoutLE('"content":"\u003Cspan class=\u0022test-content\u0022\u003ETest content\u003C\/span\u003E"', $options); + $this->assertStringContainsString( + '"content":"\u003Cspan class=\u0022test-content\u0022\u003ETest content\u003C\/span\u003E"', + $options, + ); } } diff --git a/tests/TabsTest.php b/tests/TabsTest.php index 2ca9528..4f572f7 100644 --- a/tests/TabsTest.php +++ b/tests/TabsTest.php @@ -28,7 +28,7 @@ public function testRoleTablist() ] ]); - $this->assertContainsWithoutLE('