Skip to content

Commit

Permalink
Add BehatCommands for Drush 9 (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Rosborough authored and greg-1-anderson committed Sep 20, 2018
1 parent 54aa39c commit 96cdc8f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
50 changes: 50 additions & 0 deletions BehatDrushEndpointCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Drush\Commands\behat_drush_endpoint;

use Drush\Commands\DrushCommands;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\TermInterface;

/**
* A Drush commandfile.
*
* Contains Behat Drush commands, for use by the Behat Drush Extension.
* These commands are specifically for Drush 9
*/
class BehatDrushEndpointCommands extends DrushCommands
{

public function __construct() {
include __DIR__ . '/behat.d8.drush.inc';
}

/**
* Behat Drush endpoint. Serves as an entrypoint for Behat to make remote calls into the Drupal site being tested.
*
* @param $operation
* Behat operation, e.g. create-node.
* @param $data
* Operation data in json format.
* @usage drush behat create-node '{"title":"Example page","type":"page"}'
* Create a page with the title "Example page".
*
* @bootstrap full
* @command behat
*/
public function behat($operation, $data, $options = ['format' => 'json']) {
$obj = json_decode($data);

// Dispatch if the operation exists.
$fn = 'drush_behat_op_' . strtr($operation, '-', '_');
if (function_exists($fn)) {
return $fn($obj);
}
else {
throw new \Exception(dt("Operation '!op' unknown", array('!op' => $operation)));
}
}
}
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"homepage": "https://github.com/drush-ops/behat-drush-endpoint",
"license": "GPL-2.0-or-later",
"require": {
"php": ">=5.3.0",
"composer/installers": "~1.0"
"php": ">=5.3.0"
}
}

0 comments on commit 96cdc8f

Please sign in to comment.