diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4b3f8e53..40a4f865 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -94,6 +94,9 @@ jobs: run: | APP_LOCALE=fr vendor/bin/phpunit --testsuite="TranslationsTestSuite" + - name: Run Behat + run: vendor/bin/behat --format=progress --strict + - name: "Restrict packages' versions (Admin Ui)" run: | (cd src/AdminUi/ && composer global config --no-plugins allow-plugins.symfony/flex true) diff --git a/behat.dist.yaml b/behat.dist.yaml new file mode 100644 index 00000000..5041adeb --- /dev/null +++ b/behat.dist.yaml @@ -0,0 +1,8 @@ +imports: + - config/behat/suites/ui/book/managing_books.yaml + +default: + extensions: + FriendsOfBehat\SymfonyExtension: + bootstrap: tests/bootstrap.php + diff --git a/composer.json b/composer.json index 8c62c61b..f306b89b 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,9 @@ "webmozart/assert": "^1.9" }, "require-dev": { + "behat/behat": "^3.16", "doctrine/doctrine-fixtures-bundle": "^3.6", + "friends-of-behat/symfony-extension": "^2.6", "matthiasnoback/symfony-config-test": "^5.1", "matthiasnoback/symfony-dependency-injection-test": "^5.1", "phpstan/phpstan": "^1.10", diff --git a/config/behat/suites/ui/book/managing_books.yaml b/config/behat/suites/ui/book/managing_books.yaml new file mode 100644 index 00000000..0bcd6f7a --- /dev/null +++ b/config/behat/suites/ui/book/managing_books.yaml @@ -0,0 +1,12 @@ +default: + suites: + ui_managing_books: + contexts: + - Sylius\BehatBridge\Behat\Context\Transform\SharedStorageContext + + - MainTests\Sylius\Behat\Context\Setup\BookContext + + - MainTests\Sylius\Behat\Context\Ui\ManagingBooksContext + + filters: + tags: "@managing_books&&@ui" diff --git a/config/bundles.php b/config/bundles.php index fc0356f3..23421981 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -26,4 +26,5 @@ Symfony\UX\Autocomplete\AutocompleteBundle::class => ['all' => true], Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], Symfony\UX\Icons\UXIconsBundle::class => ['all' => true], + FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true], ]; diff --git a/config/services_test.yaml b/config/services_test.yaml new file mode 100644 index 00000000..4af151cd --- /dev/null +++ b/config/services_test.yaml @@ -0,0 +1,8 @@ +services: + _defaults: + autowire: true + autoconfigure: true + + + MainTests\Sylius\Behat\: + resource: '../tests/Behat/*' diff --git a/features/admin/book/managing_books/editing_books.feature b/features/admin/book/managing_books/editing_books.feature new file mode 100644 index 00000000..22c06272 --- /dev/null +++ b/features/admin/book/managing_books/editing_books.feature @@ -0,0 +1,12 @@ +@managing_books +Feature: Editing books + In order to change information about a book + As an Administrator + I want to be able to edit the book + + Background: + Given there is a book "Shinning" + + @ui + Scenario: Renaming a book + When I want to edit this book diff --git a/src/BehatBridge/config/services/behat/context.php b/src/BehatBridge/config/services/behat/context.php new file mode 100644 index 00000000..e17c9abc --- /dev/null +++ b/src/BehatBridge/config/services/behat/context.php @@ -0,0 +1,32 @@ +services(); + + $services->defaults() + ->public() + ; + + $services + ->set('sylius_behat_bridge.behat.context.transform.shared_storage', SharedStorageContext::class) + ->args([ + service('sylius_behat_bridge.storage.shared'), + ]) + ; + $services->alias(SharedStorageContext::class, 'sylius_behat_bridge.behat.context.transform.shared_storage'); +}; diff --git a/src/BehatBridge/src/Behat/Context/Transform/SharedStorageContext.php b/src/BehatBridge/src/Behat/Context/Transform/SharedStorageContext.php new file mode 100644 index 00000000..ec92c89d --- /dev/null +++ b/src/BehatBridge/src/Behat/Context/Transform/SharedStorageContext.php @@ -0,0 +1,42 @@ +sharedStorage->getLatestResource(); + } + + /** + * @Transform /^(?:this|that|the|my|his|her) ([^"]+)$/ + */ + public function getResource(mixed $resource): mixed + { + return $this->sharedStorage->get(StringInflector::nameToCode($resource)); + } +} diff --git a/src/BehatBridge/src/Formatter/StringInflector.php b/src/BehatBridge/src/Formatter/StringInflector.php new file mode 100644 index 00000000..0a8e72a9 --- /dev/null +++ b/src/BehatBridge/src/Formatter/StringInflector.php @@ -0,0 +1,26 @@ +withTitle($title)->create() + ; + + $this->sharedStorage->set('book', $book); + } +} diff --git a/tests/Behat/Context/Ui/ManagingBooksContext.php b/tests/Behat/Context/Ui/ManagingBooksContext.php new file mode 100644 index 00000000..f9c25149 --- /dev/null +++ b/tests/Behat/Context/Ui/ManagingBooksContext.php @@ -0,0 +1,22 @@ + $book + */ + #[When('/^I want to edit (this book)$/')] + public function iWantToEditThisBook(Proxy $book): void + { + // For now, we are just testing the shared context transform + } +}