diff --git a/behat_ui.info b/behat_ui.info index 23c0328..b7df135 100644 --- a/behat_ui.info +++ b/behat_ui.info @@ -1,3 +1,4 @@ name = Behat UI description = "Create and run Behat/Mink tests from the web interface" core = 7.x +dependencies[] = composer_manager diff --git a/behat_ui.module b/behat_ui.module index 943c56d..7acf5c3 100644 --- a/behat_ui.module +++ b/behat_ui.module @@ -4,6 +4,10 @@ * Main behat_ui file */ +// Adding Symfony components +use Symfony\Component\Yaml\Parser; +use Symfony\Component\Yaml\Exception\ParseException; + /** * Implements hook_init(). */ @@ -370,10 +374,19 @@ function behat_ui_ajax_add_step($form, $form_state) { function _behat_ui_create($form, &$form_state) { global $user, $base_root; + $behat_bin = variable_get('behat_ui_behat_bin_path', 'bin/behat'); $behat_config_path = variable_get('behat_ui_behat_config_path', '.'); $features_path = 'features'; - if (extension_loaded('yaml')) { + + // Attempt to load the config with Composer library first + $behat_config = load_behat_config(); + + if (!empty($behat_config)) { + $features_path = $behat_config['default']['paths']['features'];; + } + // Otherwise try the PHP extension technique + if (extension_loaded('yaml') && empty($behat_config)) { $behat_config = yaml_parse(file_get_contents($behat_config_path . '/behat.yml')); $features_path = $behat_config['default']['paths']['features']; } @@ -432,7 +445,15 @@ function _behat_ui_steps() { function _behat_ui_features() { $behat_config_path = variable_get('behat_ui_behat_config_path', '.'); $features_path = 'features'; - if (extension_loaded('yaml')) { + + // Attempt to load the config with Composer library first + $behat_config = load_behat_config(); + + if (!empty($behat_config)) { + $features_path = $behat_config['default']['paths']['features'];; + } + // Otherwise try the PHP extension technique + if (extension_loaded('yaml') && empty($behat_config)) { $behat_config = yaml_parse(file_get_contents($behat_config_path . '/behat.yml')); $features_path = $behat_config['default']['paths']['features']; } @@ -569,3 +590,23 @@ function _behat_ui_kill() { drupal_json_output(array('response' => $response)); } + +/** + * Adding support for the Symfony yaml parser so everything can be setup through Composer + * + * @return array + */ +function load_behat_config() { + + $yaml = new Parser(); + $behat_config = array(); + + try { + $behat_config = $yaml->parse(file_get_contents($behat_config_path . '/behat.yml')); + } + catch (ParseException $e) { + drupal_set_message(t('Extension yaml is not loaded. Could not parse behat.yml file.'), 'error'); + watchdog('behat_ui', t('Could not parse Behat config file, check Composer libraries, file permissions and Behat config: Error = @error', array('@error' => $e)), WATCHDOG_ERROR); + } + return($behat_config); +} \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..fd9fb5a --- /dev/null +++ b/composer.json @@ -0,0 +1,9 @@ +{ + "require": { + "symfony/yaml": ">=2.5.7", + "symfony/process": ">=2.5.7", + "behat/behat": ">=3.0.14", + "behat/mink": ">=1.6.0", + "behat/mink-browserkit-driver": ">=1.2.0" + } +} \ No newline at end of file