Skip to content
This repository has been archived by the owner on Jan 2, 2020. It is now read-only.

Fix 146 #205

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
684f5f9
WIP - moving to another machine
rvodden Mar 25, 2018
90b399a
WIP - moving to another machine
rvodden Mar 25, 2018
feb170c
Merge branch 'fix-146' of github.com:paulgibbs/behat-wordpress-extens…
rvodden Apr 3, 2018
4071b1f
Yet more WIP - must tidy up these commit messages
rvodden Apr 3, 2018
bda9be3
Converted drivers to use constructor injection
rvodden Apr 21, 2018
560da00
Migrated user context
rvodden Apr 22, 2018
9163a3c
Completed migration of Elements
rvodden Apr 22, 2018
5841b0f
Resolved teething issues
rvodden Apr 22, 2018
3cc1957
Fixed dependencies for php7.0
rvodden Apr 22, 2018
b257b0b
Removed diagnostic output
rvodden Apr 22, 2018
8fd6d30
Removed blackbox driver (temporarily) to see if the build works
rvodden Apr 22, 2018
a655bf8
Fixed the widgetawaretrait
rvodden Apr 22, 2018
c40afed
Refixed the widget test
rvodden Apr 23, 2018
023b4a3
Added type hint to UserAwareContextTrait::setUserElement
rvodden Apr 23, 2018
15f8c22
Added type hint to CacheAwareContextTrait::setCacheElement
rvodden Apr 23, 2018
f35ee65
Removed php7.2 specific syntax
rvodden Apr 23, 2018
1c24558
Documentation part 1
rvodden Apr 24, 2018
ba6747d
removed push from builds other than pauls
rvodden May 4, 2018
b62cf2f
Corrected build.xml typo
rvodden May 4, 2018
998d1e1
removed push from builds other than pauls
rvodden May 4, 2018
0863daa
Corrected build.xml typo
rvodden May 4, 2018
c06c527
Force versions of selenium and mysql
rvodden May 4, 2018
dca50b5
Bringing in WP 4.9.5
rvodden May 4, 2018
1a48126
Locked mysql to 5.7.22
rvodden May 5, 2018
52eb341
Reverted changes to config (temporarily)
rvodden May 7, 2018
83660e3
Merge branch 'master' into fix-146
rvodden May 7, 2018
460fcb8
Fixed whitespace
rvodden May 7, 2018
7e9ea31
Removed speculative configuration refactor
rvodden May 7, 2018
0735368
Merge branch 'fix-travis-build' into fix-146
rvodden May 7, 2018
5f07c54
Fixed layout of configuration method
rvodden May 7, 2018
8944758
Replaced site_url parameter
rvodden May 7, 2018
a922721
Removing build changes (they're now on new-pipeline)
rvodden May 19, 2018
337c51b
Removed latest version script
rvodden May 19, 2018
7ab25bc
reverted phpcs-ruleset.xml to master
rvodden May 19, 2018
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
443 changes: 232 additions & 211 deletions build.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WH_WORDPRESS_DIR=/usr/src/wordpress

# wait for mysql to come up

while ! mysqladmin ping -h "db" --silent; do
while ! mysqladmin ping -h "db"; do
echo "Waiting for mysql..."
sleep 5
done
Expand Down
4 changes: 2 additions & 2 deletions build/templates/docker-compose.yml.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3'

services:
db:
image: healthcheck/mysql:latest
image: mysql:5.7.22
ports:
- "3306:3306"
environment:
Expand Down Expand Up @@ -30,6 +30,6 @@ services:
- seccomp:unconfined

selenium:
image: selenium/standalone-chrome-debug:latest
image: selenium/standalone-chrome-debug:3.11.0
ports:
- "4444:4444"
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
excludes_analyse:
# These reference global WP functions.
- %rootDir%/../../../src/Driver/Element/Wpphp/*
- src/Driver/WpphpDriver.php
- %rootDir%/../../../src/Driver/Wpphp/Element/*
- src/Driver/Wpphp/WpphpDriver.php
21 changes: 3 additions & 18 deletions src/Compiler/DriverElementPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
declare(strict_types=1);
namespace PaulGibbs\WordpressBehatExtension\Compiler;

use PaulGibbs\WordpressBehatExtension\Driver\Element\Interfaces\PluginElementInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

/**
Expand All @@ -18,22 +18,7 @@ class DriverElementPass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container)
{
$wordpress = $container->getDefinition('wordpress.wordpress');
if (! $wordpress) {
return;
}

foreach ($container->findTaggedServiceIds('wordpress.element') as $id => $attributes) {
foreach ($attributes as $attribute) {
if (! isset($attribute['alias'], $attribute['driver'])) {
continue;
}

$wordpress->addMethodCall(
'registerDriverElement',
[$attribute['alias'], new Reference($id), $attribute['driver']]
);
}
}
$container->registerForAutoconfiguration(PluginElementInterface::class)
->addTag('wordpress.driver.element.plugin');
}
}
71 changes: 54 additions & 17 deletions src/Compiler/DriverPass.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,78 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);
namespace PaulGibbs\WordpressBehatExtension\Compiler;

use PaulGibbs\WordpressBehatExtension\Driver\DriverManagerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

/**
* WordpressBehatExtension container compilation pass.
* This class is a Symfony compiler pass. It is registered with
* Symfony by BehatWordpressExtension.
*
* During compilation Symfony will call the process method.
*
* Initially it grabs the wordhat configuration from the ContainerBuilder. This
* was previously saved by BehatWordpressExtension, which in turn was read from
* behat.yml.
*
* Then it scans the existing services for those tagged with 'wordpress.driver'.
* For each tagged service it:
* 1) Grabs the shortname
* 2) Executes the bootstrap method on the driver class
* 3) Checks if shortname matched the default driver in the configuration. If it does is:
* - Binds the driverManager class to the DriverManagerInterface
* - Calls the setParameters method on the driver class which loads the driver configuration
* and binds in each of the elements.
*
* @see PaulGibbs\WordpressBehatExtension\ServiceContainer\BehatWordpressExtension
*/
class DriverPass implements CompilerPassInterface
{
/**
* Modify the container before Symfony compiles it.
* Entrypoint for the Symfony compiler path
*
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
$wordpress = $container->getDefinition('wordpress.wordpress');
if (! $wordpress) {
return;
}
$config = $this->getConfigs($container);

// Grab the default driver name from the config
$defaultDriverName = $container->getParameter('wordpress.default_driver');

// Tell WordpressDriverManager about the default driver name
//$wordpress->addMethodCall('setDefaultDriverName', [
// $defaultDriverName
//]);

foreach ($container->findTaggedServiceIds('wordpress.driver') as $id => $attributes) {
foreach ($attributes as $attribute) {
if (empty($attribute['alias'])) {
continue;
}
// Grab the definition
$definition = $container->getDefinition($id);
$class = $definition->getClass();

/* TODO: The setParameters method below should be split into an activate
* method and a setParameters method. The setParameters part should be called
* here.
*/

$driverName = call_user_func($class . '::getShortName');

$wordpress->addMethodCall('registerDriver', [$attribute['alias'], new Reference($id)]);
// bootstrap the driver at the point it is created
$definition->addMethodCall('bootstrap');

if ($driverName === $defaultDriverName) {
$container->setAlias(DriverManagerInterface::class, $id);
$driverName = call_user_func($class . '::setParameters', $container, $config);
}
}
}

$wordpress->addMethodCall(
'setDefaultDriverName',
[$container->getParameter('wordpress.wordpress.default_driver')]
);
/**
* grab the configuration from the container builder
*/
protected function getConfigs(ContainerBuilder $container)
{
return $container->getParameter('wordpress.parameters');
}
}
33 changes: 26 additions & 7 deletions src/Compiler/EventSubscriberPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,48 @@
declare(strict_types=1);
namespace PaulGibbs\WordpressBehatExtension\Compiler;

use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use RuntimeException;

/**
* Event subscribers pass.
* A specific driver can be specified for a scenario or example by using the @driver tag in the gherkin feature file.
*
* To make this work, we need to be able to switch drivers at the start of a scenario (if necessary). This
* is done by the DriverListener which has its prepareWordpressDriver method called whenever a scenario or
* example is started.
*
* It is the role of this class to make that happen. It is a Symfony compiler pass and is registered as such
* by BehatWordpressExtension. During compilation it scans for services which are tagged with 'wordpress.event_subscriber',
* and adds a call to the event_dispatchers 'addSubscriber' method for each service.
*
* Register all available event subscribers.
*/
class EventSubscriberPass implements CompilerPassInterface
{
/**
* Processes container.
* This method registers each service tagged with 'wordpress.event_subscriber' to the event_dispatcher service.
*
* Firstly it gets the event_dispatcher from the ServiceContainer by looking for a service named 'event_dispatcher'; this
* service is automatically provided by the event_dispatcher bundle.
*
* Then it scans for 'wordpress.event_subscriber' tagged services. These services are tagged by WordpressBehatExtension,
* which reads them (at the moment) from behat.yml.
*
* It checks if a priority has been configured on the service, if it has it uses that value, otherwise it uses 0.
*
* Finally it adds a call to the addSubsciber method at creation time of the event_dispatcher with a reference to the
* subscriber service and the priority as arguments.
*
* @param ContainerBuilder $container
*/
public function process(ContainerBuilder $container)
{
if (! $container->hasDefinition('wordpress.event_dispatcher')) {
return;
if (! $container->hasDefinition('event_dispatcher')) {
throw new RuntimeException('Event dispatcher cannot be found');
}

$dispatcher = $container->getDefinition('wordpress.event_dispatcher');
$dispatcher = $container->getDefinition('event_dispatcher');

foreach ($container->findTaggedServiceIds('wordpress.event_subscriber') as $id => $attributes) {
foreach ($attributes as $attribute) {
Expand Down
8 changes: 5 additions & 3 deletions src/Context/ContentContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
declare(strict_types=1);
namespace PaulGibbs\WordpressBehatExtension\Context;

use UnexpectedValueException;
use RuntimeException;
use Behat\Gherkin\Node\TableNode;
use PaulGibbs\WordpressBehatExtension\Context\Interfaces\ContentAwareContextInterface;
use PaulGibbs\WordpressBehatExtension\Context\Interfaces\UserAwareContextInterface;
use PaulGibbs\WordpressBehatExtension\Context\Traits\ContentAwareContextTrait;
use PaulGibbs\WordpressBehatExtension\Context\Traits\UserAwareContextTrait;
use RuntimeException;
use UnexpectedValueException;

/**
* Provides step definitions for creating content: post types, comments, and terms.
*/
class ContentContext extends RawWordpressContext
class ContentContext extends RawWordpressContext implements UserAwareContextInterface, ContentAwareContextInterface
{
use ContentAwareContextTrait, UserAwareContextTrait;

Expand Down
3 changes: 2 additions & 1 deletion src/Context/EditPostContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
use Behat\Gherkin\Node\PyStringNode;
use Behat\Mink\Exception\ExpectationException;
use PaulGibbs\WordpressBehatExtension\Context\Traits\ContentAwareContextTrait;
use PaulGibbs\WordpressBehatExtension\Context\Interfaces\ContentAwareContextInterface;

/**
* Provides step definitions relating to editing content in wp-admin.
*/
class EditPostContext extends RawWordpressContext
class EditPostContext extends RawWordpressContext implements ContentAwareContextInterface
{
use ContentAwareContextTrait;
/**
Expand Down
Loading