MDL-55365 behat: Remove deprecated api's in behat_config_mananger.php

This commit is contained in:
cescobedo 2018-07-20 09:34:26 +02:00
parent 8c51626841
commit 8d2432f543
3 changed files with 47 additions and 352 deletions

View file

@ -1,199 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for behat manager.
*
* @package tool_behat
* @copyright 2012 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/' . $CFG->admin .'/tool/behat/locallib.php');
require_once($CFG->libdir . '/behat/classes/util.php');
require_once($CFG->libdir . '/behat/classes/behat_config_manager.php');
/**
* Behat manager tests.
*
* @package tool_behat
* @copyright 2012 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_behat_manager_testcase extends advanced_testcase {
/**
* behat_config_manager tests.
*/
public function test_merge_configs() {
// Simple default config.
$array1 = array(
'the' => 'same',
'simple' => 'value',
'array' => array(
'one' => 'arrayvalue1',
'two' => 'arrayvalue2'
)
);
// Simple override.
$array2 = array(
'simple' => 'OVERRIDDEN1',
'array' => array(
'one' => 'OVERRIDDEN2'
),
'newprofile' => array(
'anotherlevel' => array(
'andanotherone' => array(
'list1',
'list2'
)
)
)
);
$array = testable_behat_config_manager::merge_config($array1, $array2);
$this->assertDebuggingCalled("Use of merge_config is deprecated, please see behat_config_util");
// Overrides are applied.
$this->assertEquals('OVERRIDDEN1', $array['simple']);
$this->assertEquals('OVERRIDDEN2', $array['array']['one']);
// Other values are respected.
$this->assertNotEmpty($array['array']['two']);
// Completely new nodes are added.
$this->assertNotEmpty($array['newprofile']);
$this->assertNotEmpty($array['newprofile']['anotherlevel']['andanotherone']);
$this->assertEquals('list1', $array['newprofile']['anotherlevel']['andanotherone'][0]);
$this->assertEquals('list2', $array['newprofile']['anotherlevel']['andanotherone'][1]);
// Complex override changing vectors to scalars and scalars to vectors.
$array2 = array(
'simple' => array(
'simple' => 'should',
'be' => 'overridden',
'by' => 'this-array'
),
'array' => 'one'
);
$array = testable_behat_config_manager::merge_config($array1, $array2);
$this->assertDebuggingCalled("Use of merge_config is deprecated, please see behat_config_util");
// Overrides applied.
$this->assertNotEmpty($array['simple']);
$this->assertNotEmpty($array['array']);
$this->assertTrue(is_array($array['simple']));
$this->assertFalse(is_array($array['array']));
// Other values are maintained.
$this->assertEquals('same', $array['the']);
}
/**
* behat_config_manager tests.
*/
public function test_config_file_contents() {
global $CFG;
$this->resetAfterTest(true);
// Skip tests if behat is not installed.
$vendorpath = $CFG->dirroot . '/vendor';
if (!file_exists($vendorpath . '/autoload.php') || !is_dir($vendorpath . '/behat')) {
$this->markTestSkipped('Behat not installed.');
}
// Add some fake test url.
$CFG->behat_wwwroot = 'http://example.com/behat';
// To avoid user value at config.php level.
unset($CFG->behat_config);
// List.
$features = array(
'feature1',
'feature2',
'feature3'
);
// Associative array.
$stepsdefinitions = array(
'micarro' => '/me/lo/robaron',
'anoche' => '/cuando/yo/dormia'
);
$contents = testable_behat_config_manager::get_config_file_contents($features, $stepsdefinitions);
$this->assertDebuggingCalled("Use of get_config_file_contents is deprecated, please see behat_config_util");
// YAML decides when is is necessary to wrap strings between single quotes, so not controlled
// values like paths should not be asserted including the key name as they would depend on the
// directories values.
$this->assertContains($CFG->dirroot,
$contents['default']['extensions']['Moodle\BehatExtension']['moodledirroot']);
// Not quoted strings.
$this->assertEquals('/me/lo/robaron',
$contents['default']['extensions']['Moodle\BehatExtension']['steps_definitions']['micarro']);
// YAML uses single quotes to wrap URL strings.
$this->assertEquals($CFG->behat_wwwroot, $contents['default']['extensions']['Behat\MinkExtension']['base_url']);
// Lists.
$this->assertEquals('feature1', $contents['default']['suites']['default']['paths'][0]);
$this->assertEquals('feature3', $contents['default']['suites']['default']['paths'][2]);
unset($CFG->behat_wwwroot);
}
}
/**
* Allows access to internal methods without exposing them.
*
* @package tool_behat
* @copyright 2012 David Monllaó
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class testable_behat_config_manager extends behat_config_manager {
/**
* Allow access to protected method
* @see parent::merge_config()
* @param mixed $config
* @param mixed $localconfig
* @return mixed
*/
public static function merge_config($config, $localconfig) {
return parent::merge_config($config, $localconfig);
}
/**
* Allow access to protected method
* @see parent::get_config_file_contents()
* @param array $features
* @param array $stepsdefinitions
* @return string
*/
public static function get_config_file_contents($features, $stepsdefinitions) {
return parent::get_config_file_contents($features, $stepsdefinitions);
}
}

View file

@ -132,37 +132,19 @@ class behat_config_manager {
} }
/** /**
* Search feature files for set of tags. * @deprecated since 3.2 - please use behat_config_util.php
*
* @param array $features set of feature files.
* @param string $tags list of tags (currently support && only.)
* @return array filtered list of feature files with tags.
* @deprecated since 3.2 MDL-55072 - please use behat_config_util.php
* @todo MDL-55365 This will be deleted in Moodle 3.6.
*/ */
public static function get_features_with_tags($features, $tags) { public static function get_features_with_tags() {
throw new coding_exception('get_features_with_tags() can not be used anymore. ' .
debugging('Use of get_features_with_tags is deprecated, please see behat_config_util', DEBUG_DEVELOPER); 'Please use behat_config_util instead.');
return self::get_behat_config_util()->filtered_features_with_tags($features, $tags);
} }
/** /**
* Gets the list of Moodle steps definitions * @deprecated since 3.2 - please use behat_config_util.php
*
* Class name as a key and the filepath as value
*
* Externalized from update_config_file() to use
* it from the steps definitions web interface
*
* @return array
* @deprecated since 3.2 MDL-55072 - please use behat_config_util.php
* @todo MDL-55365 This will be deleted in Moodle 3.6.
*/ */
public static function get_components_steps_definitions() { public static function get_components_steps_definitions() {
throw new coding_exception('get_components_steps_definitions() can not be used anymore. ' .
debugging('Use of get_components_steps_definitions is deprecated, please see behat_config_util::get_components_contexts', 'Please use behat_config_util instead.');
DEBUG_DEVELOPER);
return self::get_behat_config_util()->get_components_contexts();
} }
/** /**
@ -321,160 +303,59 @@ class behat_config_manager {
} }
/** /**
* Behat config file specifing the main context class, * @deprecated since 3.2 - please use behat_config_util.php
* the required Behat extensions and Moodle test wwwroot.
*
* @param array $features The system feature files
* @param array $stepsdefinitions The system steps definitions
* @return string
* @deprecated since 3.2 MDL-55072 - please use behat_config_util.php
* @todo MDL-55365 This will be deleted in Moodle 3.6.
*/ */
protected static function get_config_file_contents($features, $stepsdefinitions) { protected static function get_config_file_contents() {
throw new coding_exception('get_config_file_contents() can not be used anymore. ' .
debugging('Use of get_config_file_contents is deprecated, please see behat_config_util', DEBUG_DEVELOPER); 'Please use behat_config_util instead.');
return self::get_behat_config_util()->get_config_file_contents($features, $stepsdefinitions);
} }
/** /**
* Parse $CFG->behat_config and return the array with required config structure for behat.yml * @deprecated since 3.2 - please use behat_config_util.php
*
* @param string $profile profile name
* @param array $values values for profile
* @return array
* @deprecated since 3.2 MDL-55072 - please use behat_config_util.php
* @todo MDL-55365 This will be deleted in Moodle 3.6.
*/ */
protected static function merge_behat_config($profile, $values) { protected static function merge_behat_config() {
throw new coding_exception('merge_behat_config() can not be used anymore. ' .
debugging('Use of merge_behat_config is deprecated, please see behat_config_util', DEBUG_DEVELOPER); 'Please use behat_config_util instead.');
self::get_behat_config_util()->get_behat_config_for_profile($profile, $values);
} }
/** /**
* Parse $CFG->behat_profile and return the array with required config structure for behat.yml. * @deprecated since 3.2 - please use behat_config_util.php
*
* $CFG->behat_profiles = array(
* 'profile' = array(
* 'browser' => 'firefox',
* 'tags' => '@javascript',
* 'wd_host' => 'http://127.0.0.1:4444/wd/hub',
* 'capabilities' => array(
* 'platform' => 'Linux',
* 'version' => 44
* )
* )
* );
*
* @param string $profile profile name
* @param array $values values for profile.
* @return array
*/ */
protected static function get_behat_profile($profile, $values) { protected static function get_behat_profile() {
// Values should be an array. throw new coding_exception('get_behat_profile() can not be used anymore. ' .
if (!is_array($values)) { 'Please use behat_config_util instead.');
return array();
}
// Check suite values.
$behatprofilesuites = array();
// Fill tags information.
if (isset($values['tags'])) {
$behatprofilesuites = array(
'suites' => array(
'default' => array(
'filters' => array(
'tags' => $values['tags'],
)
)
)
);
}
// Selenium2 config values.
$behatprofileextension = array();
$seleniumconfig = array();
if (isset($values['browser'])) {
$seleniumconfig['browser'] = $values['browser'];
}
if (isset($values['wd_host'])) {
$seleniumconfig['wd_host'] = $values['wd_host'];
}
if (isset($values['capabilities'])) {
$seleniumconfig['capabilities'] = $values['capabilities'];
}
if (!empty($seleniumconfig)) {
$behatprofileextension = array(
'extensions' => array(
'Behat\MinkExtension' => array(
'selenium2' => $seleniumconfig,
)
)
);
}
return array($profile => array_merge($behatprofilesuites, $behatprofileextension));
} }
/** /**
* Attempt to split feature list into fairish buckets using timing information, if available. * @deprecated since 3.2 - please use behat_config_util.php
* Simply add each one to lightest buckets until all files allocated.
* PGA = Profile Guided Allocation. I made it up just now.
* CAUTION: workers must agree on allocation, do not be random anywhere!
*
* @param array $features Behat feature files array
* @param int $nbuckets Number of buckets to divide into
* @param int $instance Index number of this instance
* @return array Feature files array, sorted into allocations
*/ */
protected static function profile_guided_allocate($features, $nbuckets, $instance) { protected static function profile_guided_allocate() {
throw new coding_exception('profile_guided_allocate() can not be used anymore. ' .
debugging('Use of profile_guided_allocate is deprecated, please see behat_config_util', DEBUG_DEVELOPER); 'Please use behat_config_util instead.');
return self::get_behat_config_util()->profile_guided_allocate($features, $nbuckets, $instance);
} }
/** /**
* Overrides default config with local config values * @deprecated since 3.2 - please use behat_config_util.php
*
* array_merge does not merge completely the array's values
*
* @param mixed $config The node of the default config
* @param mixed $localconfig The node of the local config
* @return mixed The merge result
* @deprecated since 3.2 MDL-55072 - please use behat_config_util.php
* @todo MDL-55365 This will be deleted in Moodle 3.6.
*/ */
protected static function merge_config($config, $localconfig) { protected static function merge_config() {
throw new coding_exception('merge_config() can not be used anymore. ' .
debugging('Use of merge_config is deprecated, please see behat_config_util', DEBUG_DEVELOPER); 'Please use behat_config_util instead.');
return self::get_behat_config_util()->merge_config($config, $localconfig);
} }
/** /**
* Cleans the path returned by get_components_with_tests() to standarize it * @deprecated since 3.2 - please use behat_config_util.php
*
* @see tests_finder::get_all_directories_with_tests() it returns the path including /tests/
* @param string $path
* @return string The string without the last /tests part
* @deprecated since 3.2 MDL-55072 - please use behat_config_util.php
* @todo MDL-55365 This will be deleted in Moodle 3.6.
*/ */
protected final static function clean_path($path) { protected final static function clean_path() {
throw new coding_exception('clean_path() can not be used anymore. ' .
debugging('Use of clean_path is deprecated, please see behat_config_util', DEBUG_DEVELOPER); 'Please use behat_config_util instead.');
return self::get_behat_config_util()->clean_path($path);
} }
/** /**
* The relative path where components stores their behat tests * @deprecated since 3.2 - please use behat_config_util.php
*
* @return string
* @deprecated since 3.2 MDL-55072 - please use behat_config_util.php
* @todo MDL-55365 This will be deleted in Moodle 3.6.
*/ */
protected final static function get_behat_tests_path() { protected final static function get_behat_tests_path() {
debugging('Use of get_behat_tests_path is deprecated, please see behat_config_util', DEBUG_DEVELOPER); throw new coding_exception('get_behat_tests_path() can not be used anymore. ' .
return self::get_behat_config_util()->get_behat_tests_path(); 'Please use behat_config_util instead.');
} }
} }

View file

@ -1,6 +1,19 @@
This files describes API changes in core libraries and APIs, This files describes API changes in core libraries and APIs,
information provided here is intended especially for developers. information provided here is intended especially for developers.
=== 3.6 ===
* Following api's have been removed in behat_config_manager, please use behat_config_util instead.
- get_features_with_tags()
- get_components_steps_definitions()
- get_config_file_contents()
- merge_behat_config()
- get_behat_profile()
- profile_guided_allocate()
- merge_config()
- clean_path()
- get_behat_tests_path()
=== 3.5 === === 3.5 ===
* There is a new privacy API that every subsystem and plugin has to implement so that the site can become GDPR * There is a new privacy API that every subsystem and plugin has to implement so that the site can become GDPR