mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Merge pull request #212 from creative-commoners/pulls/4/php81
ENH PHP 8.1 compatibility
This commit is contained in:
commit
ced518e890
@ -63,7 +63,7 @@ class CoreInitializationPass implements CompilerPassInterface
|
|||||||
$container->setParameter('paths.modules.'.$module->getShortName(), $module->getPath());
|
$container->setParameter('paths.modules.'.$module->getShortName(), $module->getPath());
|
||||||
$composerName = $module->getComposerName();
|
$composerName = $module->getComposerName();
|
||||||
if ($composerName) {
|
if ($composerName) {
|
||||||
list($vendor,$name) = explode('/', $composerName);
|
list($vendor,$name) = explode('/', $composerName ?? '');
|
||||||
$container->setParameter('paths.modules.'.$vendor.'.'.$name, $module->getPath());
|
$container->setParameter('paths.modules.'.$vendor.'.'.$name, $module->getPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ class BasicContext implements Context
|
|||||||
{
|
{
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach (get_declared_classes() as $class) {
|
foreach (get_declared_classes() as $class) {
|
||||||
if (is_subclass_of($class, $parent)) {
|
if (is_subclass_of($class, $parent ?? '')) {
|
||||||
$result[] = $class;
|
$result[] = $class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -211,9 +211,9 @@ JS;
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$ajaxEnabledSteps = $this->getMainContext()->getAjaxSteps();
|
$ajaxEnabledSteps = $this->getMainContext()->getAjaxSteps();
|
||||||
$ajaxEnabledSteps = implode('|', array_filter($ajaxEnabledSteps));
|
$ajaxEnabledSteps = implode('|', array_filter($ajaxEnabledSteps ?? []));
|
||||||
|
|
||||||
if (empty($ajaxEnabledSteps) || !preg_match('/(' . $ajaxEnabledSteps . ')/i', $event->getStep()->getText())) {
|
if (empty($ajaxEnabledSteps) || !preg_match('/(' . $ajaxEnabledSteps . ')/i', $event->getStep()->getText() ?? '')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,9 +264,9 @@ JS;
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$ajaxEnabledSteps = $this->getMainContext()->getAjaxSteps();
|
$ajaxEnabledSteps = $this->getMainContext()->getAjaxSteps();
|
||||||
$ajaxEnabledSteps = implode('|', array_filter($ajaxEnabledSteps));
|
$ajaxEnabledSteps = implode('|', array_filter($ajaxEnabledSteps ?? []));
|
||||||
|
|
||||||
if (empty($ajaxEnabledSteps) || !preg_match('/(' . $ajaxEnabledSteps . ')/i', $event->getStep()->getText())) {
|
if (empty($ajaxEnabledSteps) || !preg_match('/(' . $ajaxEnabledSteps . ')/i', $event->getStep()->getText() ?? '')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,7 +377,7 @@ JS;
|
|||||||
{
|
{
|
||||||
$page = $this->getSession()->getPage();
|
$page = $this->getSession()->getPage();
|
||||||
// See https://mathiasbynens.be/notes/css-escapes
|
// See https://mathiasbynens.be/notes/css-escapes
|
||||||
$escapedTitle = addcslashes($title, '!"#$%&\'()*+,-./:;<=>?@[\]^`{|}~');
|
$escapedTitle = addcslashes($title ?? '', '!"#$%&\'()*+,-./:;<=>?@[\]^`{|}~');
|
||||||
$matchedEl = null;
|
$matchedEl = null;
|
||||||
$searches = [
|
$searches = [
|
||||||
['named', ['link_or_button', "'{$title}'"]],
|
['named', ['link_or_button', "'{$title}'"]],
|
||||||
@ -406,7 +406,7 @@ JS;
|
|||||||
public function iShouldSeeAButton($negative, $text)
|
public function iShouldSeeAButton($negative, $text)
|
||||||
{
|
{
|
||||||
$button = $this->findNamedButton($text);
|
$button = $this->findNamedButton($text);
|
||||||
if (trim($negative)) {
|
if (trim($negative ?? '')) {
|
||||||
Assert::assertNull($button, sprintf('%s button found', $text));
|
Assert::assertNull($button, sprintf('%s button found', $text));
|
||||||
} else {
|
} else {
|
||||||
Assert::assertNotNull($button, sprintf('%s button not found', $text));
|
Assert::assertNotNull($button, sprintf('%s button not found', $text));
|
||||||
@ -430,9 +430,9 @@ JS;
|
|||||||
*/
|
*/
|
||||||
public function stepIPressTheButtons($text)
|
public function stepIPressTheButtons($text)
|
||||||
{
|
{
|
||||||
$buttonNames = explode('|', $text);
|
$buttonNames = explode('|', $text ?? '');
|
||||||
foreach ($buttonNames as $name) {
|
foreach ($buttonNames as $name) {
|
||||||
$button = $this->findNamedButton(trim($name));
|
$button = $this->findNamedButton(trim($name ?? ''));
|
||||||
if ($button) {
|
if ($button) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -718,14 +718,14 @@ JS;
|
|||||||
*/
|
*/
|
||||||
public function castRelativeToAbsoluteTime($prefix, $val)
|
public function castRelativeToAbsoluteTime($prefix, $val)
|
||||||
{
|
{
|
||||||
$timestamp = strtotime($val);
|
$timestamp = strtotime($val ?? '');
|
||||||
if (!$timestamp) {
|
if (!$timestamp) {
|
||||||
throw new InvalidArgumentException(sprintf(
|
throw new InvalidArgumentException(sprintf(
|
||||||
"Can't resolve '%s' into a valid datetime value",
|
"Can't resolve '%s' into a valid datetime value",
|
||||||
$val
|
$val
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return date($this->timeFormat, $timestamp);
|
return date($this->timeFormat ?? '', $timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -740,14 +740,14 @@ JS;
|
|||||||
*/
|
*/
|
||||||
public function castRelativeToAbsoluteDatetime($prefix, $val)
|
public function castRelativeToAbsoluteDatetime($prefix, $val)
|
||||||
{
|
{
|
||||||
$timestamp = strtotime($val);
|
$timestamp = strtotime($val ?? '');
|
||||||
if (!$timestamp) {
|
if (!$timestamp) {
|
||||||
throw new InvalidArgumentException(sprintf(
|
throw new InvalidArgumentException(sprintf(
|
||||||
"Can't resolve '%s' into a valid datetime value",
|
"Can't resolve '%s' into a valid datetime value",
|
||||||
$val
|
$val
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return date($this->datetimeFormat, $timestamp);
|
return date($this->datetimeFormat ?? '', $timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -762,14 +762,14 @@ JS;
|
|||||||
*/
|
*/
|
||||||
public function castRelativeToAbsoluteDate($prefix, $val)
|
public function castRelativeToAbsoluteDate($prefix, $val)
|
||||||
{
|
{
|
||||||
$timestamp = strtotime($val);
|
$timestamp = strtotime($val ?? '');
|
||||||
if (!$timestamp) {
|
if (!$timestamp) {
|
||||||
throw new InvalidArgumentException(sprintf(
|
throw new InvalidArgumentException(sprintf(
|
||||||
"Can't resolve '%s' into a valid datetime value",
|
"Can't resolve '%s' into a valid datetime value",
|
||||||
$val
|
$val
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return date($this->dateFormat, $timestamp);
|
return date($this->dateFormat ?? '', $timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDateFormat()
|
public function getDateFormat()
|
||||||
@ -828,7 +828,7 @@ JS;
|
|||||||
Assert::assertNotNull($element, sprintf("Element '%s' not found", $name));
|
Assert::assertNotNull($element, sprintf("Element '%s' not found", $name));
|
||||||
|
|
||||||
$disabledAttribute = $element->getAttribute('disabled');
|
$disabledAttribute = $element->getAttribute('disabled');
|
||||||
if (trim($negate)) {
|
if (trim($negate ?? '')) {
|
||||||
Assert::assertNull($disabledAttribute, sprintf("Failed asserting element '%s' is not disabled", $name));
|
Assert::assertNull($disabledAttribute, sprintf("Failed asserting element '%s' is not disabled", $name));
|
||||||
} else {
|
} else {
|
||||||
Assert::assertNotNull($disabledAttribute, sprintf("Failed asserting element '%s' is disabled", $name));
|
Assert::assertNotNull($disabledAttribute, sprintf("Failed asserting element '%s' is disabled", $name));
|
||||||
@ -929,11 +929,11 @@ JS;
|
|||||||
Assert::assertNotNull($regionObj);
|
Assert::assertNotNull($regionObj);
|
||||||
|
|
||||||
$actual = $regionObj->getText();
|
$actual = $regionObj->getText();
|
||||||
$actual = preg_replace('/\s+/u', ' ', $actual);
|
$actual = preg_replace('/\s+/u', ' ', $actual ?? '');
|
||||||
$regex = '/' . preg_quote($text, '/') . '/ui';
|
$regex = '/' . preg_quote($text ?? '', '/') . '/ui';
|
||||||
|
|
||||||
if (trim($negate)) {
|
if (trim($negate ?? '')) {
|
||||||
if (preg_match($regex, $actual)) {
|
if (preg_match($regex ?? '', $actual ?? '')) {
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
'The text "%s" was found in the text of the "%s" region on the page %s.',
|
'The text "%s" was found in the text of the "%s" region on the page %s.',
|
||||||
$text,
|
$text,
|
||||||
@ -944,7 +944,7 @@ JS;
|
|||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!preg_match($regex, $actual)) {
|
if (!preg_match($regex ?? '', $actual ?? '')) {
|
||||||
$message = sprintf(
|
$message = sprintf(
|
||||||
'The text "%s" was not found anywhere in the text of the "%s" region on the page %s.',
|
'The text "%s" was not found anywhere in the text of the "%s" region on the page %s.',
|
||||||
$text,
|
$text,
|
||||||
@ -1079,15 +1079,15 @@ JS;
|
|||||||
|
|
||||||
// Check both of the texts exist in the element
|
// Check both of the texts exist in the element
|
||||||
$text = $ele->getText();
|
$text = $ele->getText();
|
||||||
Assert::assertTrue(strpos($text, $textBefore) !== 'FALSE', sprintf('%s not found in the element %s', $textBefore, $element));
|
Assert::assertTrue(strpos($text ?? '', $textBefore ?? '') !== 'FALSE', sprintf('%s not found in the element %s', $textBefore, $element));
|
||||||
Assert::assertTrue(strpos($text, $textAfter) !== 'FALSE', sprintf('%s not found in the element %s', $textAfter, $element));
|
Assert::assertTrue(strpos($text ?? '', $textAfter ?? '') !== 'FALSE', sprintf('%s not found in the element %s', $textAfter, $element));
|
||||||
|
|
||||||
/// Use strpos to get the position of the first occurrence of the two texts (case-sensitive)
|
/// Use strpos to get the position of the first occurrence of the two texts (case-sensitive)
|
||||||
// and compare them with the given order (before or after)
|
// and compare them with the given order (before or after)
|
||||||
if ($order === 'before') {
|
if ($order === 'before') {
|
||||||
Assert::assertTrue(strpos($text, $textBefore) < strpos($text, $textAfter));
|
Assert::assertTrue(strpos($text ?? '', $textBefore ?? '') < strpos($text ?? '', $textAfter ?? ''));
|
||||||
} else {
|
} else {
|
||||||
Assert::assertTrue(strpos($text, $textBefore) > strpos($text, $textAfter));
|
Assert::assertTrue(strpos($text ?? '', $textBefore ?? '') > strpos($text ?? '', $textAfter ?? ''));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1302,7 +1302,7 @@ JS;
|
|||||||
$not = '';
|
$not = '';
|
||||||
$cssSelector = $not;
|
$cssSelector = $not;
|
||||||
}
|
}
|
||||||
$sel = str_replace('"', '\\"', $cssSelector);
|
$sel = str_replace('"', '\\"', $cssSelector ?? '');
|
||||||
$js = <<<JS
|
$js = <<<JS
|
||||||
return document.querySelector("$sel");
|
return document.querySelector("$sel");
|
||||||
JS;
|
JS;
|
||||||
@ -1330,8 +1330,8 @@ JS;
|
|||||||
$field->selectOption($value);
|
$field->selectOption($value);
|
||||||
} else {
|
} else {
|
||||||
$xpath = $field->getXpath();
|
$xpath = $field->getXpath();
|
||||||
$xpath = str_replace(['"', "\n"], ['\"', ''], $xpath);
|
$xpath = str_replace(['"', "\n"], ['\"', ''], $xpath ?? '');
|
||||||
$value = str_replace('"', '\"', $value);
|
$value = str_replace('"', '\"', $value ?? '');
|
||||||
$js = <<<JS
|
$js = <<<JS
|
||||||
return (function() {
|
return (function() {
|
||||||
let select = document.evaluate("{$xpath}", document).iterateNext();
|
let select = document.evaluate("{$xpath}", document).iterateNext();
|
||||||
@ -1360,8 +1360,8 @@ JS;
|
|||||||
public function theRenderedHtmlShouldContain($not, $htmlFragment)
|
public function theRenderedHtmlShouldContain($not, $htmlFragment)
|
||||||
{
|
{
|
||||||
$html = $this->getSession()->getPage()->getOuterHtml();
|
$html = $this->getSession()->getPage()->getOuterHtml();
|
||||||
$htmlFragment = str_replace('\"', '"', $htmlFragment);
|
$htmlFragment = str_replace('\"', '"', $htmlFragment ?? '');
|
||||||
$contains = strpos($html, $htmlFragment) !== false;
|
$contains = strpos($html ?? '', $htmlFragment ?? '') !== false;
|
||||||
if ($not) {
|
if ($not) {
|
||||||
Assert::assertFalse($contains, "HTML fragment {$htmlFragment} was in rendered HTML when it should not have been");
|
Assert::assertFalse($contains, "HTML fragment {$htmlFragment} was in rendered HTML when it should not have been");
|
||||||
} else {
|
} else {
|
||||||
@ -1463,18 +1463,18 @@ JS;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$modifier = null;
|
$modifier = null;
|
||||||
$pos = strpos($keyCombo, '-');
|
$pos = strpos($keyCombo ?? '', '-');
|
||||||
if ($pos !== false && $pos !== 0) {
|
if ($pos !== false && $pos !== 0) {
|
||||||
list($modifier, $char) = explode('-', $keyCombo);
|
list($modifier, $char) = explode('-', $keyCombo ?? '');
|
||||||
} else {
|
} else {
|
||||||
$char = $keyCombo;
|
$char = $keyCombo;
|
||||||
}
|
}
|
||||||
// handle special chars e.g. "space"
|
// handle special chars e.g. "space"
|
||||||
if (defined(WebDriverKeys::class . '::' . strtoupper($char))) {
|
if (defined(WebDriverKeys::class . '::' . strtoupper($char ?? ''))) {
|
||||||
$char = constant(WebDriverKeys::class . '::' . strtoupper($char));
|
$char = constant(WebDriverKeys::class . '::' . strtoupper($char ?? ''));
|
||||||
}
|
}
|
||||||
if ($modifier) {
|
if ($modifier) {
|
||||||
$modifier = strtoupper($modifier);
|
$modifier = strtoupper($modifier ?? '');
|
||||||
if (defined(WebDriverKeys::class . '::' . $modifier)) {
|
if (defined(WebDriverKeys::class . '::' . $modifier)) {
|
||||||
$modifier = constant(WebDriverKeys::class . '::' . $modifier);
|
$modifier = constant(WebDriverKeys::class . '::' . $modifier);
|
||||||
} else {
|
} else {
|
||||||
@ -1495,13 +1495,13 @@ JS;
|
|||||||
{
|
{
|
||||||
Assert::assertNotNull($this->fixtureContext, 'FixtureContext was not found so cannot know location of fixture files');
|
Assert::assertNotNull($this->fixtureContext, 'FixtureContext was not found so cannot know location of fixture files');
|
||||||
$path = $this->fixtureContext->getFilesPath() . '/' . $filename;
|
$path = $this->fixtureContext->getFilesPath() . '/' . $filename;
|
||||||
$path = str_replace('//', '/', $path);
|
$path = str_replace('//', '/', $path ?? '');
|
||||||
Assert::assertNotEmpty($path, 'Fixture files path is empty');
|
Assert::assertNotEmpty($path, 'Fixture files path is empty');
|
||||||
$field = $this->getElement($locator);
|
$field = $this->getElement($locator);
|
||||||
$filesPath = $this->fixtureContext->getFilesPath();
|
$filesPath = $this->fixtureContext->getFilesPath();
|
||||||
if ($filesPath) {
|
if ($filesPath) {
|
||||||
$fullPath = rtrim(realpath($filesPath), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $path;
|
$fullPath = rtrim(realpath($filesPath ?? '') ?? '', DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $path;
|
||||||
if (is_file($fullPath)) {
|
if (is_file($fullPath ?? '')) {
|
||||||
$path = $fullPath;
|
$path = $fullPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1526,12 +1526,12 @@ JS;
|
|||||||
}
|
}
|
||||||
Assert::assertNotNull($link, "Link {$locator} was not found");
|
Assert::assertNotNull($link, "Link {$locator} was not found");
|
||||||
$html = $link->getOuterHtml();
|
$html = $link->getOuterHtml();
|
||||||
preg_match('#href=([\'"])#', $html, $m);
|
preg_match('#href=([\'"])#', $html ?? '', $m);
|
||||||
$q = $m[1];
|
$q = $m[1];
|
||||||
preg_match("#href={$q}(.+?){$q}#", $html, $m);
|
preg_match("#href={$q}(.+?){$q}#", $html ?? '', $m);
|
||||||
$href = str_replace("'", "\\'", $m[1]);
|
$href = str_replace("'", "\\'", $m[1] ?? '');
|
||||||
if (strpos($href, 'http') !== 0) {
|
if (strpos($href ?? '', 'http') !== 0) {
|
||||||
$href = rtrim($href, '/');
|
$href = rtrim($href ?? '', '/');
|
||||||
$href = "/{$href}";
|
$href = "/{$href}";
|
||||||
}
|
}
|
||||||
$this->getSession()->executeScript("document.location.href = '{$href}';");
|
$this->getSession()->executeScript("document.location.href = '{$href}';");
|
||||||
|
@ -63,7 +63,7 @@ class EmailContext implements Context
|
|||||||
$to = ($direction == 'to') ? $email : null;
|
$to = ($direction == 'to') ? $email : null;
|
||||||
$from = ($direction == 'from') ? $email : null;
|
$from = ($direction == 'from') ? $email : null;
|
||||||
$match = $this->mailer->findEmail($to, $from);
|
$match = $this->mailer->findEmail($to, $from);
|
||||||
if (trim($negate)) {
|
if (trim($negate ?? '')) {
|
||||||
Assert::assertNull($match);
|
Assert::assertNull($match);
|
||||||
} else {
|
} else {
|
||||||
Assert::assertNotNull($match);
|
Assert::assertNotNull($match);
|
||||||
@ -87,7 +87,7 @@ class EmailContext implements Context
|
|||||||
$allTitles = $allMails ? '"' . implode('","', array_map(function ($email) {
|
$allTitles = $allMails ? '"' . implode('","', array_map(function ($email) {
|
||||||
return $email->Subject;
|
return $email->Subject;
|
||||||
}, $allMails)) . '"' : null;
|
}, $allMails)) . '"' : null;
|
||||||
if (trim($negate)) {
|
if (trim($negate ?? '')) {
|
||||||
Assert::assertNull($match);
|
Assert::assertNull($match);
|
||||||
} else {
|
} else {
|
||||||
$msg = sprintf(
|
$msg = sprintf(
|
||||||
@ -127,7 +127,7 @@ class EmailContext implements Context
|
|||||||
$emailContent = $email->PlainContent;
|
$emailContent = $email->PlainContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trim($negate)) {
|
if (trim($negate ?? '')) {
|
||||||
Assert::assertStringNotContainsString($content, $emailContent);
|
Assert::assertStringNotContainsString($content, $emailContent);
|
||||||
} else {
|
} else {
|
||||||
Assert::assertStringContainsString($content, $emailContent);
|
Assert::assertStringContainsString($content, $emailContent);
|
||||||
@ -151,8 +151,8 @@ class EmailContext implements Context
|
|||||||
|
|
||||||
$email = $this->lastMatchedEmail;
|
$email = $this->lastMatchedEmail;
|
||||||
$emailContent = ($email->Content) ? ($email->Content) : ($email->PlainContent);
|
$emailContent = ($email->Content) ? ($email->Content) : ($email->PlainContent);
|
||||||
$emailPlainText = strip_tags($emailContent);
|
$emailPlainText = strip_tags($emailContent ?? '');
|
||||||
$emailPlainText = preg_replace("/\h+/", " ", $emailPlainText);
|
$emailPlainText = preg_replace("/\h+/", " ", $emailPlainText ?? '');
|
||||||
|
|
||||||
Assert::assertStringContainsString($content, $emailPlainText);
|
Assert::assertStringContainsString($content, $emailPlainText);
|
||||||
}
|
}
|
||||||
@ -256,12 +256,12 @@ class EmailContext implements Context
|
|||||||
$emailContent = $email->PlainContent;
|
$emailContent = $email->PlainContent;
|
||||||
}
|
}
|
||||||
// Convert html content to plain text
|
// Convert html content to plain text
|
||||||
$emailContent = strip_tags($emailContent);
|
$emailContent = strip_tags($emailContent ?? '');
|
||||||
$emailContent = preg_replace("/\h+/", " ", $emailContent);
|
$emailContent = preg_replace("/\h+/", " ", $emailContent ?? '');
|
||||||
$rows = $table->getRows();
|
$rows = $table->getRows();
|
||||||
|
|
||||||
// For "should not contain"
|
// For "should not contain"
|
||||||
if (trim($negate)) {
|
if (trim($negate ?? '')) {
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
Assert::assertStringNotContainsString($row[0], $emailContent);
|
Assert::assertStringNotContainsString($row[0], $emailContent);
|
||||||
}
|
}
|
||||||
@ -280,7 +280,7 @@ class EmailContext implements Context
|
|||||||
public function thereIsAnEmailTitled($negate, $subject)
|
public function thereIsAnEmailTitled($negate, $subject)
|
||||||
{
|
{
|
||||||
$match = $this->mailer->findEmail(null, null, $subject);
|
$match = $this->mailer->findEmail(null, null, $subject);
|
||||||
if (trim($negate)) {
|
if (trim($negate ?? '')) {
|
||||||
Assert::assertNull($match);
|
Assert::assertNull($match);
|
||||||
} else {
|
} else {
|
||||||
$msg = sprintf(
|
$msg = sprintf(
|
||||||
@ -304,7 +304,7 @@ class EmailContext implements Context
|
|||||||
}
|
}
|
||||||
|
|
||||||
$match = $this->lastMatchedEmail;
|
$match = $this->lastMatchedEmail;
|
||||||
if (trim($negate)) {
|
if (trim($negate ?? '')) {
|
||||||
Assert::assertStringNotContainsString($from, $match->From);
|
Assert::assertStringNotContainsString($from, $match->From);
|
||||||
} else {
|
} else {
|
||||||
Assert::assertStringContainsString($from, $match->From);
|
Assert::assertStringContainsString($from, $match->From);
|
||||||
@ -323,7 +323,7 @@ class EmailContext implements Context
|
|||||||
}
|
}
|
||||||
|
|
||||||
$match = $this->lastMatchedEmail;
|
$match = $this->lastMatchedEmail;
|
||||||
if (trim($negate)) {
|
if (trim($negate ?? '')) {
|
||||||
Assert::assertStringNotContainsString($to, $match->To);
|
Assert::assertStringNotContainsString($to, $match->To);
|
||||||
} else {
|
} else {
|
||||||
Assert::assertStringContainsString($to, $match->To);
|
Assert::assertStringContainsString($to, $match->To);
|
||||||
@ -352,7 +352,7 @@ class EmailContext implements Context
|
|||||||
$href = null;
|
$href = null;
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
$linkText = $tag->nodeValue;
|
$linkText = $tag->nodeValue;
|
||||||
if (strpos($linkText, $httpText) !== false) {
|
if (strpos($linkText ?? '', $httpText ?? '') !== false) {
|
||||||
$href = $linkText;
|
$href = $linkText;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -257,12 +257,12 @@ class FixtureContext implements Context
|
|||||||
$class = $this->convertTypeToClass($type);
|
$class = $this->convertTypeToClass($type);
|
||||||
preg_match_all(
|
preg_match_all(
|
||||||
'/"(?<key>[^"]+)"\s*=\s*"(?<value>[^"]+)"/',
|
'/"(?<key>[^"]+)"\s*=\s*"(?<value>[^"]+)"/',
|
||||||
$data,
|
$data ?? '',
|
||||||
$matches
|
$matches
|
||||||
);
|
);
|
||||||
$fields = $this->convertFields(
|
$fields = $this->convertFields(
|
||||||
$class,
|
$class,
|
||||||
array_combine($matches['key'], $matches['value'])
|
array_combine($matches['key'] ?? [], $matches['value'] ?? [])
|
||||||
);
|
);
|
||||||
$fields = $this->prepareFixture($class, $id, $fields);
|
$fields = $this->prepareFixture($class, $id, $fields);
|
||||||
// We should check if this fixture object already exists - if it does, we update it. If not, we create it
|
// We should check if this fixture object already exists - if it does, we update it. If not, we create it
|
||||||
@ -403,20 +403,20 @@ class FixtureContext implements Context
|
|||||||
$manyField = null;
|
$manyField = null;
|
||||||
$oneField = null;
|
$oneField = null;
|
||||||
if ($relationObj->manyMany()) {
|
if ($relationObj->manyMany()) {
|
||||||
$manyField = array_search($class, $relationObj->manyMany());
|
$manyField = array_search($class, $relationObj->manyMany() ?? []);
|
||||||
if ($manyField && strlen($relationName) > 0) {
|
if ($manyField && strlen($relationName ?? '') > 0) {
|
||||||
$manyField = $relationName;
|
$manyField = $relationName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty($manyField) && $relationObj->hasMany(true)) {
|
if (empty($manyField) && $relationObj->hasMany(true)) {
|
||||||
$manyField = array_search($class, $relationObj->hasMany());
|
$manyField = array_search($class, $relationObj->hasMany() ?? []);
|
||||||
if ($manyField && strlen($relationName) > 0) {
|
if ($manyField && strlen($relationName ?? '') > 0) {
|
||||||
$manyField = $relationName;
|
$manyField = $relationName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty($manyField) && $relationObj->hasOne()) {
|
if (empty($manyField) && $relationObj->hasOne()) {
|
||||||
$oneField = array_search($class, $relationObj->hasOne());
|
$oneField = array_search($class, $relationObj->hasOne() ?? []);
|
||||||
if ($oneField && strlen($relationName) > 0) {
|
if ($oneField && strlen($relationName ?? '') > 0) {
|
||||||
$oneField = $relationName;
|
$oneField = $relationName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -555,12 +555,12 @@ class FixtureContext implements Context
|
|||||||
{
|
{
|
||||||
preg_match_all(
|
preg_match_all(
|
||||||
'/"(?<key>[^"]+)"\s*=\s*"(?<value>[^"]+)"/',
|
'/"(?<key>[^"]+)"\s*=\s*"(?<value>[^"]+)"/',
|
||||||
$data,
|
$data ?? '',
|
||||||
$matches
|
$matches
|
||||||
);
|
);
|
||||||
$fields = $this->convertFields(
|
$fields = $this->convertFields(
|
||||||
Member::class,
|
Member::class,
|
||||||
array_combine($matches['key'], $matches['value'])
|
array_combine($matches['key'] ?? [], $matches['value'] ?? [])
|
||||||
);
|
);
|
||||||
|
|
||||||
/** @var Group $group */
|
/** @var Group $group */
|
||||||
@ -587,7 +587,7 @@ class FixtureContext implements Context
|
|||||||
public function stepCreateGroupWithPermissions($id, $permissionStr)
|
public function stepCreateGroupWithPermissions($id, $permissionStr)
|
||||||
{
|
{
|
||||||
// Convert natural language permissions to codes
|
// Convert natural language permissions to codes
|
||||||
preg_match_all('/"([^"]+)"/', $permissionStr, $matches);
|
preg_match_all('/"([^"]+)"/', $permissionStr ?? '', $matches);
|
||||||
$permissions = $matches[1];
|
$permissions = $matches[1];
|
||||||
$codes = Permission::get_codes(false);
|
$codes = Permission::get_codes(false);
|
||||||
|
|
||||||
@ -652,7 +652,7 @@ class FixtureContext implements Context
|
|||||||
{
|
{
|
||||||
// Validate the extension
|
// Validate the extension
|
||||||
Assert::assertTrue(
|
Assert::assertTrue(
|
||||||
class_exists($extension) && is_subclass_of($extension, Extension::class),
|
class_exists($extension ?? '') && is_subclass_of($extension, Extension::class),
|
||||||
'Given extension does not extend Extension'
|
'Given extension does not extend Extension'
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -662,7 +662,7 @@ class FixtureContext implements Context
|
|||||||
$targetClass::add_extension($extension);
|
$targetClass::add_extension($extension);
|
||||||
|
|
||||||
// Write config for this extension too...
|
// Write config for this extension too...
|
||||||
$snakedExtension = strtolower(str_replace('\\', '-', $extension));
|
$snakedExtension = strtolower(str_replace('\\', '-', $extension ?? '') ?? '');
|
||||||
$config = <<<YAML
|
$config = <<<YAML
|
||||||
---
|
---
|
||||||
Name: testonly-enable-extension-$snakedExtension
|
Name: testonly-enable-extension-$snakedExtension
|
||||||
@ -674,7 +674,7 @@ YAML;
|
|||||||
|
|
||||||
$filename = 'enable-' . $snakedExtension . '.yml';
|
$filename = 'enable-' . $snakedExtension . '.yml';
|
||||||
$destPath = $this->getDestinationConfigFolder($filename);
|
$destPath = $this->getDestinationConfigFolder($filename);
|
||||||
file_put_contents($destPath, $config);
|
file_put_contents($destPath ?? '', $config);
|
||||||
|
|
||||||
// Remember to cleanup...
|
// Remember to cleanup...
|
||||||
$this->activatedConfigFiles[] = $destPath;
|
$this->activatedConfigFiles[] = $destPath;
|
||||||
@ -741,8 +741,8 @@ YAML;
|
|||||||
*/
|
*/
|
||||||
public function lookupFixtureReference($string)
|
public function lookupFixtureReference($string)
|
||||||
{
|
{
|
||||||
if (preg_match('/^=>/', $string)) {
|
if (preg_match('/^=>/', $string ?? '')) {
|
||||||
list($className, $identifier) = explode('.', preg_replace('/^=>/', '', $string), 2);
|
list($className, $identifier) = explode('.', preg_replace('/^=>/', '', $string ?? '') ?? '', 2);
|
||||||
$id = $this->getFixtureFactory()->getId($className, $identifier);
|
$id = $this->getFixtureFactory()->getId($className, $identifier);
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
throw new InvalidArgumentException(sprintf(
|
throw new InvalidArgumentException(sprintf(
|
||||||
@ -768,7 +768,7 @@ YAML;
|
|||||||
$class = $this->convertTypeToClass($type);
|
$class = $this->convertTypeToClass($type);
|
||||||
$fields = $this->prepareFixture($class, $id);
|
$fields = $this->prepareFixture($class, $id);
|
||||||
$record = $this->getFixtureFactory()->createObject($class, $id, $fields);
|
$record = $this->getFixtureFactory()->createObject($class, $id, $fields);
|
||||||
$date = date("Y-m-d H:i:s", strtotime($time));
|
$date = date("Y-m-d H:i:s", strtotime($time ?? ''));
|
||||||
$table = $record->baseTable();
|
$table = $record->baseTable();
|
||||||
$field = ($mod == 'created') ? 'Created' : 'LastEdited';
|
$field = ($mod == 'created') ? 'Created' : 'LastEdited';
|
||||||
DB::prepared_query(
|
DB::prepared_query(
|
||||||
@ -821,8 +821,8 @@ YAML;
|
|||||||
|
|
||||||
|
|
||||||
$relativeTargetPath = (isset($data['Filename'])) ? $data['Filename'] : $identifier;
|
$relativeTargetPath = (isset($data['Filename'])) ? $data['Filename'] : $identifier;
|
||||||
$relativeTargetPath = preg_replace('/^' . ASSETS_DIR . '\/?/', '', $relativeTargetPath);
|
$relativeTargetPath = preg_replace('/^' . ASSETS_DIR . '\/?/', '', $relativeTargetPath ?? '');
|
||||||
$sourcePath = $this->joinPaths($this->getFilesPath(), basename($relativeTargetPath));
|
$sourcePath = $this->joinPaths($this->getFilesPath(), basename($relativeTargetPath ?? ''));
|
||||||
|
|
||||||
// Create file or folder on filesystem
|
// Create file or folder on filesystem
|
||||||
if ($class == 'SilverStripe\\Assets\\Folder' || is_subclass_of($class, 'SilverStripe\\Assets\\Folder')) {
|
if ($class == 'SilverStripe\\Assets\\Folder' || is_subclass_of($class, 'SilverStripe\\Assets\\Folder')) {
|
||||||
@ -830,7 +830,7 @@ YAML;
|
|||||||
$data['ID'] = $parent->ID;
|
$data['ID'] = $parent->ID;
|
||||||
} else {
|
} else {
|
||||||
// Check file exists
|
// Check file exists
|
||||||
if (!file_exists($sourcePath)) {
|
if (!file_exists($sourcePath ?? '')) {
|
||||||
throw new InvalidArgumentException(sprintf(
|
throw new InvalidArgumentException(sprintf(
|
||||||
'Source file for "%s" cannot be found in "%s"',
|
'Source file for "%s" cannot be found in "%s"',
|
||||||
$relativeTargetPath,
|
$relativeTargetPath,
|
||||||
@ -840,8 +840,8 @@ YAML;
|
|||||||
|
|
||||||
// Get parent
|
// Get parent
|
||||||
$parentID = 0;
|
$parentID = 0;
|
||||||
if (strstr($relativeTargetPath, '/')) {
|
if (strstr($relativeTargetPath ?? '', '/')) {
|
||||||
$folderName = dirname($relativeTargetPath);
|
$folderName = dirname($relativeTargetPath ?? '');
|
||||||
$parent = Folder::find_or_make($folderName);
|
$parent = Folder::find_or_make($folderName);
|
||||||
if ($parent) {
|
if ($parent) {
|
||||||
$parentID = $parent->ID;
|
$parentID = $parent->ID;
|
||||||
@ -865,7 +865,7 @@ YAML;
|
|||||||
$data['FileVariant'] = $asset['Variant'];
|
$data['FileVariant'] = $asset['Variant'];
|
||||||
}
|
}
|
||||||
if (!isset($data['Name'])) {
|
if (!isset($data['Name'])) {
|
||||||
$data['Name'] = basename($relativeTargetPath);
|
$data['Name'] = basename($relativeTargetPath ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save assets
|
// Save assets
|
||||||
@ -894,17 +894,17 @@ YAML;
|
|||||||
*/
|
*/
|
||||||
protected function convertTypeToClass($type)
|
protected function convertTypeToClass($type)
|
||||||
{
|
{
|
||||||
$type = trim($type);
|
$type = trim($type ?? '');
|
||||||
|
|
||||||
// Try direct mapping
|
// Try direct mapping
|
||||||
$class = str_replace(' ', '', ucwords($type));
|
$class = str_replace(' ', '', ucwords($type ?? ''));
|
||||||
if (class_exists($class) && is_subclass_of($class, DataObject::class)) {
|
if (class_exists($class ?? '') && is_subclass_of($class, DataObject::class)) {
|
||||||
return ClassInfo::class_name($class);
|
return ClassInfo::class_name($class);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to singular names
|
// Fall back to singular names
|
||||||
foreach (array_values(ClassInfo::subclassesFor(DataObject::class)) as $candidate) {
|
foreach (array_values(ClassInfo::subclassesFor(DataObject::class) ?? []) as $candidate) {
|
||||||
if (class_exists($candidate) && strcasecmp(singleton($candidate)->singular_name(), $type) === 0) {
|
if (class_exists($candidate ?? '') && strcasecmp(singleton($candidate)->singular_name() ?? '', $type ?? '') === 0) {
|
||||||
return $candidate;
|
return $candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -927,7 +927,7 @@ YAML;
|
|||||||
{
|
{
|
||||||
$labels = singleton($class)->fieldLabels();
|
$labels = singleton($class)->fieldLabels();
|
||||||
foreach ($fields as $fieldName => $fieldVal) {
|
foreach ($fields as $fieldName => $fieldVal) {
|
||||||
if ($fieldLabelKey = array_search($fieldName, $labels)) {
|
if ($fieldLabelKey = array_search($fieldName, $labels ?? [])) {
|
||||||
unset($fields[$fieldName]);
|
unset($fields[$fieldName]);
|
||||||
$fields[$labels[$fieldLabelKey]] = $fieldVal;
|
$fields[$labels[$fieldLabelKey]] = $fieldVal;
|
||||||
}
|
}
|
||||||
@ -943,9 +943,9 @@ YAML;
|
|||||||
$paths = array_merge($paths, (array)$arg);
|
$paths = array_merge($paths, (array)$arg);
|
||||||
}
|
}
|
||||||
foreach ($paths as &$path) {
|
foreach ($paths as &$path) {
|
||||||
$path = trim($path, '/');
|
$path = trim($path ?? '', '/');
|
||||||
}
|
}
|
||||||
if (substr($args[0], 0, 1) == '/') {
|
if (substr($args[0] ?? '', 0, 1) == '/') {
|
||||||
$paths[0] = '/' . $paths[0];
|
$paths[0] = '/' . $paths[0];
|
||||||
}
|
}
|
||||||
return join('/', $paths);
|
return join('/', $paths);
|
||||||
@ -959,8 +959,8 @@ YAML;
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->activatedConfigFiles as $configFile) {
|
foreach ($this->activatedConfigFiles as $configFile) {
|
||||||
if (file_exists($configFile)) {
|
if (file_exists($configFile ?? '')) {
|
||||||
unlink($configFile);
|
unlink($configFile ?? '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->activatedConfigFiles = [];
|
$this->activatedConfigFiles = [];
|
||||||
|
@ -32,7 +32,7 @@ class LoginContext implements Context
|
|||||||
|
|
||||||
$this->getMainContext()->getSession()->visit($adminUrl);
|
$this->getMainContext()->getSession()->visit($adminUrl);
|
||||||
|
|
||||||
if (0 == strpos($this->getMainContext()->getSession()->getCurrentUrl(), $loginUrl)) {
|
if (0 == strpos($this->getMainContext()->getSession()->getCurrentUrl() ?? '', $loginUrl ?? '')) {
|
||||||
$this->stepILogInWith('admin', 'password');
|
$this->stepILogInWith('admin', 'password');
|
||||||
Assert::assertStringStartsWith($adminUrl, $this->getMainContext()->getSession()->getCurrentUrl());
|
Assert::assertStringStartsWith($adminUrl, $this->getMainContext()->getSession()->getCurrentUrl());
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ abstract class SilverStripeContext extends MinkContext implements SilverStripeAw
|
|||||||
$regionObj = $this->getSession()->getPage()->find(
|
$regionObj = $this->getSession()->getPage()->find(
|
||||||
'css',
|
'css',
|
||||||
// Escape CSS selector
|
// Escape CSS selector
|
||||||
(false !== strpos($region, "'")) ? str_replace("'", "\\'", $region) : $region
|
(false !== strpos($region ?? '', "'")) ? str_replace("'", "\\'", $region) : $region
|
||||||
);
|
);
|
||||||
if ($regionObj) {
|
if ($regionObj) {
|
||||||
return $regionObj;
|
return $regionObj;
|
||||||
@ -203,7 +203,7 @@ abstract class SilverStripeContext extends MinkContext implements SilverStripeAw
|
|||||||
// Fall back to region identified by data-title.
|
// Fall back to region identified by data-title.
|
||||||
// Only apply if no double quotes exist in search string,
|
// Only apply if no double quotes exist in search string,
|
||||||
// which would break the CSS selector.
|
// which would break the CSS selector.
|
||||||
if (false === strpos($region, '"')) {
|
if (false === strpos($region ?? '', '"')) {
|
||||||
$regionObj = $this->getSession()->getPage()->find(
|
$regionObj = $this->getSession()->getPage()->find(
|
||||||
'css',
|
'css',
|
||||||
'[data-title="' . $region . '"]'
|
'[data-title="' . $region . '"]'
|
||||||
@ -217,7 +217,7 @@ abstract class SilverStripeContext extends MinkContext implements SilverStripeAw
|
|||||||
if (!$this->regionMap) {
|
if (!$this->regionMap) {
|
||||||
throw new \LogicException("Cannot find 'region_map' in the behat.yml");
|
throw new \LogicException("Cannot find 'region_map' in the behat.yml");
|
||||||
}
|
}
|
||||||
if (!array_key_exists($region, $this->regionMap)) {
|
if (!array_key_exists($region, $this->regionMap ?? [])) {
|
||||||
throw new \LogicException("Cannot find the specified region in the behat.yml");
|
throw new \LogicException("Cannot find the specified region in the behat.yml");
|
||||||
}
|
}
|
||||||
$regionObj = $this->getSession()->getPage()->find('css', $region);
|
$regionObj = $this->getSession()->getPage()->find('css', $region);
|
||||||
@ -265,7 +265,7 @@ abstract class SilverStripeContext extends MinkContext implements SilverStripeAw
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($screenSize = Environment::getEnv('BEHAT_SCREEN_SIZE')) {
|
if ($screenSize = Environment::getEnv('BEHAT_SCREEN_SIZE')) {
|
||||||
list($screenWidth, $screenHeight) = explode('x', $screenSize);
|
list($screenWidth, $screenHeight) = explode('x', $screenSize ?? '');
|
||||||
$this->getSession()->resizeWindow((int)$screenWidth, (int)$screenHeight);
|
$this->getSession()->resizeWindow((int)$screenWidth, (int)$screenHeight);
|
||||||
} else {
|
} else {
|
||||||
$this->getSession()->resizeWindow(1024, 768);
|
$this->getSession()->resizeWindow(1024, 768);
|
||||||
@ -312,7 +312,7 @@ abstract class SilverStripeContext extends MinkContext implements SilverStripeAw
|
|||||||
public function getTestSessionState()
|
public function getTestSessionState()
|
||||||
{
|
{
|
||||||
$extraParams = array();
|
$extraParams = array();
|
||||||
parse_str(Environment::getEnv('TESTSESSION_PARAMS'), $extraParams);
|
parse_str(Environment::getEnv('TESTSESSION_PARAMS') ?? '', $extraParams);
|
||||||
return array_merge(
|
return array_merge(
|
||||||
array(
|
array(
|
||||||
'database' => $this->databaseName,
|
'database' => $this->databaseName,
|
||||||
@ -330,13 +330,13 @@ abstract class SilverStripeContext extends MinkContext implements SilverStripeAw
|
|||||||
*/
|
*/
|
||||||
public function parseUrl($url)
|
public function parseUrl($url)
|
||||||
{
|
{
|
||||||
$url = parse_url($url);
|
$url = parse_url($url ?? '');
|
||||||
$url['vars'] = array();
|
$url['vars'] = array();
|
||||||
if (!isset($url['fragment'])) {
|
if (!isset($url['fragment'])) {
|
||||||
$url['fragment'] = null;
|
$url['fragment'] = null;
|
||||||
}
|
}
|
||||||
if (isset($url['query'])) {
|
if (isset($url['query'])) {
|
||||||
parse_str($url['query'], $url['vars']);
|
parse_str($url['query'] ?? '', $url['vars']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
@ -401,7 +401,7 @@ abstract class SilverStripeContext extends MinkContext implements SilverStripeAw
|
|||||||
|
|
||||||
$parts = func_get_args();
|
$parts = func_get_args();
|
||||||
$trimSlashes = function (&$part) {
|
$trimSlashes = function (&$part) {
|
||||||
$part = trim($part, '/');
|
$part = trim($part ?? '', '/');
|
||||||
};
|
};
|
||||||
array_walk($parts, $trimSlashes);
|
array_walk($parts, $trimSlashes);
|
||||||
|
|
||||||
@ -600,7 +600,7 @@ abstract class SilverStripeContext extends MinkContext implements SilverStripeAw
|
|||||||
$value = $field->getValue();
|
$value = $field->getValue();
|
||||||
$newValue = $opt->getAttribute('value');
|
$newValue = $opt->getAttribute('value');
|
||||||
if (is_array($value)) {
|
if (is_array($value)) {
|
||||||
if (!in_array($newValue, $value)) {
|
if (!in_array($newValue, $value ?? [])) {
|
||||||
$value[] = $newValue;
|
$value[] = $newValue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,8 +17,8 @@ trait ModuleCommandTrait
|
|||||||
*/
|
*/
|
||||||
protected function getModule($name, $error = true)
|
protected function getModule($name, $error = true)
|
||||||
{
|
{
|
||||||
if (strpos($name, '@') === 0) {
|
if (strpos($name ?? '', '@') === 0) {
|
||||||
$name = substr($name, 1);
|
$name = substr($name ?? '', 1);
|
||||||
}
|
}
|
||||||
$module = ModuleLoader::inst()->getManifest()->getModule($name);
|
$module = ModuleLoader::inst()->getManifest()->getModule($name);
|
||||||
if (!$module && $error) {
|
if (!$module && $error) {
|
||||||
|
@ -139,10 +139,10 @@ class ModuleInitialisationController implements Controller
|
|||||||
// Create feature_path
|
// Create feature_path
|
||||||
$features = $this->container->getParameter('silverstripe_extension.context.features_path');
|
$features = $this->container->getParameter('silverstripe_extension.context.features_path');
|
||||||
$fullPath = $module->getResourcePath($features);
|
$fullPath = $module->getResourcePath($features);
|
||||||
if (is_dir($fullPath)) {
|
if (is_dir($fullPath ?? '')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mkdir($fullPath, 0777, true);
|
mkdir($fullPath ?? '', 0777, true);
|
||||||
$output->writeln(
|
$output->writeln(
|
||||||
"<info>{$fullPath}</info> - <comment>place your *.feature files here</comment>"
|
"<info>{$fullPath}</info> - <comment>place your *.feature files here</comment>"
|
||||||
);
|
);
|
||||||
@ -165,13 +165,13 @@ class ModuleInitialisationController implements Controller
|
|||||||
{
|
{
|
||||||
$classesPath = $this->container->getParameter('silverstripe_extension.context.class_path');
|
$classesPath = $this->container->getParameter('silverstripe_extension.context.class_path');
|
||||||
$dirPath = $module->getResourcePath($classesPath);
|
$dirPath = $module->getResourcePath($classesPath);
|
||||||
if (!is_dir($dirPath)) {
|
if (!is_dir($dirPath ?? '')) {
|
||||||
mkdir($dirPath, 0777, true);
|
mkdir($dirPath ?? '', 0777, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scaffold base context file
|
// Scaffold base context file
|
||||||
$classPath = "{$dirPath}/FeatureContext.php";
|
$classPath = "{$dirPath}/FeatureContext.php";
|
||||||
if (is_file($classPath)) {
|
if (is_file($classPath ?? '')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ class ModuleInitialisationController implements Controller
|
|||||||
'ClassName' => $class,
|
'ClassName' => $class,
|
||||||
]);
|
]);
|
||||||
$classContent = $obj->renderWith(__DIR__.'/../../templates/FeatureContext.ss');
|
$classContent = $obj->renderWith(__DIR__.'/../../templates/FeatureContext.ss');
|
||||||
file_put_contents($classPath, $classContent);
|
file_put_contents($classPath ?? '', $classContent);
|
||||||
|
|
||||||
// Log
|
// Log
|
||||||
$output->writeln(
|
$output->writeln(
|
||||||
@ -194,12 +194,12 @@ class ModuleInitialisationController implements Controller
|
|||||||
|
|
||||||
// Add to composer json
|
// Add to composer json
|
||||||
$composerFile = $module->getResourcePath('composer.json');
|
$composerFile = $module->getResourcePath('composer.json');
|
||||||
if (!file_exists($composerFile)) {
|
if (!file_exists($composerFile ?? '')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add autoload directive to composer
|
// Add autoload directive to composer
|
||||||
$composerData = json_decode(file_get_contents($composerFile), true);
|
$composerData = json_decode(file_get_contents($composerFile ?? '') ?? '', true);
|
||||||
if (json_last_error()) {
|
if (json_last_error()) {
|
||||||
throw new Exception(json_last_error_msg());
|
throw new Exception(json_last_error_msg());
|
||||||
}
|
}
|
||||||
@ -211,7 +211,7 @@ class ModuleInitialisationController implements Controller
|
|||||||
}
|
}
|
||||||
$composerData['autoload']['psr-4']["{$fullNamespace}\\"] = $classesPath;
|
$composerData['autoload']['psr-4']["{$fullNamespace}\\"] = $classesPath;
|
||||||
file_put_contents(
|
file_put_contents(
|
||||||
$composerFile,
|
$composerFile ?? '',
|
||||||
json_encode($composerData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
|
json_encode($composerData, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ class ModuleInitialisationController implements Controller
|
|||||||
protected function getFixtureNamespace($namespaceRoot)
|
protected function getFixtureNamespace($namespaceRoot)
|
||||||
{
|
{
|
||||||
$namespaceSuffix = $this->container->getParameter('silverstripe_extension.context.namespace_suffix');
|
$namespaceSuffix = $this->container->getParameter('silverstripe_extension.context.namespace_suffix');
|
||||||
return trim($namespaceRoot, '/\\') . '\\' . $namespaceSuffix;
|
return trim($namespaceRoot ?? '', '/\\') . '\\' . $namespaceSuffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -252,7 +252,7 @@ class ModuleInitialisationController implements Controller
|
|||||||
protected function initConfig($output, $module, $namespaceRoot)
|
protected function initConfig($output, $module, $namespaceRoot)
|
||||||
{
|
{
|
||||||
$configPath = $module->getResourcePath('behat.yml');
|
$configPath = $module->getResourcePath('behat.yml');
|
||||||
if (file_exists($configPath)) {
|
if (file_exists($configPath ?? '')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$class = $this->getFixtureClass($namespaceRoot);
|
$class = $this->getFixtureClass($namespaceRoot);
|
||||||
@ -279,7 +279,7 @@ class ModuleInitialisationController implements Controller
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
file_put_contents($configPath, Yaml::dump($data, 99999999, 2));
|
file_put_contents($configPath ?? '', Yaml::dump($data, 99999999, 2));
|
||||||
|
|
||||||
$output->writeln(
|
$output->writeln(
|
||||||
"<info>{$configPath}</info> - <comment>default behat.yml created</comment>"
|
"<info>{$configPath}</info> - <comment>default behat.yml created</comment>"
|
||||||
|
@ -158,7 +158,7 @@ class ModuleSuiteLocator implements Controller
|
|||||||
// Find all candidate paths
|
// Find all candidate paths
|
||||||
foreach ([ "{$path}/", "{$path}/{$pathSuffix}"] as $parent) {
|
foreach ([ "{$path}/", "{$path}/{$pathSuffix}"] as $parent) {
|
||||||
foreach ([$parent.'behat.yml', $parent.'.behat.yml'] as $candidate) {
|
foreach ([$parent.'behat.yml', $parent.'.behat.yml'] as $candidate) {
|
||||||
if (file_exists($candidate)) {
|
if (file_exists($candidate ?? '')) {
|
||||||
return $candidate;
|
return $candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,7 +178,7 @@ class ModuleSuiteLocator implements Controller
|
|||||||
{
|
{
|
||||||
$path = $this->findModuleConfig($module);
|
$path = $this->findModuleConfig($module);
|
||||||
$yamlParser = new Parser();
|
$yamlParser = new Parser();
|
||||||
$config = $yamlParser->parse(file_get_contents($path));
|
$config = $yamlParser->parse(file_get_contents($path ?? ''));
|
||||||
if (empty($config['default']['suites'][$suite])) {
|
if (empty($config['default']['suites'][$suite])) {
|
||||||
throw new Exception("Path {$path} does not contain default.suites.{$suite} config");
|
throw new Exception("Path {$path} does not contain default.suites.{$suite} config");
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ class Extension implements ExtensionInterface
|
|||||||
];
|
];
|
||||||
|
|
||||||
foreach ($options as $file) {
|
foreach ($options as $file) {
|
||||||
if (file_exists($file)) {
|
if (file_exists($file ?? '')) {
|
||||||
require_once $file;
|
require_once $file;
|
||||||
$found = true;
|
$found = true;
|
||||||
break;
|
break;
|
||||||
|
@ -118,9 +118,9 @@ trait DebugTools
|
|||||||
// prefix with zz_ so that it alpha sorts in the directory lower than screenshots which
|
// prefix with zz_ so that it alpha sorts in the directory lower than screenshots which
|
||||||
// will typically be referred to far more often. This is mainly for when you have
|
// will typically be referred to far more often. This is mainly for when you have
|
||||||
// enabled `dumpRenderedHtmlAfterEveryStep`
|
// enabled `dumpRenderedHtmlAfterEveryStep`
|
||||||
$path = sprintf('%s/zz_%s_%d.html', $path, basename($feature->getFile()), $step->getLine());
|
$path = sprintf('%s/zz_%s_%d.html', $path, basename($feature->getFile() ?? ''), $step->getLine());
|
||||||
$html = $this->getSession()->getPage()->getOuterHtml();
|
$html = $this->getSession()->getPage()->getOuterHtml();
|
||||||
file_put_contents($path, $html);
|
file_put_contents($path ?? '', $html);
|
||||||
$this->logMessage(sprintf('Saving HTML into %s', $path));
|
$this->logMessage(sprintf('Saving HTML into %s', $path));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,9 +143,9 @@ trait DebugTools
|
|||||||
if (!$path) {
|
if (!$path) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$path = sprintf('%s/%s_%d.png', $path, basename($feature->getFile()), $step->getLine());
|
$path = sprintf('%s/%s_%d.png', $path, basename($feature->getFile() ?? ''), $step->getLine());
|
||||||
$screenshot = $driver->getScreenshot();
|
$screenshot = $driver->getScreenshot();
|
||||||
file_put_contents($path, $screenshot);
|
file_put_contents($path ?? '', $screenshot);
|
||||||
$this->logMessage(sprintf('Saving screenshot into %s', $path));
|
$this->logMessage(sprintf('Saving screenshot into %s', $path));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,16 +161,16 @@ trait DebugTools
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Filesystem::makeFolder($path);
|
Filesystem::makeFolder($path);
|
||||||
$path = realpath($path);
|
$path = realpath($path ?? '');
|
||||||
if (!file_exists($path)) {
|
if (!file_exists($path ?? '')) {
|
||||||
$this->logMessage(sprintf('"%s" is not valid directory and failed to create it', $path));
|
$this->logMessage(sprintf('"%s" is not valid directory and failed to create it', $path));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (file_exists($path) && !is_dir($path)) {
|
if (file_exists($path ?? '') && !is_dir($path ?? '')) {
|
||||||
$this->logMessage(sprintf('"%s" is not valid directory', $path));
|
$this->logMessage(sprintf('"%s" is not valid directory', $path));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (file_exists($path) && !is_writable($path)) {
|
if (file_exists($path ?? '') && !is_writable($path ?? '')) {
|
||||||
$this->logMessage(sprintf('"%s" directory is not writable', $path));
|
$this->logMessage(sprintf('"%s" directory is not writable', $path));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -112,10 +112,10 @@ class RetryableCallHandler implements CallHandler
|
|||||||
// Determine whether to call with retries
|
// Determine whether to call with retries
|
||||||
if ($retry) {
|
if ($retry) {
|
||||||
$return = $this->retryThrowable(function () use ($callable, $arguments) {
|
$return = $this->retryThrowable(function () use ($callable, $arguments) {
|
||||||
return call_user_func_array($callable, $arguments);
|
return call_user_func_array($callable, $arguments ?? []);
|
||||||
}, $this->retrySeconds);
|
}, $this->retrySeconds);
|
||||||
} else {
|
} else {
|
||||||
$return = call_user_func_array($callable, $arguments);
|
$return = call_user_func_array($callable, $arguments ?? []);
|
||||||
}
|
}
|
||||||
} catch (Exception $caught) {
|
} catch (Exception $caught) {
|
||||||
$exception = $caught;
|
$exception = $caught;
|
||||||
@ -144,7 +144,7 @@ class RetryableCallHandler implements CallHandler
|
|||||||
private function startErrorAndOutputBuffering(Call $call)
|
private function startErrorAndOutputBuffering(Call $call)
|
||||||
{
|
{
|
||||||
$errorReporting = $call->getErrorReportingLevel() ? : $this->errorReportingLevel;
|
$errorReporting = $call->getErrorReportingLevel() ? : $this->errorReportingLevel;
|
||||||
set_error_handler(array($this, 'handleError'), $errorReporting);
|
set_error_handler(array($this, 'handleError'), $errorReporting ?? 0);
|
||||||
$this->obStarted = ob_start();
|
$this->obStarted = ob_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class TestMailer extends BaseTestMailer
|
|||||||
{
|
{
|
||||||
$matches = $this->findEmails($to, $from, $subject, $content);
|
$matches = $this->findEmails($to, $from, $subject, $content);
|
||||||
//got the count of matches emails
|
//got the count of matches emails
|
||||||
$emailCount = count($matches);
|
$emailCount = count($matches ?? []);
|
||||||
//get the last(latest) one
|
//get the last(latest) one
|
||||||
return $matches ? $matches[$emailCount-1] : null;
|
return $matches ? $matches[$emailCount-1] : null;
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ class TestMailer extends BaseTestMailer
|
|||||||
$value = (isset($args[$i])) ? $args[$i] : null;
|
$value = (isset($args[$i])) ? $args[$i] : null;
|
||||||
if ($value) {
|
if ($value) {
|
||||||
if ($value[0] == '/') {
|
if ($value[0] == '/') {
|
||||||
$matched = preg_match($value, $email->$field);
|
$matched = preg_match($value ?? '', $email->$field ?? '');
|
||||||
} else {
|
} else {
|
||||||
$matched = ($value == $email->$field);
|
$matched = ($value == $email->$field);
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ class TestMailer extends BaseTestMailer
|
|||||||
if (!isset($state->emails)) {
|
if (!isset($state->emails)) {
|
||||||
$state->emails = array();
|
$state->emails = array();
|
||||||
}
|
}
|
||||||
$state->emails[] = array_filter($data);
|
$state->emails[] = array_filter($data ?? []);
|
||||||
$this->testSessionEnvironment->applyState($state);
|
$this->testSessionEnvironment->applyState($state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user