-
Notifications
You must be signed in to change notification settings - Fork 12
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
loic425
merged 1 commit into
Sylius:behat-bridge
from
loic425:features/shared-storage-context
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,8 @@ | ||||
services: | ||||
_defaults: | ||||
autowire: true | ||||
autoconfigure: true | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
|
||||
MainTests\Sylius\Behat\: | ||||
resource: '../tests/Behat/*' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}; |
42 changes: 42 additions & 0 deletions
42
src/BehatBridge/src/Behat/Context/Transform/SharedStorageContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.