-
-
Notifications
You must be signed in to change notification settings - Fork 14
[#778] Imported the Behat integration layer as 'BehatStepsExtension'. #805
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d9e34b1
[#778] Imported the Behat integration layer as 'BehatStepsExtension'.
AlexSkrypnyk 4f638d3
[#778] Documented the Behat layer and its Behat 4 readiness rules.
AlexSkrypnyk dc4abd6
[#778] Rejected an unreadable node timestamp instead of storing a fal…
AlexSkrypnyk 05ee92f
[#778] Matched every role a 'currentUserHasRole()' query names.
AlexSkrypnyk 271a442
[#778] Named the missing setting when no driver is configured.
AlexSkrypnyk e6e3bf0
[#778] Treated a path as absolute only when it carries an HTTP scheme.
AlexSkrypnyk e316dbc
[#778] Shared the hook attribute filter string through one trait.
AlexSkrypnyk 609df2d
[#778] Restricted a region selector to a scalar and read the login wa…
AlexSkrypnyk 5cfd310
[#778] Asserted the login field value and the vocabulary the driver r…
AlexSkrypnyk c27fa70
[#778] Declared 'symfony/yaml' and raised the 'symfony/config' floor …
AlexSkrypnyk f0bf09e
[#778] Registered a created entity before its post-create hooks run.
AlexSkrypnyk ea11670
[#778] Required 'drupal_root' whenever the Drupal driver is enabled.
AlexSkrypnyk f1fb2f6
[#778] Asserted the hook callee's method rather than its callable shape.
AlexSkrypnyk 29c436a
Re-triggered CI to clear a flaky check.
AlexSkrypnyk 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 hidden or 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 hidden or 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 hidden or 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,107 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace DrevOps\BehatSteps\Behat\Context\Attribute; | ||
|
|
||
| use Behat\Behat\Context\Attribute\AttributeReader; | ||
| use DrevOps\BehatSteps\Behat\Hook\Attribute\AfterEntityCreate as AfterEntityCreateAttribute; | ||
| use DrevOps\BehatSteps\Behat\Hook\Attribute\AfterNodeCreate as AfterNodeCreateAttribute; | ||
| use DrevOps\BehatSteps\Behat\Hook\Attribute\AfterTermCreate as AfterTermCreateAttribute; | ||
| use DrevOps\BehatSteps\Behat\Hook\Attribute\AfterUserCreate as AfterUserCreateAttribute; | ||
| use DrevOps\BehatSteps\Behat\Hook\Attribute\BeforeEntityCreate as BeforeEntityCreateAttribute; | ||
| use DrevOps\BehatSteps\Behat\Hook\Attribute\BeforeNodeCreate as BeforeNodeCreateAttribute; | ||
| use DrevOps\BehatSteps\Behat\Hook\Attribute\BeforeTermCreate as BeforeTermCreateAttribute; | ||
| use DrevOps\BehatSteps\Behat\Hook\Attribute\BeforeUserCreate as BeforeUserCreateAttribute; | ||
| use DrevOps\BehatSteps\Behat\Hook\Attribute\DrupalHookInterface; | ||
| use DrevOps\BehatSteps\Behat\Hook\Call\AfterEntityCreate; | ||
| use DrevOps\BehatSteps\Behat\Hook\Call\AfterNodeCreate; | ||
| use DrevOps\BehatSteps\Behat\Hook\Call\AfterTermCreate; | ||
| use DrevOps\BehatSteps\Behat\Hook\Call\AfterUserCreate; | ||
| use DrevOps\BehatSteps\Behat\Hook\Call\BeforeEntityCreate; | ||
| use DrevOps\BehatSteps\Behat\Hook\Call\BeforeNodeCreate; | ||
| use DrevOps\BehatSteps\Behat\Hook\Call\BeforeTermCreate; | ||
| use DrevOps\BehatSteps\Behat\Hook\Call\BeforeUserCreate; | ||
|
|
||
| /** | ||
| * Reads the entity creation hook attributes off a context method. | ||
| */ | ||
| class HookAttributeReader implements AttributeReader { | ||
|
|
||
| /** | ||
| * Behat's factory for a callable that survives late instance binding. | ||
| * | ||
| * Behat 4 types the callee constructor as 'callable', and a | ||
| * '[class-string, method]' pair is not callable for an instance method, so | ||
| * it wraps such methods instead. The class is absent on Behat 3, which | ||
| * accepts the pair directly. | ||
| */ | ||
| protected const CALLABLE_FACTORY = 'Behat\\Behat\\Context\\ContextMethodCallableFactory'; | ||
|
|
||
| /** | ||
| * Map of attribute classes to their hook call classes. | ||
| * | ||
| * @var array<class-string, class-string<\DrevOps\BehatSteps\Behat\Hook\Call\EntityHook>> | ||
| */ | ||
| protected const ATTRIBUTE_MAP = [ | ||
| AfterEntityCreateAttribute::class => AfterEntityCreate::class, | ||
| AfterNodeCreateAttribute::class => AfterNodeCreate::class, | ||
| AfterTermCreateAttribute::class => AfterTermCreate::class, | ||
| AfterUserCreateAttribute::class => AfterUserCreate::class, | ||
| BeforeEntityCreateAttribute::class => BeforeEntityCreate::class, | ||
| BeforeNodeCreateAttribute::class => BeforeNodeCreate::class, | ||
| BeforeTermCreateAttribute::class => BeforeTermCreate::class, | ||
| BeforeUserCreateAttribute::class => BeforeUserCreate::class, | ||
| ]; | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| * | ||
| * @param class-string<\Behat\Behat\Context\Context> $contextClass | ||
| * The context class name. | ||
| * @param \ReflectionMethod $method | ||
| * The reflected method. | ||
| */ | ||
| public function readCallees(string $contextClass, \ReflectionMethod $method): array { | ||
| $attributes = $method->getAttributes(DrupalHookInterface::class, \ReflectionAttribute::IS_INSTANCEOF); | ||
|
|
||
| $callees = []; | ||
| foreach ($attributes as $attribute) { | ||
| $hook_call_class = self::ATTRIBUTE_MAP[$attribute->getName()] ?? NULL; | ||
| if ($hook_call_class === NULL) { | ||
| continue; | ||
| } | ||
|
|
||
| $hook = $attribute->newInstance(); | ||
| $callees[] = new $hook_call_class($hook->getFilterString(), $this->makeCallable($contextClass, $method)); | ||
| } | ||
|
|
||
| return $callees; | ||
| } | ||
|
|
||
| /** | ||
| * Builds the callable a hook call is constructed with. | ||
| * | ||
| * @param class-string<\Behat\Behat\Context\Context> $context_class | ||
| * The context class declaring the method. | ||
| * @param \ReflectionMethod $method | ||
| * The reflected method carrying the attribute. | ||
| * | ||
| * @return array{class-string<\Behat\Behat\Context\Context>, string}|callable | ||
| * The pair Behat 3 accepts, or the wrapper Behat 4 requires. | ||
| */ | ||
| protected function makeCallable(string $context_class, \ReflectionMethod $method): array|callable { | ||
| if ($method->isStatic() || !class_exists(self::CALLABLE_FACTORY)) { | ||
| return [$context_class, $method->getName()]; | ||
| } | ||
|
|
||
| // @codeCoverageIgnoreStart | ||
| /** @var callable $callable */ | ||
| // @phpstan-ignore argument.type | ||
| $callable = call_user_func([self::CALLABLE_FACTORY, 'makeCallable'], $context_class, $method); | ||
|
|
||
| return $callable; | ||
| // @codeCoverageIgnoreEnd | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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,59 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace DrevOps\BehatSteps\Behat\Context; | ||
|
|
||
| use Behat\Behat\Context\Context; | ||
| use Behat\Testwork\Hook\HookDispatcher; | ||
| use DrevOps\BehatSteps\Behat\Manager\AuthenticationManagerInterface; | ||
| use DrevOps\BehatSteps\Behat\Manager\DriverManagerInterface; | ||
| use DrevOps\BehatSteps\Behat\Manager\UserManagerInterface; | ||
| use DrevOps\BehatSteps\Behat\ParametersAwareInterface; | ||
|
|
||
| /** | ||
| * Contract for contexts wired to the driver manager and its collaborators. | ||
| * | ||
| * @see \DrevOps\BehatSteps\Behat\Context\Initializer\DriverAwareInitializer | ||
| */ | ||
| interface DriverAwareInterface extends Context, ParametersAwareInterface { | ||
|
|
||
| /** | ||
| * Sets the driver manager. | ||
| */ | ||
| public function setDriverManager(DriverManagerInterface $driverManager): void; | ||
|
|
||
| /** | ||
| * Returns the driver manager. | ||
| * | ||
| * @throws \RuntimeException | ||
| * When the context has not been initialized by Behat yet. | ||
| */ | ||
| public function getDriverManager(): DriverManagerInterface; | ||
|
|
||
| /** | ||
| * Sets the hook dispatcher. | ||
| */ | ||
| public function setDispatcher(HookDispatcher $dispatcher): void; | ||
|
|
||
| /** | ||
| * Sets the user manager. | ||
| */ | ||
| public function setUserManager(UserManagerInterface $userManager): void; | ||
|
|
||
| /** | ||
| * Returns the user manager. | ||
| */ | ||
| public function getUserManager(): UserManagerInterface; | ||
|
|
||
| /** | ||
| * Sets the authentication manager. | ||
| */ | ||
| public function setAuthenticationManager(AuthenticationManagerInterface $authenticationManager): void; | ||
|
|
||
| /** | ||
| * Returns the authentication manager. | ||
| */ | ||
| public function getAuthenticationManager(): AuthenticationManagerInterface; | ||
|
|
||
| } |
This file contains hidden or 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,66 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace DrevOps\BehatSteps\Behat\Context\Initializer; | ||
|
|
||
| use Behat\Behat\Context\Context; | ||
| use Behat\Behat\Context\Initializer\ContextInitializer; | ||
| use Behat\Testwork\Hook\HookDispatcher; | ||
| use DrevOps\BehatSteps\Behat\Context\DriverAwareInterface; | ||
| use DrevOps\BehatSteps\Behat\Manager\AuthenticationManagerInterface; | ||
| use DrevOps\BehatSteps\Behat\Manager\DriverManagerInterface; | ||
| use DrevOps\BehatSteps\Behat\Manager\UserManagerInterface; | ||
| use DrevOps\BehatSteps\Behat\ParametersAwareInterface; | ||
|
|
||
| /** | ||
| * Injects the driver manager and its collaborators into a context. | ||
| */ | ||
| class DriverAwareInitializer implements ContextInitializer { | ||
|
|
||
| /** | ||
| * Constructs a DriverAwareInitializer object. | ||
| * | ||
| * @param \DrevOps\BehatSteps\Behat\Manager\DriverManagerInterface $driverManager | ||
| * The driver manager. | ||
| * @param array<string, mixed> $parameters | ||
| * Configuration parameters. | ||
| * @param \Behat\Testwork\Hook\HookDispatcher $hookDispatcher | ||
| * The hook dispatcher. | ||
| * @param \DrevOps\BehatSteps\Behat\Manager\AuthenticationManagerInterface $authenticationManager | ||
| * The authentication manager. | ||
| * @param \DrevOps\BehatSteps\Behat\Manager\UserManagerInterface $userManager | ||
| * The user manager. | ||
| */ | ||
| public function __construct( | ||
| protected readonly DriverManagerInterface $driverManager, | ||
| protected readonly array $parameters, | ||
| protected readonly HookDispatcher $hookDispatcher, | ||
| protected readonly AuthenticationManagerInterface $authenticationManager, | ||
| protected readonly UserManagerInterface $userManager, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| public function initializeContext(Context $context): void { | ||
| // 'ParametersAwareInterface' is a strict subset of 'DriverAwareInterface' | ||
| // (the latter extends the former). Pass parameters to any context that | ||
| // asks for them, then layer the heavier driver wiring on top for full | ||
| // driver-aware contexts only. | ||
| if ($context instanceof ParametersAwareInterface) { | ||
| $context->setParameters($this->parameters); | ||
| } | ||
|
|
||
| if (!$context instanceof DriverAwareInterface) { | ||
| return; | ||
| } | ||
|
|
||
| $context->setDriverManager($this->driverManager); | ||
| $context->setDispatcher($this->hookDispatcher); | ||
| $context->setAuthenticationManager($this->authenticationManager); | ||
| $context->setUserManager($this->userManager); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.