Skip to content
Snippets Groups Projects
Commit 3c081d6e authored by jurgenhaas's avatar jurgenhaas
Browse files

Move scripts to composer commands

parent 2981d6c8
No related branches found
No related tags found
No related merge requests found
......@@ -7,5 +7,5 @@ commands:
cmd: docker-compose exec -T --user root php ./vendor/bin/behat --config tests/behat/behat.yml --format junit --out tests/output "$@"
usage: Run Behat tests on the project and output in junit format
update:
cmd: composer b4d "$@"
usage: Update Behat4Drupal setup in project
cmd: composer lakedrops:behat
usage: (Re-)Configure Behat for this project
......@@ -29,6 +29,7 @@
"source": "https://gitlab.lakedrops.com/composer/plugin/behat4drupal/tree/master"
},
"require": {
"php": ">=7.0",
"behat/behat": "^3.5",
"behat/mink": "^1.7",
"behat/mink-goutte-driver": "^1.2",
......@@ -38,10 +39,10 @@
"drush-ops/behat-drush-endpoint": "^9.2",
"jcalderonzumba/gastonjs": "^1.2",
"jcalderonzumba/mink-phantomjs-driver": "^0.3",
"lakedrops/composer-json-utils": "^1.3.1",
"lakedrops/composer-scripts": "^1.1.0",
"lakedrops/docker4drupal": "^1.8.6",
"lakedrops/dotenv": "^1.0.0",
"php": ">=5.6",
"twig/twig": "^1.23.1"
},
"require-dev": {
......@@ -58,14 +59,8 @@
"extra": {
"class": "LakeDrops\\Behat4Drupal\\Plugin",
"lakedrops": {
"scripts": {
"b4d": {
"callback": "LakeDrops\\Behat4Drupal\\Plugin::config",
"description": "(Re-)Configure Behat for this project."
}
},
"ahoy": {
"b4d": {
"behat": {
"usage": "Behat for Drupal",
"imports": ["ahoy.yml"]
}
......
<?php
namespace LakeDrops\Behat4Drupal;
use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;
use Composer\Command\BaseCommand;
class CommandProvider implements CommandProviderCapability {
/**
* Retrieves an array of commands
*
* @return BaseCommand[]
*/
public function getCommands(): array {
return [
new UpdateCommand(),
];
}
}
......@@ -2,7 +2,6 @@
namespace LakeDrops\Behat4Drupal;
use Composer\Script\Event;
use LakeDrops\Component\Composer\BaseHandler;
use LakeDrops\Component\Dotenv\Dotenv;
use LakeDrops\Docker4Drupal\Handler as D4DHandler;
......@@ -19,8 +18,6 @@ class Handler extends BaseHandler {
/**
* Post project create event to execute the scaffolding.
*
* @param \Composer\Script\Event $event
* The event that triggered the plugin.
* @param bool $overwrite
* Whether to overwrite existing config files.
*
......@@ -28,10 +25,10 @@ class Handler extends BaseHandler {
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*/
public function configureProject(Event $event, $overwrite = FALSE) {
public function configureProject($overwrite = FALSE) {
// We only do the fancy stuff for developers.
if (!$event->isDevMode()) {
if (!$this->isDevMode()) {
return;
}
......@@ -64,7 +61,7 @@ class Handler extends BaseHandler {
$rendered = Yaml::dump($yaml, 9, 2);
}
if ($fs->exists($file)) {
if (md5_file($file) == md5($rendered)) {
if (md5_file($file) === md5($rendered)) {
continue;
}
$orig_file = $file . '.orig';
......@@ -90,7 +87,7 @@ class Handler extends BaseHandler {
* @return array
* List of files.
*/
protected function getFiles($projectRoot) {
protected function getFiles($projectRoot): array {
return [
'behat.yml' => [
'dest' => $projectRoot . '/tests/behat',
......@@ -113,7 +110,7 @@ class Handler extends BaseHandler {
* @return array
* The settings from the extra configuration.
*/
protected function getOptions() {
protected function getOptions(): array {
$handler = new D4DHandler($this->composer, $this->io);
$projectname = $handler->getOptions('projectname');
$webserver = $handler->getOptions('webserver');
......
......@@ -21,35 +21,37 @@ class Plugin extends BasePlugin {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return array(
ScriptEvents::POST_CREATE_PROJECT_CMD => 'postCreateProject',
);
public function getCapabilities(): array {
return [
\Composer\Plugin\Capability\CommandProvider::class => CommandProvider::class,
];
}
/**
* Post create project event callback.
*
* @param \Composer\Script\Event $event
* The event that triggered the plugin.
* {@inheritdoc}
*/
public function postCreateProject(Event $event) {
$this->handler->configureProject($event);
public static function getSubscribedEvents(): array {
return [
ScriptEvents::POST_CREATE_PROJECT_CMD => 'postCreateProject',
];
}
/**
* Script callback for putting in composer scripts to configure the project.
* Post create project event callback.
*
* @param \Composer\Script\Event $event
* The event that triggered the call of this function.
* The event that triggered the plugin.
*
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*/
public static function config(Event $event) {
$handler = new Handler($event->getComposer(), $event->getIO());
$handler->configureProject($event, TRUE);
public function postCreateProject(Event $event) {
/** @var Handler $handler */
$handler = $this->handler;
$handler
->setEvent($event)
->configureProject();
}
}
<?php
namespace LakeDrops\Behat4Drupal;
use LakeDrops\Component\Composer\BaseCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class UpdateCommand extends BaseCommand {
/**
* {@inheritdoc}
*/
protected function configure() {
$this->setName('lakedrops:behat');
$this->setDescription('(Re-)Configure Behat for this project.');
}
/**
* {@inheritdoc}
*/
public function getHandlerClass() {
return Handler::class;
}
/**
* {@inheritdoc}
*
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*/
protected function execute(InputInterface $input, OutputInterface $output) {
parent::execute($input, $output);
/** @var Handler $handler */
$handler = $this->handler;
$handler->configureProject(TRUE);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment