diff --git a/src/SilverStripe/BehatExtension/Compiler/MinkExtensionBaseUrlPass.php b/src/SilverStripe/BehatExtension/Compiler/MinkExtensionBaseUrlPass.php index d6d7c27..deb34d3 100644 --- a/src/SilverStripe/BehatExtension/Compiler/MinkExtensionBaseUrlPass.php +++ b/src/SilverStripe/BehatExtension/Compiler/MinkExtensionBaseUrlPass.php @@ -35,10 +35,10 @@ class MinkExtensionBaseUrlPass implements CompilerPassInterface if (!$container->hasParameter('behat.mink.base_url')) { throw new \Exception('MinkExtension improperly configured. Missing base_url parameter.'); } - $base_url = $container->getParameter('behat.mink.base_url'); - if (empty($base_url)) { + $baseUrl = $container->getParameter('behat.mink.base_url'); + if (empty($baseUrl)) { throw new \Exception('MinkExtension improperly configured. Missing or empty base_url parameter.'); } - $container->setParameter('behat.silverstripe_extension.framework_host', $base_url); + $container->setParameter('behat.silverstripe_extension.framework_host', $baseUrl); } } diff --git a/src/SilverStripe/BehatExtension/Context/BasicContext.php b/src/SilverStripe/BehatExtension/Context/BasicContext.php index 01cd506..d8af927 100644 --- a/src/SilverStripe/BehatExtension/Context/BasicContext.php +++ b/src/SilverStripe/BehatExtension/Context/BasicContext.php @@ -107,10 +107,10 @@ JS; */ public function handleAjaxBeforeStep(StepEvent $event) { - $ajax_enabled_steps = $this->getMainContext()->getAjaxSteps(); - $ajax_enabled_steps = implode('|', array_filter($ajax_enabled_steps)); + $ajaxEnabledSteps = $this->getMainContext()->getAjaxSteps(); + $ajaxEnabledSteps = implode('|', array_filter($ajaxEnabledSteps)); - if (empty($ajax_enabled_steps) || !preg_match('/(' . $ajax_enabled_steps . ')/i', $event->getStep()->getText())) { + if (empty($ajaxEnabledSteps) || !preg_match('/(' . $ajaxEnabledSteps . ')/i', $event->getStep()->getText())) { return; } @@ -150,10 +150,10 @@ JS; */ public function handleAjaxAfterStep(StepEvent $event) { - $ajax_enabled_steps = $this->getMainContext()->getAjaxSteps(); - $ajax_enabled_steps = implode('|', array_filter($ajax_enabled_steps)); + $ajaxEnabledSteps = $this->getMainContext()->getAjaxSteps(); + $ajaxEnabledSteps = implode('|', array_filter($ajaxEnabledSteps)); - if (empty($ajax_enabled_steps) || !preg_match('/(' . $ajax_enabled_steps . ')/i', $event->getStep()->getText())) { + if (empty($ajaxEnabledSteps) || !preg_match('/(' . $ajaxEnabledSteps . ')/i', $event->getStep()->getText())) { return; } @@ -205,7 +205,7 @@ JS; $parent = $event->getLogicalParent(); $feature = $parent->getFeature(); $step = $event->getStep(); - $screenshot_path = null; + $screenshotPath = null; $path = $this->getMainContext()->getScreenshotPath(); if(!$path) return; // quit silently when path is not set @@ -267,10 +267,10 @@ JS; { $page = $this->getSession()->getPage(); - $button_element = $page->find('named', array('link_or_button', "'$button'")); - assertNotNull($button_element, sprintf('%s button not found', $button)); + $buttonElement = $page->find('named', array('link_or_button', "'$button'")); + assertNotNull($buttonElement, sprintf('%s button not found', $button)); - $button_element->click(); + $buttonElement->click(); } /** @@ -280,10 +280,10 @@ JS; { $page = $this->getSession()->getPage(); - $parent_element = $page->find('css', $selector); - assertNotNull($parent_element, sprintf('"%s" element not found', $selector)); + $parentElement = $page->find('css', $selector); + assertNotNull($parentElement, sprintf('"%s" element not found', $selector)); - $element = $parent_element->find('xpath', sprintf('//*[count(*)=0 and contains(.,"%s")]', $text)); + $element = $parentElement->find('xpath', sprintf('//*[count(*)=0 and contains(.,"%s")]', $text)); assertNotNull($element, sprintf('"%s" not found', $text)); $element->click(); diff --git a/src/SilverStripe/BehatExtension/Context/Initializer/SilverStripeAwareInitializer.php b/src/SilverStripe/BehatExtension/Context/Initializer/SilverStripeAwareInitializer.php index 800c651..d5f18bc 100644 --- a/src/SilverStripe/BehatExtension/Context/Initializer/SilverStripeAwareInitializer.php +++ b/src/SilverStripe/BehatExtension/Context/Initializer/SilverStripeAwareInitializer.php @@ -25,7 +25,7 @@ use SilverStripe\BehatExtension\Context\SilverStripeAwareContextInterface; class SilverStripeAwareInitializer implements InitializerInterface { - private $database_name; + private $databaseName; /** * @var Array @@ -55,10 +55,10 @@ class SilverStripeAwareInitializer implements InitializerInterface /** * Initializes initializer. */ - public function __construct($framework_path, $framework_host) + public function __construct($frameworkPath, $frameworkHost) { - $this->bootstrap($framework_path, $framework_host); - $this->database_name = $this->initializeTempDb(); + $this->bootstrap($frameworkPath, $frameworkHost); + $this->databaseName = $this->initializeTempDb(); } public function __destruct() @@ -85,7 +85,7 @@ class SilverStripeAwareInitializer implements InitializerInterface */ public function initialize(ContextInterface $context) { - $context->setDatabase($this->database_name); + $context->setDatabase($this->databaseName); $context->setAjaxSteps($this->ajaxSteps); $context->setAjaxTimeout($this->ajaxTimeout); $context->setScreenshotPath($this->screenshotPath); @@ -143,17 +143,17 @@ class SilverStripeAwareInitializer implements InitializerInterface return $this->screenshotPath; } - protected function bootstrap($framework_path, $framework_host) + protected function bootstrap($frameworkPath, $frameworkHost) { file_put_contents('php://stderr', 'Bootstrapping' . PHP_EOL); // Set file to URL mappings global $_FILE_TO_URL_MAPPING; - $_FILE_TO_URL_MAPPING[dirname($framework_path)] = $framework_host; + $_FILE_TO_URL_MAPPING[dirname($frameworkPath)] = $frameworkHost; // Connect to database and build manifest $_GET['flush'] = 1; - require_once $framework_path . '/core/Core.php'; + require_once $frameworkPath . '/core/Core.php'; unset($_GET['flush']); // Remove the error handler so that PHPUnit can add its own diff --git a/src/SilverStripe/BehatExtension/Context/LoginContext.php b/src/SilverStripe/BehatExtension/Context/LoginContext.php index b9c5de7..9d864ca 100644 --- a/src/SilverStripe/BehatExtension/Context/LoginContext.php +++ b/src/SilverStripe/BehatExtension/Context/LoginContext.php @@ -54,14 +54,14 @@ class LoginContext extends BehatContext public function stepIAmLoggedIn() { $c = $this->getMainContext(); - $admin_url = $c->joinUrlParts($c->getBaseUrl(), $c->getAdminUrl()); - $login_url = $c->joinUrlParts($c->getBaseUrl(), $c->getLoginUrl()); + $adminUrl = $c->joinUrlParts($c->getBaseUrl(), $c->getAdminUrl()); + $loginUrl = $c->joinUrlParts($c->getBaseUrl(), $c->getLoginUrl()); - $this->getSession()->visit($admin_url); + $this->getSession()->visit($adminUrl); - if (0 == strpos($this->getSession()->getCurrentUrl(), $login_url)) { + if (0 == strpos($this->getSession()->getCurrentUrl(), $loginUrl)) { $this->stepILogInWith('admin', 'password'); - assertStringStartsWith($admin_url, $this->getSession()->getCurrentUrl()); + assertStringStartsWith($adminUrl, $this->getSession()->getCurrentUrl()); } } @@ -113,17 +113,17 @@ class LoginContext extends BehatContext public function stepILogInWith($email, $password) { $c = $this->getMainContext(); - $login_url = $c->joinUrlParts($c->getBaseUrl(), $c->getLoginUrl()); + $loginUrl = $c->joinUrlParts($c->getBaseUrl(), $c->getLoginUrl()); - $this->getSession()->visit($login_url); + $this->getSession()->visit($loginUrl); $page = $this->getSession()->getPage(); - $email_field = $page->find('css', '[name=Email]'); - $password_field = $page->find('css', '[name=Password]'); + $emailField = $page->find('css', '[name=Email]'); + $passwordField = $page->find('css', '[name=Password]'); $submit_button = $page->find('css', '[type=submit]'); - $email_field->setValue($email); - $password_field->setValue($password); + $emailField->setValue($email); + $passwordField->setValue($password); $submit_button->press(); } @@ -134,8 +134,8 @@ class LoginContext extends BehatContext { $page = $this->getSession()->getPage(); - $login_form = $page->find('css', '#MemberLoginForm_LoginForm'); - assertNotNull($login_form, 'I should see a log-in form'); + $loginForm = $page->find('css', '#MemberLoginForm_LoginForm'); + assertNotNull($loginForm, 'I should see a log-in form'); } /** @@ -145,8 +145,8 @@ class LoginContext extends BehatContext { $page = $this->getSession()->getPage(); - $bad_message = $page->find('css', '.message.bad'); + $badMessage = $page->find('css', '.message.bad'); - assertNotNull($bad_message, 'Bad message not found.'); + assertNotNull($badMessage, 'Bad message not found.'); } } diff --git a/src/SilverStripe/BehatExtension/Context/SilverStripeAwareContextInterface.php b/src/SilverStripe/BehatExtension/Context/SilverStripeAwareContextInterface.php index 71f8955..e81a060 100644 --- a/src/SilverStripe/BehatExtension/Context/SilverStripeAwareContextInterface.php +++ b/src/SilverStripe/BehatExtension/Context/SilverStripeAwareContextInterface.php @@ -23,12 +23,12 @@ interface SilverStripeAwareContextInterface * * @param String $database_name Temp database name */ - public function setDatabase($database_name); + public function setDatabase($databaseName); /** * Marks steps as AJAX steps for special treatment * * @param array $ajax_steps Array of step name parts to match */ - public function setAjaxSteps($ajax_steps); + public function setAjaxSteps($ajaxSteps); } diff --git a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php index 77599bc..9c84fba 100644 --- a/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php +++ b/src/SilverStripe/BehatExtension/Context/SilverStripeContext.php @@ -26,7 +26,7 @@ require_once 'vendor/autoload.php'; */ class SilverStripeContext extends MinkContext implements SilverStripeAwareContextInterface { - protected $database_name; + protected $databaseName; /** * @var Array Partial string match for step names @@ -60,9 +60,9 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex protected $context; protected $fixtures; - protected $fixtures_lazy; - protected $files_path; - protected $created_files_paths; + protected $fixturesLazy; + protected $filesPath; + protected $createdFilesPaths; /** * Initializes context. @@ -76,9 +76,9 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex $this->context = $parameters; } - public function setDatabase($database_name) + public function setDatabase($databaseName) { - $this->database_name = $database_name; + $this->databaseName = $databaseName; } public function setAjaxSteps($ajaxSteps) @@ -131,13 +131,13 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex return $this->screenshotPath; } - public function getFixture($data_object) + public function getFixture($dataObject) { - if (!array_key_exists($data_object, $this->fixtures)) { - throw new \OutOfBoundsException(sprintf('Data object `%s` does not exist!', $data_object)); + if (!array_key_exists($dataObject, $this->fixtures)) { + throw new \OutOfBoundsException(sprintf('Data object `%s` does not exist!', $dataObject)); } - return $this->fixtures[$data_object]; + return $this->fixtures[$dataObject]; } public function getFixtures() @@ -150,13 +150,13 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex */ public function before(ScenarioEvent $event) { - if (!isset($this->database_name)) { - throw new \LogicException('Context\'s $database_name has to be set when implementing SilverStripeAwareContextInterface.'); + if (!isset($this->databaseName)) { + throw new \LogicException('Context\'s $databaseName has to be set when implementing SilverStripeAwareContextInterface.'); } - $setdb_url = $this->joinUrlParts($this->getBaseUrl(), '/dev/tests/setdb'); - $setdb_url = sprintf('%s?database=%s', $setdb_url, $this->database_name); - $this->getSession()->visit($setdb_url); + $setdbUrl = $this->joinUrlParts($this->getBaseUrl(), '/dev/tests/setdb'); + $setdbUrl = sprintf('%s?database=%s', $setdbUrl, $this->databaseName); + $this->getSession()->visit($setdbUrl); } /** @@ -188,9 +188,9 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex */ public function afterResetAssets(ScenarioEvent $event) { - if (is_array($this->created_files_paths)) { - $created_files = array_reverse($this->created_files_paths); - foreach ($created_files as $path) { + if (is_array($this->createdFilesPaths)) { + $createdFiles = array_reverse($this->createdFilesPaths); + foreach ($createdFiles as $path) { if (is_dir($path)) { \Filesystem::removeFolder($path); } else { @@ -204,44 +204,44 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex /** * @Given /^there are the following ([^\s]*) records$/ */ - public function thereAreTheFollowingRecords($data_object, PyStringNode $string) + public function thereAreTheFollowingRecords($dataObject, PyStringNode $string) { if (!is_array($this->fixtures)) { $this->fixtures = array(); } - if (!is_array($this->fixtures_lazy)) { - $this->fixtures_lazy = array(); + if (!is_array($this->fixturesLazy)) { + $this->fixturesLazy = array(); } - if (!isset($this->files_path)) { - $this->files_path = realpath($this->getMinkParameter('files_path')); + if (!isset($this->filesPath)) { + $this->filesPath = realpath($this->getMinkParameter('files_path')); } - if (!is_array($this->created_files_paths)) { - $this->created_files_paths = array(); + if (!is_array($this->createdFilesPaths)) { + $this->createdFilesPaths = array(); } - if (array_key_exists($data_object, $this->fixtures)) { - throw new \InvalidArgumentException(sprintf('Data object `%s` already exists!', $data_object)); + if (array_key_exists($dataObject, $this->fixtures)) { + throw new \InvalidArgumentException(sprintf('Data object `%s` already exists!', $dataObject)); } - $fixture = array_merge(array($data_object . ':'), $string->getLines()); + $fixture = array_merge(array($dataObject . ':'), $string->getLines()); $fixture = implode("\n ", $fixture); - if ('Folder' === $data_object) { + if ('Folder' === $dataObject) { $this->prepareTestAssetsDirectories($fixture); } - if ('File' === $data_object) { + if ('File' === $dataObject) { $this->prepareTestAssetsFiles($fixture); } - $fixtures_lazy = array($data_object => array()); + $fixturesLazy = array($dataObject => array()); if (preg_match('/=>(\w+)/', $fixture)) { $fixture_content = Yaml::parse($fixture); - foreach ($fixture_content[$data_object] as $identifier => &$fields) { + foreach ($fixture_content[$dataObject] as $identifier => &$fields) { foreach ($fields as $field_val) { if (substr($field_val, 0, 2) == '=>') { - $fixtures_lazy[$data_object][$identifier] = $fixture_content[$data_object][$identifier]; - unset($fixture_content[$data_object][$identifier]); + $fixturesLazy[$dataObject][$identifier] = $fixture_content[$dataObject][$identifier]; + unset($fixture_content[$dataObject][$identifier]); } } } @@ -250,27 +250,27 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex // As we're dealing with split fixtures and can't join them, replace references by hand // if (preg_match('/=>(\w+)\.([\w.]+)/', $fixture, $matches)) { -// if ($matches[1] !== $data_object) { +// if ($matches[1] !== $dataObject) { // $fixture = preg_replace_callback('/=>(\w+)\.([\w.]+)/', array($this, 'replaceFixtureReferences'), $fixture); // } // } $fixture = preg_replace_callback('/=>(\w+)\.([\w.]+)/', array($this, 'replaceFixtureReferences'), $fixture); // Save fixtures into database - $this->fixtures[$data_object] = new \YamlFixture($fixture); + $this->fixtures[$dataObject] = new \YamlFixture($fixture); $model = \DataModel::inst(); - $this->fixtures[$data_object]->saveIntoDatabase($model); + $this->fixtures[$dataObject]->saveIntoDatabase($model); // Lazy load fixtures into database // Loop is required for nested lazy fixtures - foreach ($fixtures_lazy[$data_object] as $identifier => $fields) { + foreach ($fixturesLazy[$dataObject] as $identifier => $fields) { $fixture = array( - $data_object => array( + $dataObject => array( $identifier => $fields, ), ); $fixture = Yaml::dump($fixture); $fixture = preg_replace_callback('/=>(\w+)\.([\w.]+)/', array($this, 'replaceFixtureReferences'), $fixture); - $this->fixtures_lazy[$data_object][$identifier] = new \YamlFixture($fixture); - $this->fixtures_lazy[$data_object][$identifier]->saveIntoDatabase($model); + $this->fixturesLazy[$dataObject][$identifier] = new \YamlFixture($fixture); + $this->fixturesLazy[$dataObject][$identifier]->saveIntoDatabase($model); } } @@ -286,11 +286,11 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex $folder_path = ASSETS_PATH . DIRECTORY_SEPARATOR . $value; if (file_exists($folder_path) && !is_dir($folder_path)) { - throw new \Exception(sprintf('`%s` already exists and is not a directory', $this->files_path)); + throw new \Exception(sprintf('`%s` already exists and is not a directory', $this->filesPath)); } \Filesystem::makeFolder($folder_path); - $this->created_files_paths[] = $folder_path; + $this->createdFilesPaths[] = $folder_path; } } } @@ -306,18 +306,18 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex $value = substr($value, strlen('assets/')); } - $file_path = $this->files_path . DIRECTORY_SEPARATOR . basename($value); - if (!file_exists($file_path) || !is_file($file_path)) { - throw new \Exception(sprintf('`%s` does not exist or is not a file', $this->files_path)); + $filePath = $this->filesPath . DIRECTORY_SEPARATOR . basename($value); + if (!file_exists($filePath) || !is_file($filePath)) { + throw new \Exception(sprintf('`%s` does not exist or is not a file', $this->filesPath)); } $asset_path = ASSETS_PATH . DIRECTORY_SEPARATOR . $value; if (file_exists($asset_path) && !is_file($asset_path)) { - throw new \Exception(sprintf('`%s` already exists and is not a file', $this->files_path)); + throw new \Exception(sprintf('`%s` already exists and is not a file', $this->filesPath)); } if (!file_exists($asset_path)) { - if (@copy($file_path, $asset_path)) { - $this->created_files_paths[] = $asset_path; + if (@copy($filePath, $asset_path)) { + $this->createdFilesPaths[] = $asset_path; } } } @@ -333,17 +333,17 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex return $this->idFromFixture($references[1], $references[2]); } - protected function idFromFixture($class_name, $identifier) + protected function idFromFixture($className, $identifier) { - if (false !== ($id = $this->fixtures[$class_name]->idFromFixture($class_name, $identifier))) { + if (false !== ($id = $this->fixtures[$className]->idFromFixture($className, $identifier))) { return $id; } - if (isset($this->fixtures_lazy[$class_name], $this->fixtures_lazy[$class_name][$identifier]) && - false !== ($id = $this->fixtures_lazy[$class_name][$identifier]->idFromFixture($class_name, $identifier))) { + if (isset($this->fixturesLazy[$className], $this->fixturesLazy[$className][$identifier]) && + false !== ($id = $this->fixturesLazy[$className][$identifier]->idFromFixture($className, $identifier))) { return $id; } - throw new \OutOfBoundsException(sprintf('`%s` identifier in Data object `%s` does not exist!', $identifier, $class_name)); + throw new \OutOfBoundsException(sprintf('`%s` identifier in Data object `%s` does not exist!', $identifier, $className)); } /** @@ -424,10 +424,10 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex } $parts = func_get_args(); - $trim_slashes = function(&$part) { + $trimSlashes = function(&$part) { $part = trim($part, '/'); }; - array_walk($parts, $trim_slashes); + array_walk($parts, $trimSlashes); return implode('/', $parts); } @@ -468,8 +468,8 @@ class SilverStripeContext extends MinkContext implements SilverStripeAwareContex throw new \Exception('Fixture reference should be in following format: =>ClassName.identifier'); } - list($class_name, $identifier) = explode('.', $reference); - $id = $this->idFromFixture($class_name, $identifier); + list($className, $identifier) = explode('.', $reference); + $id = $this->idFromFixture($className, $identifier); //$step = preg_replace('#=>(.+?) for "([^"]*)"#', '"'.$id.'" for "'.$field.'"', $step); // below is not working, because Selenium can't interact with hidden inputs @@ -493,8 +493,8 @@ JAVASCRIPT; throw new \Exception('Fixture reference should be in following format: =>ClassName.identifier'); } - list($class_name, $identifier) = explode('.', $reference); - $id = $this->idFromFixture($class_name, $identifier); + list($className, $identifier) = explode('.', $reference); + $id = $this->idFromFixture($className, $identifier); //$step = preg_replace('#"([^"]*)" with =>(.+)#', '"'.$field.'" with "'.$id.'"', $step); // below is not working, because Selenium can't interact with hidden inputs diff --git a/src/SilverStripe/BehatExtension/Extension.php b/src/SilverStripe/BehatExtension/Extension.php index a3286c9..d78c6f3 100644 --- a/src/SilverStripe/BehatExtension/Extension.php +++ b/src/SilverStripe/BehatExtension/Extension.php @@ -40,9 +40,9 @@ class Extension implements ExtensionInterface $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/services')); $loader->load('silverstripe.yml'); - $behat_base_path = $container->getParameter('behat.paths.base'); + $behatBasePath = $container->getParameter('behat.paths.base'); $config['framework_path'] = realpath(sprintf('%s%s%s', - rtrim($behat_base_path, DIRECTORY_SEPARATOR), + rtrim($behatBasePath, DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR, ltrim($config['framework_path'], DIRECTORY_SEPARATOR) ));