diff --git a/composer.json b/composer.json index d02860f0..c1788875 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,6 @@ "guzzlehttp/psr7": "^2.7", "liuggio/fastest": "^1.11", "php-http/client-common": "^2.1", - "phpunit/phpunit": "^8.5 || ^9.0 || ^10.0", "symfony/config": "^7.3", "symfony/console": "^7.3", "symfony/dependency-injection": "^7.3", @@ -36,7 +35,8 @@ "psy/psysh": "^0.12.4", "oleg-andreyev/mink-phpwebdriver": "<1.3.3", "oleg-andreyev/mink-phpwebdriver-extension": "^1.0", - "symfony/form": "^7.3" + "symfony/form": "^7.3", + "webmozart/assert": "^2.3" }, "require-dev": { "ibexa/code-style": "~2.3.0", @@ -46,7 +46,8 @@ "phpstan/phpstan": "^2.0", "phpstan/phpstan-phpunit": "^2.0", "phpstan/phpstan-symfony": "^2.0", - "symfony/phpunit-bridge": "^7.3" + "symfony/phpunit-bridge": "^7.3", + "phpunit/phpunit": "^12.5" }, "autoload": { "psr-4": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c2db6114..e6616381 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -576,12 +576,6 @@ parameters: count: 1 path: src/lib/API/ContentData/FieldTypeData/SelectionDataProvider.php - - - message: '#^Parameter \#1 \$min \(1\) of function random_int expects lower number than parameter \#2 \$max \(int\<0, max\>\)\.$#' - identifier: argument.type - count: 1 - path: src/lib/API/ContentData/FieldTypeData/SelectionDataProvider.php - - message: '#^Parameter \#1 \$selection of class Ibexa\\Core\\FieldType\\Selection\\Value constructor expects array\, list\ given\.$#' identifier: argument.type @@ -1086,12 +1080,6 @@ parameters: count: 1 path: src/lib/API/Facade/SearchFacade.php - - - message: '#^Parameter \#1 \$min \(0\) of function random_int expects lower number than parameter \#2 \$max \(int\<\-1, max\>\)\.$#' - identifier: argument.type - count: 1 - path: src/lib/API/Facade/SearchFacade.php - - message: '#^Possibly invalid array key type array\\|int\.$#' identifier: offsetAccess.invalidOffset @@ -2946,12 +2934,6 @@ parameters: count: 1 path: tests/lib/Browser/Element/Criterion/ChildElementTextCriterionTest.php - - - message: '#^Call to an undefined method PHPUnit\\Framework\\MockObject\\Builder\\InvocationStubber\:\:with\(\)\.$#' - identifier: method.notFound - count: 1 - path: tests/lib/Browser/Element/Criterion/ElementAttributeCriterionTest.php - - message: '#^Method Ibexa\\Tests\\Behat\\Browser\\Element\\Criterion\\ElementAttributeCriterionTest\:\:createElementWithAttribute\(\) has parameter \$attribute with no type specified\.$#' identifier: missingType.parameter diff --git a/phpunit.xml b/phpunit.xml index 8a186cee..32c402a9 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,13 @@ - + diff --git a/src/lib/API/Facade/ContentFacade.php b/src/lib/API/Facade/ContentFacade.php index a68d2d33..00b2d6eb 100644 --- a/src/lib/API/Facade/ContentFacade.php +++ b/src/lib/API/Facade/ContentFacade.php @@ -18,7 +18,7 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Ibexa\Contracts\Core\Repository\Values\Content\Location; use Ibexa\Contracts\Core\Repository\Values\Content\URLAlias; -use PHPUnit\Framework\Assert; +use Webmozart\Assert\Assert; class ContentFacade { @@ -63,7 +63,7 @@ public function createContentDraft( $contentItemData = null ): Content { $parentUrlAlias = $this->urlAliasService->lookup($parentUrl); - Assert::assertEquals(URLAlias::LOCATION, $parentUrlAlias->type); + Assert::eq($parentUrlAlias->type, URLAlias::LOCATION); $parentLocationId = $parentUrlAlias->destination; $locationCreateStruct = $this->locationService->newLocationCreateStruct((int) $parentLocationId); @@ -111,7 +111,7 @@ public function createDraftForExistingContent( $contentItemData ): Content { $urlAlias = $this->urlAliasService->lookup($locationURL); - Assert::assertEquals(URLAlias::LOCATION, $urlAlias->type); + Assert::eq($urlAlias->type, URLAlias::LOCATION); $location = $this->locationService->loadLocation((int) $urlAlias->destination); $contentDraft = $this->contentService->createContentDraft($location->getContentInfo()); @@ -132,7 +132,7 @@ public function getContentByLocationURL($locationURL): Content public function getLocationByLocationURL($locationURL): Location { $urlAlias = $this->urlAliasService->lookup($locationURL); - Assert::assertEquals(URLAlias::LOCATION, $urlAlias->type); + Assert::eq($urlAlias->type, URLAlias::LOCATION); return $this->repository->sudo(function () use ($urlAlias) { return $this->locationService->loadLocation((int) $urlAlias->destination); diff --git a/src/lib/API/Facade/SearchFacade.php b/src/lib/API/Facade/SearchFacade.php index 2bf602bf..bb5b29e6 100644 --- a/src/lib/API/Facade/SearchFacade.php +++ b/src/lib/API/Facade/SearchFacade.php @@ -19,7 +19,7 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\LogicalNot; use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\Subtree; use Ibexa\Contracts\Core\Repository\Values\Content\URLAlias; -use PHPUnit\Framework\Assert; +use Webmozart\Assert\Assert; class SearchFacade { @@ -54,7 +54,7 @@ public function __construct( public function getRandomChildFromPath(string $path): string { $urlAlias = $this->urlAliasService->lookup($path); - Assert::assertEquals(URLAlias::LOCATION, $urlAlias->type); + Assert::eq($urlAlias->type, URLAlias::LOCATION); $location = $this->locationService->loadLocation((int) $urlAlias->destination); diff --git a/src/lib/API/Facade/TrashFacade.php b/src/lib/API/Facade/TrashFacade.php index 8c6dd793..934ef594 100644 --- a/src/lib/API/Facade/TrashFacade.php +++ b/src/lib/API/Facade/TrashFacade.php @@ -12,7 +12,7 @@ use Ibexa\Contracts\Core\Repository\TrashService; use Ibexa\Contracts\Core\Repository\URLAliasService; use Ibexa\Contracts\Core\Repository\Values\Content\URLAlias; -use PHPUnit\Framework\Assert; +use Webmozart\Assert\Assert; class TrashFacade { @@ -38,7 +38,7 @@ public function __construct( public function trash(string $locationURL) { $urlAlias = $this->urlAliasService->lookup($locationURL); - Assert::assertEquals(URLAlias::LOCATION, $urlAlias->type); + Assert::eq($urlAlias->type, URLAlias::LOCATION); $location = $this->locationService->loadLocation((int) $urlAlias->destination); diff --git a/src/lib/Browser/Assert/CollectionAssert.php b/src/lib/Browser/Assert/CollectionAssert.php index 23c90d36..e80682b9 100644 --- a/src/lib/Browser/Assert/CollectionAssert.php +++ b/src/lib/Browser/Assert/CollectionAssert.php @@ -11,7 +11,7 @@ use Ibexa\Behat\Browser\Element\ElementCollectionInterface; use Ibexa\Behat\Browser\Element\Mapper\ElementTextMapper; use Ibexa\Behat\Browser\Locator\LocatorInterface; -use PHPUnit\Framework\Assert; +use Webmozart\Assert\Assert; class CollectionAssert implements CollectionAssertInterface { @@ -35,7 +35,7 @@ public function __construct( public function isEmpty(): ElementCollectionInterface { - Assert::assertTrue( + Assert::true( $this->elementCollection->empty(), sprintf( "Failed asserting that Collection created with %s locator '%s': '%s' is empty", @@ -53,7 +53,7 @@ public function hasElements(): ElementCollectionInterface $elements = $this->elementCollection->toArray(); $this->elementCollection->setElements($elements); - Assert::assertNotEmpty( + Assert::notEmpty( $elements, sprintf( "Failed asserting that Collection created with %s locator '%s': '%s' is not empty", @@ -71,9 +71,9 @@ public function countEquals(int $expectedCount): ElementCollectionInterface $elements = $this->elementCollection->toArray(); $this->elementCollection->setElements($elements); - Assert::assertCount( - $expectedCount, + Assert::count( $elements, + $expectedCount, sprintf( "Failed asserting that Collection created with %s locator '%s': '%s' has %d elements. Found %s instead.", $this->locator->getType(), @@ -95,7 +95,7 @@ public function containsElementsWithText(array $expectedElementTexts): ElementCo $elementTexts = $this->elementCollection->mapBy(new ElementTextMapper()); foreach ($expectedElementTexts as $expectedElementText) { - Assert::assertContains( + Assert::inArray( $expectedElementText, $elementTexts, sprintf( diff --git a/src/lib/Browser/Assert/Debug/Interactive/CollectionAssert.php b/src/lib/Browser/Assert/Debug/Interactive/CollectionAssert.php index 29351c2f..b15d26cd 100644 --- a/src/lib/Browser/Assert/Debug/Interactive/CollectionAssert.php +++ b/src/lib/Browser/Assert/Debug/Interactive/CollectionAssert.php @@ -11,7 +11,7 @@ use Ibexa\Behat\Browser\Assert\CollectionAssertInterface; use Ibexa\Behat\Browser\Element\ElementCollectionInterface; use Ibexa\Behat\Core\Debug\InteractiveDebuggerTrait; -use PHPUnit\Framework\ExpectationFailedException; +use Webmozart\Assert\InvalidArgumentException; class CollectionAssert implements CollectionAssertInterface { @@ -29,7 +29,7 @@ public function isEmpty(): ElementCollectionInterface { try { return $this->baseCollectionAssert->isEmpty(); - } catch (ExpectationFailedException $exception) { + } catch (InvalidArgumentException $exception) { return $this->startInteractiveSessionOnException($exception, true); } } @@ -38,7 +38,7 @@ public function hasElements(): ElementCollectionInterface { try { return $this->baseCollectionAssert->hasElements(); - } catch (ExpectationFailedException $exception) { + } catch (InvalidArgumentException $exception) { return $this->startInteractiveSessionOnException($exception, true); } } @@ -47,7 +47,7 @@ public function countEquals(int $expectedCount): ElementCollectionInterface { try { return $this->baseCollectionAssert->countEquals($expectedCount); - } catch (ExpectationFailedException $exception) { + } catch (InvalidArgumentException $exception) { return $this->startInteractiveSessionOnException($exception, true); } } @@ -56,7 +56,7 @@ public function containsElementsWithText(array $expectedElementTexts): ElementCo { try { return $this->baseCollectionAssert->containsElementsWithText($expectedElementTexts); - } catch (ExpectationFailedException $exception) { + } catch (InvalidArgumentException $exception) { return $this->startInteractiveSessionOnException($exception, true); } } diff --git a/src/lib/Browser/Assert/Debug/Interactive/ElementAssert.php b/src/lib/Browser/Assert/Debug/Interactive/ElementAssert.php index 17e21214..bed989bb 100644 --- a/src/lib/Browser/Assert/Debug/Interactive/ElementAssert.php +++ b/src/lib/Browser/Assert/Debug/Interactive/ElementAssert.php @@ -11,7 +11,7 @@ use Ibexa\Behat\Browser\Assert\ElementAssertInterface; use Ibexa\Behat\Browser\Element\ElementInterface; use Ibexa\Behat\Core\Debug\InteractiveDebuggerTrait; -use PHPUnit\Framework\ExpectationFailedException; +use Webmozart\Assert\InvalidArgumentException; class ElementAssert implements ElementAssertInterface { @@ -29,7 +29,7 @@ public function textEquals(string $expectedText): ElementInterface { try { return $this->baseElementAssert->textEquals($expectedText); - } catch (ExpectationFailedException $exception) { + } catch (InvalidArgumentException $exception) { return $this->startInteractiveSessionOnException($exception, true); } } @@ -38,7 +38,7 @@ public function textContains(string $expectedTextFragment): ElementInterface { try { return $this->baseElementAssert->textContains($expectedTextFragment); - } catch (ExpectationFailedException $exception) { + } catch (InvalidArgumentException $exception) { return $this->startInteractiveSessionOnException($exception, true); } } @@ -47,7 +47,7 @@ public function isVisible(): ElementInterface { try { return $this->baseElementAssert->isVisible(); - } catch (ExpectationFailedException $exception) { + } catch (InvalidArgumentException $exception) { return $this->startInteractiveSessionOnException($exception, true); } } @@ -56,7 +56,7 @@ public function hasClass(string $expectedClass): ElementInterface { try { return $this->baseElementAssert->hasClass($expectedClass); - } catch (ExpectationFailedException $exception) { + } catch (InvalidArgumentException $exception) { return $this->startInteractiveSessionOnException($exception, true); } } diff --git a/src/lib/Browser/Assert/ElementAssert.php b/src/lib/Browser/Assert/ElementAssert.php index a6fd27d5..2304d4cf 100644 --- a/src/lib/Browser/Assert/ElementAssert.php +++ b/src/lib/Browser/Assert/ElementAssert.php @@ -10,7 +10,7 @@ use Ibexa\Behat\Browser\Element\ElementInterface; use Ibexa\Behat\Browser\Locator\LocatorInterface; -use PHPUnit\Framework\Assert; +use Webmozart\Assert\Assert; class ElementAssert implements ElementAssertInterface { @@ -36,9 +36,9 @@ public function textEquals(string $expectedText): ElementInterface { $actualText = $this->element->getText(); - Assert::assertEquals( - $expectedText, + Assert::eq( $actualText, + $expectedText, sprintf( "Failed asserting that expected string '%s' is equal to actual '%s' for %s locator '%s': '%s'", $expectedText, @@ -56,9 +56,9 @@ public function textContains(string $expectedTextFragment): ElementInterface { $actualText = $this->element->getText(); - Assert::assertStringContainsString( - $expectedTextFragment, + Assert::contains( $actualText, + $expectedTextFragment, sprintf( "Failed asserting that expected text '%s' is found in actual text '%s' for %s locator '%s': '%s'", $expectedTextFragment, @@ -74,7 +74,7 @@ public function textContains(string $expectedTextFragment): ElementInterface public function isVisible(): ElementInterface { - Assert::assertTrue( + Assert::true( $this->element->isVisible(), sprintf( "Failed asserting that %s locator '%s': '%s' is visible", @@ -91,7 +91,7 @@ public function hasClass(string $expectedClass): ElementInterface { $actualClass = $this->element->getAttribute('class'); - Assert::assertTrue( + Assert::true( $this->element->hasClass($expectedClass), sprintf( "Failed asserting that element with %s locator '%s': '%s' has '%s' class, instead class is '%s'", diff --git a/src/lib/Browser/Context/BrowserContext.php b/src/lib/Browser/Context/BrowserContext.php index c1128da7..9826f1d7 100644 --- a/src/lib/Browser/Context/BrowserContext.php +++ b/src/lib/Browser/Context/BrowserContext.php @@ -12,7 +12,7 @@ use Behat\MinkExtension\Context\RawMinkContext; use DMore\ChromeDriver\ChromeDriver; use Ibexa\Behat\Core\Behat\ArgumentParser; -use PHPUnit\Framework\Assert; +use Webmozart\Assert\Assert; class BrowserContext extends RawMinkContext { @@ -44,7 +44,7 @@ public function responseHeadersContain(TableNode $expectedHeadersData): void $responseHeaders = $this->getSession()->getDriver()->getResponseHeaders(); foreach ($expectedHeadersData->getHash() as $row) { - Assert::assertEquals($row['Value'], $this->getHeaderValue($responseHeaders, $row['Header'])); + Assert::eq($this->getHeaderValue($responseHeaders, $row['Header']), $row['Value']); } } @@ -58,7 +58,7 @@ public function responseHeadersMatchPattern(TableNode $expectedHeadersData): voi foreach ($expectedHeadersData->getHash() as $row) { $expectedValuePattern = $row['Pattern']; $actualValue = $this->getHeaderValue($responseHeaders, $row['Header']); - Assert::assertEquals(1, preg_match($expectedValuePattern, $actualValue)); + Assert::eq(preg_match($expectedValuePattern, $actualValue), 1); } } diff --git a/src/lib/Browser/Element/Debug/Interactive/ElementCollection.php b/src/lib/Browser/Element/Debug/Interactive/ElementCollection.php index ed3845a1..858fbf09 100644 --- a/src/lib/Browser/Element/Debug/Interactive/ElementCollection.php +++ b/src/lib/Browser/Element/Debug/Interactive/ElementCollection.php @@ -16,8 +16,8 @@ use Ibexa\Behat\Browser\Element\Mapper\MapperInterface; use Ibexa\Behat\Browser\Exception\ElementNotFoundException; use Ibexa\Behat\Core\Debug\InteractiveDebuggerTrait; -use PHPUnit\Framework\ExpectationFailedException; use Traversable; +use Webmozart\Assert\InvalidArgumentException; class ElementCollection implements ElementCollectionInterface { @@ -95,7 +95,7 @@ public function single(): ElementInterface { try { return $this->baseElementCollection->single(); - } catch (ExpectationFailedException $exception) { + } catch (InvalidArgumentException $exception) { return $this->startInteractiveSessionOnException($exception, true); } } diff --git a/src/lib/Browser/Element/ElementCollection.php b/src/lib/Browser/Element/ElementCollection.php index a8e639dc..8465a415 100644 --- a/src/lib/Browser/Element/ElementCollection.php +++ b/src/lib/Browser/Element/ElementCollection.php @@ -14,8 +14,8 @@ use Ibexa\Behat\Browser\Element\Mapper\MapperInterface; use Ibexa\Behat\Browser\Exception\ElementNotFoundException; use Ibexa\Behat\Browser\Locator\LocatorInterface; -use PHPUnit\Framework\Assert; use Traversable; +use Webmozart\Assert\Assert; class ElementCollection implements ElementCollectionInterface { @@ -146,9 +146,9 @@ public function single(): ElementInterface if (!is_array($this->elements)) { $this->elements = iterator_to_array($this->elements); } - Assert::assertCount( - 1, + Assert::count( $this->elements, + 1, sprintf( "Failed asserting that collection created with %s locator '%s': '%s' has only one element", $this->locator->getType(), diff --git a/src/lib/Browser/Page/LoginPage.php b/src/lib/Browser/Page/LoginPage.php index b686a1d3..acd0b762 100644 --- a/src/lib/Browser/Page/LoginPage.php +++ b/src/lib/Browser/Page/LoginPage.php @@ -11,7 +11,7 @@ use Ibexa\Behat\Browser\Element\Criterion\ElementTextCriterion; use Ibexa\Behat\Browser\Element\Criterion\LogicalOrCriterion; use Ibexa\Behat\Browser\Locator\CSSLocator; -use PHPUnit\Framework\Assert; +use Webmozart\Assert\Assert; class LoginPage extends Page { @@ -37,12 +37,12 @@ public function loginSuccessfully( ->single() ->click(); - Assert::assertNotEquals('/login', $this->getSession()->getCurrentUrl()); + Assert::notEq($this->getSession()->getCurrentUrl(), '/login'); } public function verifyIsLoaded(): void { - Assert::assertStringContainsString($this->getRoute(), $this->getSession()->getCurrentUrl()); + Assert::contains($this->getSession()->getCurrentUrl(), $this->getRoute()); } public function getName(): string diff --git a/src/lib/Browser/Page/RedirectLoginPage.php b/src/lib/Browser/Page/RedirectLoginPage.php index 3e48f351..055a8c55 100644 --- a/src/lib/Browser/Page/RedirectLoginPage.php +++ b/src/lib/Browser/Page/RedirectLoginPage.php @@ -8,7 +8,7 @@ namespace Ibexa\Behat\Browser\Page; -use PHPUnit\Framework\Assert; +use Webmozart\Assert\Assert; class RedirectLoginPage extends LoginPage { @@ -19,7 +19,7 @@ public function getName(): string public function verifyIsLoaded(): void { - Assert::assertStringContainsString('/login', $this->getSession()->getCurrentUrl()); + Assert::contains($this->getSession()->getCurrentUrl(), '/login'); } public function loginSuccessfully( diff --git a/src/lib/Core/Context/TimeContext.php b/src/lib/Core/Context/TimeContext.php index 81536d5c..00b8efe3 100644 --- a/src/lib/Core/Context/TimeContext.php +++ b/src/lib/Core/Context/TimeContext.php @@ -9,8 +9,8 @@ namespace Ibexa\Behat\Core\Context; use Behat\Behat\Context\Context; -use PHPUnit\Framework\Assert; use Symfony\Component\Stopwatch\Stopwatch; +use Webmozart\Assert\Assert; class TimeContext implements Context { @@ -47,7 +47,7 @@ public function actionTookNoLongerThan(string $maxDuration): void $actualDuration = $this->stopwatch->getEvent('event')->getDuration() / 1000; $this->stopwatch->reset(); - Assert::assertLessThanOrEqual($maxDuration, $actualDuration); + Assert::lessThanEq($actualDuration, $maxDuration); } /** @@ -59,6 +59,6 @@ public function actionTookLongerThan(string $maxDuration): void $actualDuration = $this->stopwatch->getEvent('event')->getDuration() / 1000; $this->stopwatch->reset(); - Assert::assertGreaterThan($maxDuration, $actualDuration); + Assert::greaterThan($actualDuration, $maxDuration); } } diff --git a/src/lib/Subscriber/AbstractProcessStage.php b/src/lib/Subscriber/AbstractProcessStage.php index 914412e8..f788ee29 100644 --- a/src/lib/Subscriber/AbstractProcessStage.php +++ b/src/lib/Subscriber/AbstractProcessStage.php @@ -13,12 +13,12 @@ use Ibexa\Contracts\Core\Repository\PermissionResolver; use Ibexa\Contracts\Core\Repository\UserService; use Ibexa\Contracts\Core\Repository\Values\User\User; -use PHPUnit\Framework\Assert; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Contracts\EventDispatcher\Event; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; +use Webmozart\Assert\Assert; abstract class AbstractProcessStage { @@ -70,7 +70,7 @@ protected function transitionToNextStage($event) } if (!$chosenEvent) { - Assert::fail('No event was chosen, possible error in transition logic.'); + throw new \InvalidArgumentException('No event was chosen, possible error in transition logic.'); } $this->eventDispatcher->dispatch($event, $chosenEvent); @@ -96,7 +96,7 @@ protected function validateTransitions(): void $sum += $probability; } - Assert::assertEquals(1, $sum, 'Sum of all probabilities must be equal to 1.'); + Assert::eq($sum, 1, 'Sum of all probabilities must be equal to 1.'); } protected function getRandomValue(array $values): string diff --git a/tests/Browser/Element/Assert/CollectionAssertTest.php b/tests/Browser/Element/Assert/CollectionAssertTest.php index dfcc4b11..315e35e2 100644 --- a/tests/Browser/Element/Assert/CollectionAssertTest.php +++ b/tests/Browser/Element/Assert/CollectionAssertTest.php @@ -12,7 +12,8 @@ use Ibexa\Behat\Browser\Element\ElementCollection; use Ibexa\Behat\Browser\Locator\XPathLocator; use Ibexa\Tests\Behat\Browser\Element\BaseTestCase; -use PHPUnit\Framework\ExpectationFailedException; +use PHPUnit\Framework\Attributes\DataProvider; +use Webmozart\Assert\InvalidArgumentException; class CollectionAssertTest extends BaseTestCase { @@ -24,9 +25,7 @@ protected function setUp(): void $this->locator = new XPathLocator('locator', '//'); } - /** - * @dataProvider provideForTestAssertionPasses - */ + #[DataProvider('provideForTestAssertionPasses')] public function testAssertionPasses( array $expectedElementTexts, array $actualElementTexts @@ -38,14 +37,12 @@ public function testAssertionPasses( self::assertSame($collection, $returnedCollection); } - /** - * @dataProvider provideForTestAssertionFails - */ + #[DataProvider('provideForTestAssertionFails')] public function testAssertionFails( array $expectedElementTexts, array $actualElementTexts ): void { - $this->expectException(ExpectationFailedException::class); + $this->expectException(InvalidArgumentException::class); $collectionAssert = new CollectionAssert($this->locator, $this->createElementCollection($actualElementTexts)); $collectionAssert->containsElementsWithText($expectedElementTexts); } diff --git a/tests/Browser/Locator/Validator/CssLocatorValidatorTest.php b/tests/Browser/Locator/Validator/CssLocatorValidatorTest.php index d8692b19..36bf4040 100644 --- a/tests/Browser/Locator/Validator/CssLocatorValidatorTest.php +++ b/tests/Browser/Locator/Validator/CssLocatorValidatorTest.php @@ -10,6 +10,7 @@ use Ibexa\Behat\Browser\Locator\CSSLocator; use Ibexa\Behat\Browser\Locator\Validator\CssLocatorValidator; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\CssSelector\Exception\ParseException; @@ -22,18 +23,14 @@ protected function setUp(): void $this->validator = new CssLocatorValidator(); } - /** - * @dataProvider provideValidSelectors - */ + #[DataProvider('provideValidSelectors')] public function testValidationPasses(string $selector): void { $this->validator->validate(new CSSLocator('test', $selector)); $this->expectNotToPerformAssertions(); } - /** - * @dataProvider provideInvalidSelectors - */ + #[DataProvider('provideInvalidSelectors')] public function testValidationFails(string $selector): void { $this->expectException(ParseException::class); diff --git a/tests/bundle/Form/RetryChoiceListFactoryTest.php b/tests/bundle/Form/RetryChoiceListFactoryTest.php index fa68db1a..fdb5f709 100644 --- a/tests/bundle/Form/RetryChoiceListFactoryTest.php +++ b/tests/bundle/Form/RetryChoiceListFactoryTest.php @@ -11,6 +11,7 @@ use ErrorException; use Ibexa\Bundle\Behat\Form\RetryChoiceListFactory; use Ibexa\Tests\Bundle\Behat\Form\Stub\UnstableChoiceListFactory; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Bridge\PhpUnit\ClockMock; use Symfony\Component\Form\ChoiceList\ChoiceListInterface; @@ -29,27 +30,21 @@ public function tearDown(): void ClockMock::withClockMock(false); } - /** - * @dataProvider provider - */ + #[DataProvider('provider')] public function testCreateListFromChoicesSuccess(int $numberOfFails): void { $retryChoiceListFactory = new RetryChoiceListFactory(new UnstableChoiceListFactory($numberOfFails)); self::assertEquals([], $retryChoiceListFactory->createListFromChoices([], null)->getChoices()); } - /** - * @dataProvider provider - */ + #[DataProvider('provider')] public function testCreateListFromLoaderSuccess(int $numberOfFails): void { $retryChoiceListFactory = new RetryChoiceListFactory(new UnstableChoiceListFactory($numberOfFails)); self::assertEquals([], $retryChoiceListFactory->createListFromLoader($this->createMock(ChoiceLoaderInterface::class))->getChoices()); } - /** - * @dataProvider provider - */ + #[DataProvider('provider')] public function testCreateViewSuccess(int $numberOfFails): void { $retryChoiceListFactory = new RetryChoiceListFactory(new UnstableChoiceListFactory($numberOfFails)); diff --git a/tests/lib/Browser/Element/Condition/ElementTransitionHasEndedConditionTest.php b/tests/lib/Browser/Element/Condition/ElementTransitionHasEndedConditionTest.php index 25ca923d..dae2f203 100644 --- a/tests/lib/Browser/Element/Condition/ElementTransitionHasEndedConditionTest.php +++ b/tests/lib/Browser/Element/Condition/ElementTransitionHasEndedConditionTest.php @@ -68,12 +68,12 @@ private function createChildElement( ): ElementInterface { $childElement = self::createStub(ElementInterface::class); $childElement->method('getText')->willReturn('ChildText'); - $childElement->method('hasClass')->will(self::returnValueMap( + $childElement->method('hasClass')->willReturnMap( [ ['ibexa-selenium-transition-started', $hasStartedTransition], ['ibexa-selenium-transition-ended', $hasEndedTransition], ] - )); + ); return $childElement; } diff --git a/tests/lib/Browser/Element/Criterion/ChildElementTextCriterionTest.php b/tests/lib/Browser/Element/Criterion/ChildElementTextCriterionTest.php index b9cb7c6e..257363b2 100644 --- a/tests/lib/Browser/Element/Criterion/ChildElementTextCriterionTest.php +++ b/tests/lib/Browser/Element/Criterion/ChildElementTextCriterionTest.php @@ -14,12 +14,11 @@ use Ibexa\Behat\Browser\Locator\XPathLocator; use Ibexa\Tests\Behat\Browser\Element\BaseTestCase; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; class ChildElementTextCriterionTest extends BaseTestCase { - /** - * @dataProvider dataProviderTestMatches - */ + #[DataProvider('dataProviderTestMatches')] public function testMatches( LocatorInterface $locator, string $childElementText, diff --git a/tests/lib/Browser/Element/Criterion/ElementAttributeCriterionTest.php b/tests/lib/Browser/Element/Criterion/ElementAttributeCriterionTest.php index 0fb4a4e6..275f2640 100644 --- a/tests/lib/Browser/Element/Criterion/ElementAttributeCriterionTest.php +++ b/tests/lib/Browser/Element/Criterion/ElementAttributeCriterionTest.php @@ -13,12 +13,11 @@ use Ibexa\Behat\Browser\Locator\CSSLocator; use Ibexa\Tests\Behat\Browser\Element\BaseTestCase; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; class ElementAttributeCriterionTest extends BaseTestCase { - /** - * @dataProvider dataProviderTestMatches - */ + #[DataProvider('dataProviderTestMatches')] public function testMatches( string $attributeName, string $attributeValue, diff --git a/tests/lib/Browser/Element/Criterion/ElementTextCriterionTest.php b/tests/lib/Browser/Element/Criterion/ElementTextCriterionTest.php index dcf9dfa9..5086d993 100644 --- a/tests/lib/Browser/Element/Criterion/ElementTextCriterionTest.php +++ b/tests/lib/Browser/Element/Criterion/ElementTextCriterionTest.php @@ -12,12 +12,11 @@ use Ibexa\Behat\Browser\Locator\CSSLocator; use Ibexa\Tests\Behat\Browser\Element\BaseTestCase; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; class ElementTextCriterionTest extends BaseTestCase { - /** - * @dataProvider dataProviderTestMatches - */ + #[DataProvider('dataProviderTestMatches')] public function testMatches( string $elementText, bool $shouldMatch diff --git a/tests/lib/Browser/Element/Criterion/ElementTextFragmentCriterionTest.php b/tests/lib/Browser/Element/Criterion/ElementTextFragmentCriterionTest.php index d294b2e1..ea7a4190 100644 --- a/tests/lib/Browser/Element/Criterion/ElementTextFragmentCriterionTest.php +++ b/tests/lib/Browser/Element/Criterion/ElementTextFragmentCriterionTest.php @@ -12,12 +12,11 @@ use Ibexa\Behat\Browser\Locator\CSSLocator; use Ibexa\Tests\Behat\Browser\Element\BaseTestCase; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; class ElementTextFragmentCriterionTest extends BaseTestCase { - /** - * @dataProvider dataProviderTestMatches - */ + #[DataProvider('dataProviderTestMatches')] public function testMatches( string $elementText, bool $shouldMatch diff --git a/tests/lib/Browser/Element/ElementCollectionTest.php b/tests/lib/Browser/Element/ElementCollectionTest.php index 15283181..4f37c1fe 100644 --- a/tests/lib/Browser/Element/ElementCollectionTest.php +++ b/tests/lib/Browser/Element/ElementCollectionTest.php @@ -16,6 +16,7 @@ use Ibexa\Behat\Browser\Locator\CSSLocator; use Ibexa\Behat\Browser\Locator\LocatorInterface; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; class ElementCollectionTest extends BaseTestCase { @@ -61,9 +62,7 @@ public function testCount(): void Assert::assertEquals(3, $this->collection->count()); } - /** - * @dataProvider dataProviderTestAny - */ + #[DataProvider('dataProviderTestAny')] public function testAny( LocatorInterface $locator, array $elementNames, @@ -89,9 +88,7 @@ public static function dataProviderTestAny(): array ]; } - /** - * @dataProvider dataProviderTestEmpty - */ + #[DataProvider('dataProviderTestEmpty')] public function testEmpty( LocatorInterface $locator, array $elementNames, diff --git a/tests/lib/Browser/Element/ElementTest.php b/tests/lib/Browser/Element/ElementTest.php index 7d05e518..22d8d9cc 100644 --- a/tests/lib/Browser/Element/ElementTest.php +++ b/tests/lib/Browser/Element/ElementTest.php @@ -18,6 +18,7 @@ use Ibexa\Behat\Browser\Locator\LocatorInterface; use Ibexa\Behat\Browser\Locator\VisibleCSSLocator; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; class ElementTest extends BaseTestCase { @@ -132,9 +133,7 @@ public function testWaitUntilConditionWhenNotMet(): void $element->waitUntilCondition(new ElementExistsCondition($searchedElement, $this->irrelevantLocator)); } - /** - * @dataProvider dataProvidertestAdditionalLocatorConditionsAreAppliedWhenUsingFind - */ + #[DataProvider('dataProvidertestAdditionalLocatorConditionsAreAppliedWhenUsingFind')] public function testAdditionalLocatorConditionsAreAppliedWhenUsingFind( LocatorInterface $locator, string $expectedElementText @@ -158,9 +157,7 @@ public static function dataProvidertestAdditionalLocatorConditionsAreAppliedWhen ]; } - /** - * @dataProvider dataProvidertestAdditionalLocatorConditionsAreAppliedWhenUsingFindAll - */ + #[DataProvider('dataProvidertestAdditionalLocatorConditionsAreAppliedWhenUsingFindAll')] public function testAdditionalLocatorConditionsAreAppliedWhenUsingFindAll( LocatorInterface $locator, int $expectedElementCount diff --git a/tests/lib/Core/Behat/ArgumentParserTest.php b/tests/lib/Core/Behat/ArgumentParserTest.php index ec857025..687b96dd 100644 --- a/tests/lib/Core/Behat/ArgumentParserTest.php +++ b/tests/lib/Core/Behat/ArgumentParserTest.php @@ -12,6 +12,7 @@ use Ibexa\Behat\Browser\Environment\ParameterProvider; use Ibexa\Behat\Core\Behat\ArgumentParser; use PHPUnit\Framework\Assert; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -21,9 +22,7 @@ */ class ArgumentParserTest extends TestCase { - /** - * @dataProvider provideUrlData - */ + #[DataProvider('provideUrlData')] public function testParserGivenUrlCorrectly( string $valueToParse, string $expectedResult