Skip to content

Commit c756be1

Browse files
authored
IBX-11766: Replaced phpunit assertions with webmozart equivalents (#1920)
* IBX-11766 composer require --dev webmozart/assert:^2.3 * IBX-11766 Replaced phpunit assertions with these from webmozart library * IBX-11766 Fixed code styles * IBX-11766 Removed not neccesary "\" before RuntimeException
1 parent 660c18d commit c756be1

62 files changed

Lines changed: 255 additions & 254 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
"phpstan/phpstan": "^2.0",
7474
"phpstan/phpstan-phpunit": "^2.0",
7575
"phpstan/phpstan-symfony": "^2.0",
76-
"phpunit/phpunit": "^9.5"
76+
"phpunit/phpunit": "^9.5",
77+
"webmozart/assert": "^2.3"
7778
},
7879
"config": {
7980
"allow-plugins": {

src/lib/Behat/BrowserContext/BookmarkContext.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Behat\Behat\Context\Context;
1212
use Ibexa\AdminUi\Behat\Page\BookmarksPage;
1313
use Ibexa\AdminUi\Behat\Page\ContentViewPage;
14-
use PHPUnit\Framework\Assert;
14+
use Webmozart\Assert\Assert;
1515

1616
final readonly class BookmarkContext implements Context
1717
{
@@ -36,23 +36,23 @@ public function bookmarkContentItem(string $path): void
3636
*/
3737
public function contentItemIsBookmarked(): void
3838
{
39-
Assert::assertTrue($this->contentViewPage->isBookmarked());
39+
Assert::true($this->contentViewPage->isBookmarked());
4040
}
4141

4242
/**
4343
* @Given there's a :contentName Content Item on Bookmarks list
4444
*/
4545
public function contentItemIsDisplayed(string $contentName): void
4646
{
47-
Assert::assertTrue($this->bookmarksPage->isBookmarked($contentName));
47+
Assert::true($this->bookmarksPage->isBookmarked($contentName));
4848
}
4949

5050
/**
5151
* @Given there's no :contentName Content Item on Bookmarks list
5252
*/
5353
public function contentItemIsNotDisplayed(string $contentName): void
5454
{
55-
Assert::assertFalse($this->bookmarksPage->isBookmarked($contentName));
55+
Assert::false($this->bookmarksPage->isBookmarked($contentName));
5656
}
5757

5858
/**

src/lib/Behat/BrowserContext/ContentActionsMenuContext.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Behat\Behat\Context\Context;
1212
use Behat\Gherkin\Node\TableNode;
1313
use Ibexa\AdminUi\Behat\Component\ContentActionsMenu;
14-
use PHPUnit\Framework\Assert;
14+
use Webmozart\Assert\Assert;
1515

1616
final readonly class ContentActionsMenuContext implements Context
1717
{
@@ -35,7 +35,7 @@ public function clickEditActionBar(string $buttonName, ?string $groupName = null
3535
public function theButtonsAreDisabled(TableNode $buttons): void
3636
{
3737
foreach ($buttons->getHash() as $button) {
38-
Assert::assertFalse($this->contentActionsMenu->isButtonActive($button['buttonName']));
38+
Assert::false($this->contentActionsMenu->isButtonActive($button['buttonName']));
3939
}
4040
}
4141

@@ -44,14 +44,14 @@ public function theButtonsAreDisabled(TableNode $buttons): void
4444
*/
4545
public function buttonIsNotVisible(string $buttonName): void
4646
{
47-
Assert::assertFalse($this->contentActionsMenu->isButtonVisible($buttonName));
47+
Assert::false($this->contentActionsMenu->isButtonVisible($buttonName));
4848
}
4949

5050
/**
5151
* @Given the :buttonName button is visible
5252
*/
5353
public function buttonIsVisible(string $buttonName): void
5454
{
55-
Assert::assertTrue($this->contentActionsMenu->isButtonVisible($buttonName));
55+
Assert::true($this->contentActionsMenu->isButtonVisible($buttonName));
5656
}
5757
}

src/lib/Behat/BrowserContext/ContentTypeContext.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Ibexa\AdminUi\Behat\Page\ContentTypeGroupsPage;
1515
use Ibexa\AdminUi\Behat\Page\ContentTypePage;
1616
use Ibexa\AdminUi\Behat\Page\ContentTypeUpdatePage;
17-
use PHPUnit\Framework\Assert;
17+
use Webmozart\Assert\Assert;
1818

1919
final readonly class ContentTypeContext implements Context
2020
{
@@ -32,7 +32,7 @@ public function __construct(
3232
public function contentTypeHasProperGlobalProperties(TableNode $table): void
3333
{
3434
foreach ($table->getHash() as $row) {
35-
Assert::assertTrue($this->contentTypePage->hasProperty($row['label'], $row['value']));
35+
Assert::true($this->contentTypePage->hasProperty($row['label'], $row['value']));
3636
}
3737
}
3838

@@ -58,7 +58,7 @@ public function createNewContentTypeGroup(): void
5858
public function contentTypeHasProperFields(TableNode $table): void
5959
{
6060
foreach ($table->getHash() as $row) {
61-
Assert::assertTrue($this->contentTypePage->hasFieldType(
61+
Assert::true($this->contentTypePage->hasFieldType(
6262
['Name' => $row['fieldName'], 'Type' => $row['fieldType']]
6363
));
6464
}
@@ -69,31 +69,31 @@ public function contentTypeHasProperFields(TableNode $table): void
6969
*/
7070
public function thereSNoOnContentTypesList(string $contentTypeName): void
7171
{
72-
Assert::assertFalse($this->contentTypeGroupPage->isContentTypeOnTheList($contentTypeName));
72+
Assert::false($this->contentTypeGroupPage->isContentTypeOnTheList($contentTypeName));
7373
}
7474

7575
/**
7676
* @Given there's no :contentTypeGroupName content type group on content type groups list
7777
*/
7878
public function thereSNoOnContentTypesGroupList(string $contentTypeGroupName): void
7979
{
80-
Assert::assertFalse($this->contentTypeGroupsPage->isContentTypeGroupOnTheList($contentTypeGroupName));
80+
Assert::false($this->contentTypeGroupsPage->isContentTypeGroupOnTheList($contentTypeGroupName));
8181
}
8282

8383
/**
8484
* @Given there's a :contentTypeGroupName content type group on content type groups list
8585
*/
8686
public function thereSAOnContentTypesGroupList(string $contentTypeGroupName): void
8787
{
88-
Assert::assertTrue($this->contentTypeGroupsPage->isContentTypeGroupOnTheList($contentTypeGroupName));
88+
Assert::true($this->contentTypeGroupsPage->isContentTypeGroupOnTheList($contentTypeGroupName));
8989
}
9090

9191
/**
9292
* @Given there's a :contentTypeName on content types list
9393
*/
9494
public function thereAContentTypeOnContentTypesList(string $contentTypeName): void
9595
{
96-
Assert::assertTrue($this->contentTypeGroupPage->isContentTypeOnTheList($contentTypeName));
96+
Assert::true($this->contentTypeGroupPage->isContentTypeOnTheList($contentTypeName));
9797
}
9898

9999
/**
@@ -187,31 +187,31 @@ public function iShouldBeOnContentTypePage(string $contentTypeName): void
187187
*/
188188
public function thereAreNoContentTypes(): void
189189
{
190-
Assert::assertFalse($this->contentTypeGroupPage->hasContentTypes());
190+
Assert::false($this->contentTypeGroupPage->hasContentTypes());
191191
}
192192

193193
/**
194194
* @Then there's an empty :contentTypeGroupName content type group on content type groups list
195195
*/
196196
public function thereIsAnEmptyContentTypeGroup(string $contentTypeGroupName): void
197197
{
198-
Assert::assertFalse($this->contentTypeGroupPage->hasAssignedContentItems($contentTypeGroupName));
198+
Assert::false($this->contentTypeGroupPage->hasAssignedContentItems($contentTypeGroupName));
199199
}
200200

201201
/**
202202
* @Then there's non-empty :contentTypeGroupName content type group on content type groups list
203203
*/
204204
public function thereIsANonEmptyContentTypeGroup(string $contentTypeGroupName): void
205205
{
206-
Assert::assertTrue($this->contentTypeGroupPage->hasAssignedContentItems($contentTypeGroupName));
206+
Assert::true($this->contentTypeGroupPage->hasAssignedContentItems($contentTypeGroupName));
207207
}
208208

209209
/**
210210
* @Then content type group :contentTypeGroupName cannot be selected
211211
*/
212212
public function contentTypeGroupCannotBeSelected(string $contentTypeGroupName): void
213213
{
214-
Assert::assertFalse($this->contentTypeGroupsPage->canBeSelected($contentTypeGroupName));
214+
Assert::false($this->contentTypeGroupsPage->canBeSelected($contentTypeGroupName));
215215
}
216216

217217
/**

src/lib/Behat/BrowserContext/ContentUpdateContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Ibexa\AdminUi\Behat\Component\Fields\NonEditableField;
1414
use Ibexa\AdminUi\Behat\Page\ContentUpdateItemPage;
1515
use Ibexa\AdminUi\Behat\Page\UserUpdatePage;
16-
use PHPUnit\Framework\Assert;
16+
use Webmozart\Assert\Assert;
1717

1818
final readonly class ContentUpdateContext implements Context
1919
{
@@ -50,7 +50,7 @@ public function fieldContainsValidationError(string $fieldName, string $errorMes
5050
public function verifyFieldIsNotEditable(string $fieldName): void
5151
{
5252
$field = $this->contentUpdateItemPage->getField($fieldName);
53-
Assert::assertEquals(NonEditableField::EXPECTED_NON_EDITABLE_TEXT, $field->getValue()[0]);
53+
Assert::eq($field->getValue()[0], NonEditableField::EXPECTED_NON_EDITABLE_TEXT);
5454
}
5555

5656
/**

src/lib/Behat/BrowserContext/ContentViewContext.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Ibexa\AdminUi\Behat\Component\DraftConflictDialog;
1414
use Ibexa\AdminUi\Behat\Page\ContentViewPage;
1515
use Ibexa\Behat\Core\Behat\ArgumentParser;
16-
use PHPUnit\Framework\Assert;
16+
use Webmozart\Assert\Assert;
1717

1818
final readonly class ContentViewContext implements Context
1919
{
@@ -107,7 +107,7 @@ public function startEditingContent(?string $language = null): void
107107
public function verifyThereIsItemInSubItemList(string $itemName, string $itemType): void
108108
{
109109
$this->contentViewPage->verifyIsLoaded();
110-
Assert::assertTrue($this->contentViewPage->isChildElementPresent(['Name' => $itemName, 'Content type' => $itemType]));
110+
Assert::true($this->contentViewPage->isChildElementPresent(['Name' => $itemName, 'Content type' => $itemType]));
111111
}
112112

113113
/**
@@ -116,7 +116,7 @@ public function verifyThereIsItemInSubItemList(string $itemName, string $itemTyp
116116
public function verifyThereIsNoItemInSubItemListInRoot(string $itemName, string $itemType): void
117117
{
118118
$this->contentViewPage->verifyIsLoaded();
119-
Assert::assertFalse($this->contentViewPage->isChildElementPresent(['Name' => $itemName, 'Content type' => $itemType]));
119+
Assert::false($this->contentViewPage->isChildElementPresent(['Name' => $itemName, 'Content type' => $itemType]));
120120
}
121121

122122
/**
@@ -181,7 +181,7 @@ public function iCreateNewUrlAlias(string $path, string $languageName, string $r
181181
*/
182182
public function verifyUrlAliasExists(string $path, string $type): void
183183
{
184-
Assert::assertTrue(
184+
Assert::true(
185185
$this->contentViewPage->isUrlAliasOnTheList($path, $type),
186186
sprintf('Url alias "%s" with type "%s" not found', $path, $type)
187187
);

src/lib/Behat/BrowserContext/DashboardContext.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Ibexa\AdminUi\Behat\Component\UpperMenu;
1313
use Ibexa\AdminUi\Behat\Page\ContentUpdateItemPage;
1414
use Ibexa\AdminUi\Behat\Page\DashboardPage;
15-
use PHPUnit\Framework\Assert;
15+
use Webmozart\Assert\Assert;
1616

1717
final readonly class DashboardContext implements Context
1818
{
@@ -36,15 +36,15 @@ public function iGoToDashboard(): void
3636
*/
3737
public function goingToDashboardISeeDraft(string $draftName): void
3838
{
39-
Assert::assertTrue($this->dashboardPage->isDraftOnList($draftName));
39+
Assert::true($this->dashboardPage->isDraftOnList($draftName));
4040
}
4141

4242
/**
4343
* @Then there's no draft :draftName on Dashboard list
4444
*/
4545
public function goingToDashboardISeeNoDraft(string $draftName): void
4646
{
47-
Assert::assertFalse($this->dashboardPage->isDraftOnList($draftName));
47+
Assert::false($this->dashboardPage->isDraftOnList($draftName));
4848
}
4949

5050
/**

src/lib/Behat/BrowserContext/LanguageContext.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Behat\Gherkin\Node\TableNode;
1313
use Ibexa\AdminUi\Behat\Page\LanguagePage;
1414
use Ibexa\AdminUi\Behat\Page\LanguagesPage;
15-
use PHPUnit\Framework\Assert;
15+
use Webmozart\Assert\Assert;
1616

1717
final readonly class LanguageContext implements Context
1818
{
@@ -35,7 +35,7 @@ public function deleteLanguage(): void
3535
*/
3636
public function thereSNoLanguageOnLanguageList(string $languageName): void
3737
{
38-
Assert::assertFalse($this->languagesPage->isLanguageOnTheList($languageName));
38+
Assert::false($this->languagesPage->isLanguageOnTheList($languageName));
3939
}
4040

4141
/**
@@ -51,7 +51,7 @@ public function deleteLanguageNamed(string $languageName): void
5151
*/
5252
public function thereALanguageOnLanguageList(string $languageName): void
5353
{
54-
Assert::assertTrue($this->languagesPage->isLanguageOnTheList($languageName));
54+
Assert::true($this->languagesPage->isLanguageOnTheList($languageName));
5555
}
5656

5757
/**
@@ -72,7 +72,7 @@ public function languageHasProperAttributes(TableNode $languageData): void
7272
$expectedCode = $languageData->getHash()[0]['Language code'];
7373
$expectedEnabledFlag = $languageData->getHash()[0]['Enabled'];
7474

75-
Assert::assertTrue(
75+
Assert::true(
7676
$this->languagePage->hasProperties([
7777
'Name' => $expectedName,
7878
'Language code' => $expectedCode,

src/lib/Behat/BrowserContext/MyDraftsContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use Behat\Behat\Context\Context;
1212
use Ibexa\AdminUi\Behat\Page\MyDraftsPage;
13-
use PHPUnit\Framework\Assert;
13+
use Webmozart\Assert\Assert;
1414

1515
final readonly class MyDraftsContext implements Context
1616
{
@@ -32,7 +32,7 @@ public function iDeleteADraftFromTheList(string $draftName): void
3232
*/
3333
public function iSeeTheDraftIsDeleted(string $draftName): void
3434
{
35-
Assert::assertFalse($this->myDraftsPage->isDraftOnTheList($draftName));
35+
Assert::false($this->myDraftsPage->isDraftOnTheList($draftName));
3636
}
3737

3838
/**

src/lib/Behat/BrowserContext/NotificationContext.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use Behat\Behat\Context\Context;
1212
use Ibexa\AdminUi\Behat\Component\Notification;
13-
use PHPUnit\Framework\Assert;
13+
use Webmozart\Assert\Assert;
1414

1515
/** Context for actions on notifications */
1616
final readonly class NotificationContext implements Context
@@ -29,7 +29,7 @@ public function notificationAppears(string $itemType, string $itemName, string $
2929

3030
$this->notification->verifyIsLoaded();
3131
$this->notification->verifyAlertSuccess();
32-
Assert::assertEquals($expectedMessage, $this->notification->getMessage());
32+
Assert::eq($this->notification->getMessage(), $expectedMessage);
3333
$this->notification->closeAlert();
3434
}
3535

@@ -62,7 +62,7 @@ public function specificErrorNotificationAppears(string $message): void
6262
{
6363
$this->notification->verifyIsLoaded();
6464
$this->notification->verifyAlertFailure();
65-
Assert::assertStringContainsString($message, $this->notification->getMessage());
65+
Assert::contains($this->notification->getMessage(), $message);
6666
$this->notification->closeAlert();
6767
}
6868
}

0 commit comments

Comments
 (0)