diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c76b628e..dd44f8e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,9 @@ jobs: steps: - name: Checkout source uses: actions/checkout@v1 + - name: Install symfony/clock + run: composer require --dev symfony/clock + if: ${{ matrix.php-version != '7.4' && matrix.php-version != '8.0' }} - name: Validate composer config run: composer validate - name: Install dependencies @@ -50,7 +53,7 @@ jobs: nohup php -S 0.0.0.0:8080 -t features/fixtures/project/web > features/fixtures/project/var/logs/server.log 2>&1 & sleep 5 - name: Functional tests - run: vendor/bin/behat --no-snippets --format=progress --profile=travis -vvv + run: vendor/bin/behat --no-snippets --format=progress --profile=actions -vvv - name: Upload logs uses: actions/upload-artifact@master with: diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d869ce4b..00000000 --- a/.travis.yml +++ /dev/null @@ -1,57 +0,0 @@ -language: php - -cache: - directories: - - $HOME/.composer/cache - - vendor - -dist: focal - -addons: - firefox: "47.0.1" - apt: - packages: - - "libonig5" - -services: - - xvfb - -env: - global: - - COMPOSER_MEMORY_LIMIT=-1 - -matrix: - include: - - php: 7.4 - env: - - COMPOSER_FLAGS='--prefer-lowest' - - php: 7.4 - - php: 8.0 - - php: 8.1 - before_install: - - composer require --dev symfony/clock - - php: 8.2 - before_install: - - composer require --dev symfony/clock - - php: 8.3 - before_install: - - composer require --dev symfony/clock - -install: - - phpenv config-rm xdebug.ini - - composer update $COMPOSER_FLAGS - - wget --no-clobber -O vendor/bin/selenium.jar http://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.1.jar || true - -before_script: - - nohup php -S localhost:8080 -t features/fixtures/project/web > /dev/null 2>&1 & - - java -jar vendor/bin/selenium.jar > /dev/null 2>&1 & - - sleep 5 - - features/fixtures/project/bin/console assets:install features/fixtures/project/web --relative --symlink - -script: - - composer sniffer - - composer stan - - composer spec - - vendor/bin/behat --no-snippets --format=progress --profile=travis -vvv - -after_failure: cat features/fixtures/project/var/logs/test.log diff --git a/Behat/Context/AdminContext.php b/Behat/Context/AdminContext.php index 753e31c7..98b87706 100644 --- a/Behat/Context/AdminContext.php +++ b/Behat/Context/AdminContext.php @@ -11,6 +11,7 @@ namespace FSi\Bundle\AdminBundle\Behat\Context; +use Assert\Assertion; use Behat\Gherkin\Node\TableNode; use Behat\Mink\Session; use Doctrine\ORM\EntityManagerInterface; @@ -63,10 +64,10 @@ public function theFollowingAdminElementsWereRegistered(TableNode $table): void foreach ($table->getHash() as $serviceRow) { $id = $serviceRow['Id']; $class = $serviceRow['Class']; - expect($this->manager->hasElement($id))->toBe(true); - expect($this->manager->getElement($id))->toBeAnInstanceOf($class); + Assertion::true($this->manager->hasElement($id)); + Assertion::isInstanceOf($this->manager->getElement($id), $class); if (true === array_key_exists('Parent', $serviceRow) && '' !== $serviceRow['Parent']) { - expect($this->manager->getElement($id)->getParentId())->toBe($serviceRow['Parent']); + Assertion::same($this->manager->getElement($id)->getParentId(), $serviceRow['Parent']); } } } @@ -79,8 +80,8 @@ public function elementHaveFollowingOptionsDefined(AbstractElement $adminElement foreach ($options->getHash() as $optionRow) { $option = $optionRow['Option']; $value = $optionRow['Value']; - expect($adminElement->hasOption($option))->toBe(true); - expect($adminElement->getOption($option))->toBe($value); + Assertion::true($adminElement->hasOption($option)); + Assertion::eq($adminElement->getOption($option), $value); } } @@ -92,8 +93,8 @@ public function thereAreFollowingAdminElementsAvailable(TableNode $table): void foreach ($table->getHash() as $elementRow) { $id = $elementRow['Id']; $name = $elementRow['Name']; - expect($this->manager->hasElement($id))->toBe(true); - expect($this->manager->getElement($id)->getName())->toBe($name); + Assertion::true($this->manager->hasElement($id)); + Assertion::same($this->manager->getElement($id)->getName(), $name); } } @@ -102,7 +103,7 @@ public function thereAreFollowingAdminElementsAvailable(TableNode $table): void */ public function iShouldSeeTitleAtTopBar($navbarBrandText): void { - expect($this->getPage(AdminPanel::class)->getNavbarBrandText())->toBe($navbarBrandText); + Assertion::eq($this->getPage(AdminPanel::class)->getNavbarBrandText(), $navbarBrandText); } /** @@ -110,7 +111,7 @@ public function iShouldSeeTitleAtTopBar($navbarBrandText): void */ public function iShouldSeePageHeader(Page $page, $headerContent): void { - expect($page->getHeader())->toBe($headerContent); + Assertion::eq($page->getHeader(), $headerContent); } /** @@ -118,7 +119,7 @@ public function iShouldSeePageHeader(Page $page, $headerContent): void */ public function translationsAreEnabledInApplication(): void { - expect($this->translator)->toBeAnInstanceOf(TranslatorInterface::class); + Assertion::isInstanceOf($this->translator, TranslatorInterface::class); } /** @@ -127,7 +128,7 @@ public function translationsAreEnabledInApplication(): void */ public function iShouldSeeLanguageDropdownButtonInNavigationBarWithText($button): void { - expect($this->getPage(AdminPanel::class)->getLanguageDropdown()->hasLink($button))->toBe(true); + Assertion::true($this->getPage(AdminPanel::class)->getLanguageDropdown()->hasLink($button)); } /** @@ -138,7 +139,7 @@ public function languageDropdownButtonShouldHaveFollowingLinks(TableNode $dropdo $links = $this->getPage(AdminPanel::class)->getLanguageDropdownOptions(); foreach ($dropdownLinks->getHash() as $link) { - expect($links)->toContain($link['Link']); + Assertion::inArray($link['Link'], $links); } } diff --git a/Behat/Context/DataContext.php b/Behat/Context/DataContext.php index a5498f69..2e7cbadf 100644 --- a/Behat/Context/DataContext.php +++ b/Behat/Context/DataContext.php @@ -11,6 +11,7 @@ namespace FSi\Bundle\AdminBundle\Behat\Context; +use Assert\Assertion; use Behat\Gherkin\Node\TableNode; use Behat\Mink\Session; use DateTime; @@ -29,7 +30,6 @@ use function array_key_exists; use function count; -use function expect; use function file_exists; class DataContext extends AbstractContext @@ -99,6 +99,8 @@ public function entityToClassName(string $entityName): string return Subscriber::class; case 'person': return Person::class; + default: + throw new InvalidArgumentException(sprintf('Unknown entity name "%s"', $entityName)); } } @@ -118,7 +120,7 @@ public function thereIsNumberOfEntities(int $count, string $className): void $entityManager->flush(); - expect(count($this->getRepository($className)->findAll()))->toBe($count); + Assertion::count($this->getRepository($className)->findAll(), $count); } /** @@ -138,7 +140,7 @@ public function thereIsAnEntityWithField(string $className, string $field, $valu $entityManager->persist($instance); $entityManager->flush(); - expect($this->getRepository($className)->findOneBy([$field => $value]))->toBeAnInstanceOf($className); + Assertion::isInstanceOf($this->getRepository($className)->findOneBy([$field => $value]), $className); } /** @@ -146,7 +148,7 @@ public function thereIsAnEntityWithField(string $className, string $field, $valu */ public function entityWithFieldShouldExist(string $className, string $field, $value): void { - expect($this->getRepository($className)->findOneBy([$field => $value]))->toBeAnInstanceOf($className); + Assertion::isInstanceOf($this->getRepository($className)->findOneBy([$field => $value]), $className); } /** @@ -154,7 +156,7 @@ public function entityWithFieldShouldExist(string $className, string $field, $va */ public function entityShouldNotExistInDatabaseAnymore(string $className, string $field, $value): void { - expect($this->getRepository($className)->findOneBy([$field => $value]))->toBe(null); + Assertion::null($this->getRepository($className)->findOneBy([$field => $value])); } /** @@ -178,7 +180,7 @@ public function thereShouldNotBeAnyEntities(string $className): void */ public function thereShouldExistsNumberOfEntities($count, string $className): void { - expect(count($this->getRepository($className)->findAll()))->toBe($count); + Assertion::count($this->getRepository($className)->findAll(), $count); } /** @@ -237,7 +239,7 @@ public function entityShouldHaveElementsInCollection( $entity = $this->getRepository($className)->findOneBy([$field => $value]); $this->getEntityManager()->refresh($entity); - expect(count($this->getEntityField($entity, $collectionName)))->toBe($expectedCount); + Assertion::count($this->getEntityField($entity, $collectionName), $expectedCount); } /** @@ -248,7 +250,7 @@ public function entityWithIdShouldHaveChangedField(string $className, $id, strin $entity = $this->getRepository($className)->find($id); $this->getEntityManager()->refresh($entity); - expect($this->getEntityField($entity, $field))->toBe($value); + Assertion::eq($this->getEntityField($entity, $field), $value); } /** @@ -259,7 +261,7 @@ public function entityWithIdShouldNotHaveChangedFieldValue(string $className, $i $entity = $this->getRepository($className)->find($id); $this->getEntityManager()->refresh($entity); - expect($this->getEntityField($entity, $field))->notToBe($value); + Assertion::notEq($this->getEntityField($entity, $field), $value); } /** diff --git a/Behat/Context/DisplayContext.php b/Behat/Context/DisplayContext.php index 9068e7fc..fc0927b3 100644 --- a/Behat/Context/DisplayContext.php +++ b/Behat/Context/DisplayContext.php @@ -11,6 +11,7 @@ namespace FSi\Bundle\AdminBundle\Behat\Context; +use Assert\Assertion; use Behat\Gherkin\Node\TableNode; use FSi\Bundle\AdminBundle\Behat\Element\Display; @@ -23,7 +24,7 @@ public function iShouldSeeDisplayWithFollowingFields(TableNode $table): void { $display = $this->getElement(Display::class); foreach ($table->getHash() as $row) { - expect($display->hasFieldWithName($row['Field name']))->toBe(true); + Assertion::true($display->hasFieldWithName($row['Field name']), true); } } } diff --git a/Behat/Context/FiltersContext.php b/Behat/Context/FiltersContext.php index 6f75e2be..6f4f8675 100644 --- a/Behat/Context/FiltersContext.php +++ b/Behat/Context/FiltersContext.php @@ -11,6 +11,7 @@ namespace FSi\Bundle\AdminBundle\Behat\Context; +use Assert\Assertion; use Behat\Gherkin\Node\TableNode; use FSi\Bundle\AdminBundle\Admin\CRUD\ListElement as AdminListElement; use FSi\Bundle\AdminBundle\Behat\Element\Filters; @@ -31,7 +32,7 @@ class FiltersContext extends AbstractContext */ public function elementDatasourceMaxResultsIsSet(AdminListElement $adminElement, $maxResults): void { - expect($this->getDataSource($adminElement)->getMaxResults())->toBe($maxResults); + Assertion::eq($this->getDataSource($adminElement)->getMaxResults(), $maxResults); } /** @@ -41,7 +42,7 @@ public function elementHaveDatasourceWithFields(AdminListElement $adminElement): { $dataSource = $this->getDataSource($adminElement); - expect(count($dataSource->getFields()) > 0)->toBe(true); + Assertion::true(count($dataSource->getFields()) > 0); } /** @@ -58,7 +59,7 @@ public function elementHaveDatasourceWithoutFilters(AdminListElement $adminEleme break; } } - expect($filters)->toBe(false); + Assertion::false($filters); } /** @@ -66,7 +67,7 @@ public function elementHaveDatasourceWithoutFilters(AdminListElement $adminEleme */ public function bothSortingButtonsInColumnHeaderShouldBeActive($column): void { - expect($this->getListElement()->isColumnAscSortActive($column))->toBe(true); + Assertion::true($this->getListElement()->isColumnAscSortActive($column)); } /** @@ -86,10 +87,10 @@ public function buttonInColumnHeaderShouldBeDisabled($sort, $column): void switch (strtolower($sort)) { case 'sort asc': - expect($list->isColumnAscSortActive($column))->toBe(false); + Assertion::false($list->isColumnAscSortActive($column)); break; case 'sort desc': - expect($list->isColumnDescSortActive($column))->toBe(false); + Assertion::false($list->isColumnDescSortActive($column)); break; default: throw new \LogicException(sprintf('Unknown sorting type %s', $sort)); @@ -105,10 +106,10 @@ public function buttonInColumnHeaderShouldBeActive($sort, $column): void switch (strtolower($sort)) { case 'sort asc': - expect($list->isColumnAscSortActive($column))->toBe(true); + Assertion::true($list->isColumnAscSortActive($column)); break; case 'sort desc': - expect($list->isColumnDescSortActive($column))->toBe(true); + Assertion::true($list->isColumnDescSortActive($column)); break; default: throw new \LogicException(sprintf('Unknown sorting type %s', $sort)); @@ -128,7 +129,7 @@ public function iChangeElementsPerPageTo($elementsCount): void */ public function iShouldNotSeeAnyFilters(): void { - expect($this->getSession()->getPage()->find('css', 'form.filters'))->toBe(null); + Assertion::null($this->getSession()->getPage()->find('css', 'form.filters')); } /** @@ -136,7 +137,7 @@ public function iShouldNotSeeAnyFilters(): void */ public function iShouldSeeSimpleTextFilter($filterName): void { - expect($this->getFiltersElement()->hasFilter($filterName))->toBe(true); + Assertion::true($this->getFiltersElement()->hasFilter($filterName)); } /** @@ -144,7 +145,7 @@ public function iShouldSeeSimpleTextFilter($filterName): void */ public function iShouldSeeBetweenFilterWithAndSimpleTextFields($filterName, $fromName, $toName): void { - expect($this->getFiltersElement()->hasBetweenFilter($filterName, $fromName, $toName))->toBe(true); + Assertion::true($this->getFiltersElement()->hasBetweenFilter($filterName, $fromName, $toName)); } /** @@ -152,7 +153,7 @@ public function iShouldSeeBetweenFilterWithAndSimpleTextFields($filterName, $fro */ public function iShouldSeeChoiceFilter($filterName): void { - expect($this->getFiltersElement()->hasChoiceFilter($filterName))->toBe(true); + Assertion::true($this->getFiltersElement()->hasChoiceFilter($filterName)); } /** @@ -184,7 +185,7 @@ public function iPressSearchButton(): void */ public function simpleTextFilterShouldBeFilledWithValue($filterName, $filterValue): void { - expect($this->getFiltersElement()->getFilerValue($filterName))->toBe($filterValue); + Assertion::eq($this->getFiltersElement()->getFilerValue($filterName), $filterValue); } /** @@ -192,7 +193,7 @@ public function simpleTextFilterShouldBeFilledWithValue($filterName, $filterValu */ public function choiceFilterShouldHaveValueSelected($filterName, $choice): void { - expect($this->getFiltersElement()->getFilterOption($filterName))->toBe($choice); + Assertion::eq($this->getFiltersElement()->getFilterOption($filterName), $choice); } /** @@ -200,10 +201,10 @@ public function choiceFilterShouldHaveValueSelected($filterName, $choice): void */ public function iShouldSeeActionsDropdownWithFollowingOptions(TableNode $actions): void { - expect($this->getPage(AdminPanel::class)->hasBatchActionsDropdown())->toBe(true); + Assertion::true($this->getPage(AdminPanel::class)->hasBatchActionsDropdown()); foreach ($actions->getHash() as $actionRow) { - expect($this->getPage(AdminPanel::class)->hasBatchAction($actionRow['Option']))->toBe(true); + Assertion::true($this->getPage(AdminPanel::class)->hasBatchAction($actionRow['Option'])); } } diff --git a/Behat/Context/FormContext.php b/Behat/Context/FormContext.php index 9d05cab0..ed16b89a 100644 --- a/Behat/Context/FormContext.php +++ b/Behat/Context/FormContext.php @@ -11,6 +11,7 @@ namespace FSi\Bundle\AdminBundle\Behat\Context; +use Assert\Assertion; use Behat\Gherkin\Node\TableNode; use Behat\Mink\Element\NodeElement; use FSi\Bundle\AdminBundle\Behat\Page\AdminPanel; @@ -22,7 +23,7 @@ class FormContext extends AbstractContext */ public function iChangeFormFieldWithValue($field, $value): void { - expect($this->getFormElement()->findField($field)->getValue())->toNotBe($value); + Assertion::notEq($this->getFormElement()->findField($field)->getValue(), $value); $this->getFormElement()->fillField($field, $value); } @@ -33,7 +34,7 @@ public function iShouldSeeFormWithFollowingFields(TableNode $table): void { $form = $this->getFormElement(); foreach ($table->getHash() as $fieldRow) { - expect($form->hasField($fieldRow['Field name']))->toBe(true); + Assertion::true($form->hasField($fieldRow['Field name'])); } } @@ -54,7 +55,7 @@ public function iFillFormFields(TableNode $table): void foreach ($table->getHash() as $fieldRow) { $fieldName = $fieldRow['Field name']; $fieldValue = $fieldRow['Field value']; - expect($form->hasField($fieldName))->toBe(true); + Assertion::true($form->hasField($fieldName)); $field = $form->findField($fieldName); if ('checkbox' === $field->getAttribute('type')) { $this->parseScenarioValue($fieldValue) ? $field->check() : $field->uncheck(); @@ -93,7 +94,7 @@ public function transformToCollection($collectionNames): ?NodeElement public function collectionShouldHaveElements(NodeElement $collection, $elementsCount): void { $elements = $collection->findAll('xpath', '/*/*[@class = "form-group"]'); - expect(count($elements))->toBe($elementsCount); + Assertion::eq(count($elements), $elementsCount); } /** @@ -101,7 +102,7 @@ public function collectionShouldHaveElements(NodeElement $collection, $elementsC */ public function collectionShouldHaveButton(NodeElement $collection, $buttonName): void { - expect($collection->findButton($buttonName))->toNotBeNull(); + Assertion::notNull($collection->findButton($buttonName)); } /** @@ -110,14 +111,14 @@ public function collectionShouldHaveButton(NodeElement $collection, $buttonName) public function allCollectionButtonsDisabled(NodeElement $collection): void { $removeButtons = $collection->findAll('css', '.collection-remove'); - expect(count($removeButtons))->notToBe(0); + Assertion::notEq(count($removeButtons), 0); foreach ($removeButtons as $removeButton) { - expect($removeButton->hasClass('disabled'))->toBe(true); + Assertion::true($removeButton->hasClass('disabled')); } $addButtons = $collection->findAll('css', '.collection-add'); - expect(count($addButtons))->notToBe(0); + Assertion::notEq(count($addButtons), 0); foreach ($addButtons as $addButton) { - expect($addButton->hasClass('disabled'))->toBe(true); + Assertion::true($addButton->hasClass('disabled')); } } @@ -127,9 +128,9 @@ public function allCollectionButtonsDisabled(NodeElement $collection): void public function collectionAddButtonIsDisabled(NodeElement $collection): void { $addButtons = $collection->findAll('css', '.collection-add'); - expect(count($addButtons))->notToBe(0); + Assertion::notEq(count($addButtons), 0); foreach ($addButtons as $addButton) { - expect($addButton->hasClass('disabled'))->toBe(true); + Assertion::true($addButton->hasClass('disabled')); } } @@ -139,9 +140,9 @@ public function collectionAddButtonIsDisabled(NodeElement $collection): void public function collectionRemoveButtonsAreEnabled(NodeElement $collection): void { $addButtons = $collection->findAll('css', '.collection-remove'); - expect(count($addButtons))->notToBe(0); + Assertion::notEq(count($addButtons), 0); foreach ($addButtons as $addButton) { - expect($addButton->hasClass('disabled'))->toBe(false); + Assertion::false($addButton->hasClass('disabled')); } } diff --git a/Behat/Context/ListContext.php b/Behat/Context/ListContext.php index f1dcea58..79c6d0eb 100644 --- a/Behat/Context/ListContext.php +++ b/Behat/Context/ListContext.php @@ -11,6 +11,7 @@ namespace FSi\Bundle\AdminBundle\Behat\Context; +use Assert\Assertion; use Behat\Gherkin\Node\TableNode; use Behat\Mink\Element\NodeElement; use Exception; @@ -132,7 +133,7 @@ public function iShouldSeeListWithFollowingColumns(TableNode $table): void */ public function thereShouldBeElementsAtList($elemetsCount): void { - expect($this->getListElement()->getRowsCount())->toBe($elemetsCount); + Assertion::eq($this->getListElement()->getRowsCount(), $elemetsCount); } /** @@ -140,7 +141,7 @@ public function thereShouldBeElementsAtList($elemetsCount): void */ public function columnIsEditable($columnHeader): void { - expect($this->getListElement()->isColumnEditable($columnHeader))->toBe(true); + Assertion::true($this->getListElement()->isColumnEditable($columnHeader)); } /** @@ -148,7 +149,7 @@ public function columnIsEditable($columnHeader): void */ public function iShouldNotSeePagination(Page $page): void { - expect($this->getSession()->getPage()->find('css', 'ul.pagination'))->toBe(null); + Assertion::null($this->getSession()->getPage()->find('css', 'ul.pagination')); } /** @@ -177,8 +178,8 @@ public function iClickEditInColumnInFirstRow($columnHeader): void public function popoverWithFieldInFormShouldAppear($newsTitle): void { $popover = $this->getPage(AdminPanel::class)->getPopover(); - expect($popover->isVisible())->toBe(true); - expect($popover->findField('Title')->getValue())->toBe($newsTitle); + Assertion::true($popover->isVisible()); + Assertion::eq($popover->findField('Title')->getValue(), $newsTitle); } /** @@ -187,15 +188,15 @@ public function popoverWithFieldInFormShouldAppear($newsTitle): void public function popoverWithEmptyDateFieldInFormShouldAppear(): void { $popover = $this->getPage(AdminPanel::class)->getPopover(); - expect($popover->isVisible())->toBe(true); - expect($popover->findField('Date')->getValue())->toBe(''); + Assertion::true($popover->isVisible()); + Assertion::eq($popover->findField('Date')->getValue(), ''); } /** * @Then /^popover should not be visible anymore$/ */ public function popoverShouldNotBeVisibleAnymore(): void { - expect($this->getPage(AdminPanel::class)->getPopover())->toBe(null); + Assertion::null($this->getPage(AdminPanel::class)->getPopover()); } /** diff --git a/Behat/Context/MessageContext.php b/Behat/Context/MessageContext.php index 48e7bdc6..b67a4e37 100644 --- a/Behat/Context/MessageContext.php +++ b/Behat/Context/MessageContext.php @@ -11,6 +11,7 @@ namespace FSi\Bundle\AdminBundle\Behat\Context; +use Assert\Assertion; use Behat\Gherkin\Node\PyStringNode; use FSi\Bundle\AdminBundle\Behat\Element\Messages; @@ -23,7 +24,7 @@ public function iShouldSeeErrorMessageSaying(PyStringNode $message): void { $notifications = $this->getMessagesElement(); - expect($notifications->getMessageText('danger'))->toBe($message->getRaw()); + Assertion::eq($notifications->getMessageText('danger'), $message->getRaw()); } /** @@ -33,7 +34,7 @@ public function iShouldSeeWarningMessageSaying(PyStringNode $message): void { $notifications = $this->getMessagesElement(); - expect($notifications->getMessageText('warning'))->toBe($message->getRaw()); + Assertion::eq($notifications->getMessageText('warning'), $message->getRaw()); } /** @@ -43,7 +44,7 @@ public function iShouldSeeInformationalMessageSaying(PyStringNode $message): voi { $notifications = $this->getMessagesElement(); - expect($notifications->getMessageText('info'))->toBe($message->getRaw()); + Assertion::eq($notifications->getMessageText('info'), $message->getRaw()); } /** @@ -53,7 +54,7 @@ public function iShouldSeeSuccessMessageSaying(PyStringNode $message): void { $notifications = $this->getMessagesElement(); - expect($notifications->getMessageText('success'))->toBe($message->getRaw()); + Assertion::eq($notifications->getMessageText('success'), $message->getRaw()); } private function getMessagesElement(): Messages diff --git a/Behat/Context/NavigationContext.php b/Behat/Context/NavigationContext.php index 78bf7c54..6324c4c3 100644 --- a/Behat/Context/NavigationContext.php +++ b/Behat/Context/NavigationContext.php @@ -11,6 +11,7 @@ namespace FSi\Bundle\AdminBundle\Behat\Context; +use Assert\Assertion; use Behat\Gherkin\Node\TableNode; use Exception; use FSi\Bundle\AdminBundle\Behat\Element\Pagination; @@ -107,13 +108,13 @@ public function iFollowUrlFromTopBar($menuElement): void */ public function menuWithFollowingElementsShouldBeVisibleAtTheTopOfThePage(TableNode $table): void { - expect($this->getPage(AdminPanel::class)->getMenuElementsCount())->toBe(count($table->getHash())); + Assertion::eq($this->getPage(AdminPanel::class)->getMenuElementsCount(), count($table->getHash())); foreach ($table->getHash() as $elementRow) { - expect($this->getPage(AdminPanel::class)->hasMenuElement( + Assertion::true($this->getPage(AdminPanel::class)->hasMenuElement( $elementRow['Element name'], empty($elementRow['Element group']) ? null : $elementRow['Element group'] - ))->toBe(true); + )); } } @@ -124,7 +125,7 @@ public function linkInTheTopBarShouldBeHighlighted($link): void { $linkNode = $this->getPage(AdminPanel::class)->getMenu()->findLink($link); - expect($linkNode->getParent()->hasClass('active'))->toBe(true); + Assertion::true($linkNode->getParent()->hasClass('active')); } /** @@ -149,7 +150,7 @@ public function iAmOnThePageWithId(Page $page, $id): void */ public function iShouldBeOnThePage(Page $page): void { - expect($page->isOpen())->toBe(true); + Assertion::true($page->isOpen()); } /** @@ -184,18 +185,18 @@ public function iShouldSeePaginationWithFollowingButtons(TableNode $table): void $pagination = $this->getElement(Pagination::class); foreach ($table->getHash() as $buttonRow) { - expect($pagination->hasLink($buttonRow['Button']))->toBe(true); + Assertion::true($pagination->hasLink($buttonRow['Button'])); if ('true' === $buttonRow['Active']) { - expect($pagination->isDisabled($buttonRow['Button']))->toBe(false); + Assertion::false($pagination->isDisabled($buttonRow['Button'])); } else { - expect($pagination->isDisabled($buttonRow['Button']))->toBe(true); + Assertion::true($pagination->isDisabled($buttonRow['Button'])); } if ('true' === $buttonRow['Current']) { - expect($pagination->isCurrentPage($buttonRow['Button']))->toBe(true); + Assertion::true($pagination->isCurrentPage($buttonRow['Button'])); } else { - expect($pagination->isCurrentPage($buttonRow['Button']))->toBe(false); + Assertion::false($pagination->isCurrentPage($buttonRow['Button'])); } } } diff --git a/Behat/Context/ResourceContext.php b/Behat/Context/ResourceContext.php index 4141c81b..7c74a3ae 100644 --- a/Behat/Context/ResourceContext.php +++ b/Behat/Context/ResourceContext.php @@ -11,11 +11,13 @@ namespace FSi\Bundle\AdminBundle\Behat\Context; +use Assert\Assertion; use Behat\Gherkin\Node\TableNode; use Behat\Mink\Session; use Doctrine\ORM\EntityManagerInterface; use FriendsOfBehat\SymfonyExtension\Mink\MinkParameters; use FSi\Bundle\ResourceRepositoryBundle\Repository\MapBuilder; +use FSi\Bundle\ResourceRepositoryBundle\Repository\Resource\Type\AbstractType; class ResourceContext extends AbstractContext { @@ -38,15 +40,15 @@ public function __construct( public function thereAreFollowingResourcesAddedToResourceMap(TableNode $resources): void { foreach ($resources->getHash() as $resource) { - expect($this->mapBuilder->hasResource($resource['Key']))->toBe(true); + Assertion::true($this->mapBuilder->hasResource($resource['Key'])); if (isset($resource['Type'])) { - expect($this->mapBuilder->getResource($resource['Key']))->toBeAnInstanceOf( - sprintf( - 'FSi\Bundle\ResourceRepositoryBundle\Repository\Resource\Type\%sType', - ucfirst($resource['Type']) - ) + /** @var class-string $className */ + $className = sprintf( + 'FSi\Bundle\ResourceRepositoryBundle\Repository\Resource\Type\%sType', + ucfirst($resource['Type']) ); + Assertion::isInstanceOf($this->mapBuilder->getResource($resource['Key']), $className); } } } @@ -64,6 +66,6 @@ public function iFillFormFieldWith($value): void */ public function iShouldSeeFormFieldWithValue($value): void { - expect($this->getSession()->getPage()->findField('Content')->getValue())->toBe($value); + Assertion::eq($this->getSession()->getPage()->findField('Content')->getValue(), $value); } } diff --git a/behat.yml b/behat.yml index 7ae71b16..e7c68fb2 100644 --- a/behat.yml +++ b/behat.yml @@ -28,12 +28,12 @@ default: &default path: features/fixtures/project/src/AppKernel.php class: FSi\AppKernel Caciobanu\Behat\DeprecationExtension: ~ -travis: +actions: <<: *default extensions: Behat\MinkExtension: - base_url: "http://localhost:8080/app_test.php" + base_url: "http://test-container:8080/app_test.php" sessions: javascript: selenium2: - wd_host: http://localhost:4444/wd/hub + wd_host: http://firefox:4444/wd/hub diff --git a/composer.json b/composer.json index b30d95e3..f2da99a9 100644 --- a/composer.json +++ b/composer.json @@ -47,6 +47,7 @@ }, "require-dev": { "ext-pdo_sqlite": "*", + "beberlei/assert": "^3.3", "behat/behat": "^3.10", "behat/mink": "^1.10", "behat/mink-selenium2-driver": "^1.3", @@ -56,18 +57,17 @@ "friends-of-behat/mink-extension": "^2.6", "friends-of-behat/page-object-extension": "^0.3.2", "friends-of-behat/symfony-extension": "^2.3", - "friends-of-phpspec/phpspec-expect": "^4.0", "fsi/files": "^2.0.4|^3.0@dev", - "fsi/resource-repository-bundle": "^3.0.3", + "fsi/resource-repository-bundle": "^3.0.3@dev", "gedmo/doctrine-extensions": "^3.13", "mockery/mockery": "^1.6", "nyholm/psr7": "^1.8", "ocramius/proxy-manager": "^2.5", "oneup/flysystem-bundle": "^4.4", - "phpspec/phpspec": "^7.4", + "phpspec/phpspec": "^7.4|^8.0@dev", "phpstan/phpstan": "^1.10", "phpstan/phpstan-beberlei-assert": "^1.0", - "rize/uri-template": "^0.3.5", + "rize/uri-template": "^0.3.5|^0.4.0", "sebastian/comparator": "^4.0|^5.0", "sebastian/exporter": "^4.0|^5.0", "squizlabs/php_codesniffer": "^3.7", diff --git a/spec/FSi/Bundle/AdminBundle/EventSubscriber/LocaleMenuSubscriberSpec.php b/spec/FSi/Bundle/AdminBundle/EventSubscriber/LocaleMenuSubscriberSpec.php index 03b80837..4eab0ddc 100644 --- a/spec/FSi/Bundle/AdminBundle/EventSubscriber/LocaleMenuSubscriberSpec.php +++ b/spec/FSi/Bundle/AdminBundle/EventSubscriber/LocaleMenuSubscriberSpec.php @@ -11,6 +11,7 @@ namespace spec\FSi\Bundle\AdminBundle\EventSubscriber; +use Assert\Assertion; use FSi\Bundle\AdminBundle\Event\MenuEvent; use FSi\Bundle\AdminBundle\Menu\Item\Item; use PhpSpec\ObjectBehavior; @@ -54,14 +55,14 @@ public function it_should_build_locale_menu( $enItem = $localeItems['admin-locale.en']; $deItem = $localeItems['admin-locale.de']; - expect($enItem->getLabel())->toBe('Englisch'); - expect($enItem->getRoute())->toBe('fsi_admin_locale'); - expect($enItem->getRouteParameters())->toBe(['_locale' => 'en', 'redirect_uri' => 'uri_to_redirect_to']); - expect($enItem->getOptions())->toBe(['attr' => ['id' => null, 'class' => null]]); + Assertion::same($enItem->getLabel(), 'Englisch'); + Assertion::same($enItem->getRoute(), 'fsi_admin_locale'); + Assertion::same($enItem->getRouteParameters(), ['_locale' => 'en', 'redirect_uri' => 'uri_to_redirect_to']); + Assertion::same($enItem->getOptions(), ['attr' => ['id' => null, 'class' => null]]); - expect($deItem->getLabel())->toBe('Deutsch'); - expect($deItem->getRoute())->toBe('fsi_admin_locale'); - expect($deItem->getRouteParameters())->toBe(['_locale' => 'de', 'redirect_uri' => 'uri_to_redirect_to']); - expect($deItem->getOptions())->toBe(['attr' => ['id' => null, 'class' => 'active']]); + Assertion::same($deItem->getLabel(), 'Deutsch'); + Assertion::same($deItem->getRoute(), 'fsi_admin_locale'); + Assertion::same($deItem->getRouteParameters(), ['_locale' => 'de', 'redirect_uri' => 'uri_to_redirect_to']); + Assertion::same($deItem->getOptions(), ['attr' => ['id' => null, 'class' => 'active']]); } }