Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BehatBridge] Add Shared storage context #151

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions behat.dist.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
imports:
- config/behat/suites/ui/book/managing_books.yaml

default:
extensions:
FriendsOfBehat\SymfonyExtension:
bootstrap: tests/bootstrap.php

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions config/behat/suites/ui/book/managing_books.yaml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
];
8 changes: 8 additions & 0 deletions config/services_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
_defaults:
autowire: true
autoconfigure: true

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change


MainTests\Sylius\Behat\:
resource: '../tests/Behat/*'
12 changes: 12 additions & 0 deletions features/admin/book/managing_books/editing_books.feature
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions src/BehatBridge/config/services/behat/context.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Sylius\BehatBridge\Behat\Context\Transform\SharedStorageContext;

return function (ContainerConfigurator $configurator): void {
$services = $configurator->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');
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\BehatBridge\Behat\Context\Transform;

use Behat\Behat\Context\Context;
use Sylius\BehatBridge\Formatter\StringInflector;
use Sylius\BehatBridge\Storage\SharedStorageInterface;

final class SharedStorageContext implements Context
{
public function __construct(
private readonly SharedStorageInterface $sharedStorage,
) {
}

/**
* @Transform /^(it|its|theirs|them)$/
*/
public function getLatestResource(): mixed
{
return $this->sharedStorage->getLatestResource();
}

/**
* @Transform /^(?:this|that|the|my|his|her) ([^"]+)$/
*/
public function getResource(mixed $resource): mixed
{
return $this->sharedStorage->get(StringInflector::nameToCode($resource));
}
}
26 changes: 26 additions & 0 deletions src/BehatBridge/src/Formatter/StringInflector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\BehatBridge\Formatter;

final class StringInflector
{
public static function nameToCode(string $value): string
{
return str_replace([' ', '-'], '_', $value);
}

private function __construct()
{
}
}
9 changes: 9 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
"src/DataFixtures/AppFixtures.php"
]
},
"friends-of-behat/symfony-extension": {
"version": "2.6",
"recipe": {
"repo": "github.com/symfony/recipes-contrib",
"branch": "main",
"version": "2.0",
"ref": "1e012e04f573524ca83795cd19df9ea690adb604"
}
},
"knplabs/knp-menu-bundle": {
"version": "v3.4.2"
},
Expand Down
26 changes: 26 additions & 0 deletions tests/Behat/Context/Setup/BookContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace MainTests\Sylius\Behat\Context\Setup;

use App\Factory\BookFactory;
use Behat\Behat\Context\Context;
use Behat\Step\Given;
use Sylius\BehatBridge\Storage\SharedStorageInterface;

final class BookContext implements Context
{
public function __construct(
private readonly SharedStorageInterface $sharedStorage,
) {
}

#[Given('there is a book :title')]
public function thereIsABook(string $title): void
{
$book = BookFactory::new()
->withTitle($title)->create()
;

$this->sharedStorage->set('book', $book);
}
}
22 changes: 22 additions & 0 deletions tests/Behat/Context/Ui/ManagingBooksContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace MainTests\Sylius\Behat\Context\Ui;

use App\Entity\Book;
use Behat\Behat\Context\Context;
use Behat\Step\When;
use Zenstruck\Foundry\Persistence\Proxy;

final class ManagingBooksContext implements Context
{
/**
* @param Proxy<Book> $book
*/
#[When('/^I want to edit (this book)$/')]
public function iWantToEditThisBook(Proxy $book): void
{
// For now, we are just testing the shared context transform
}
}
Loading