Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for arguments of type Closure #110

Merged
merged 5 commits into from
Mar 27, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/Internal/ArgumentAsString.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(

public static function get(mixed $argument): string
{
return (string) new self($argument);
return (string)new self($argument);
alnivv-vi marked this conversation as resolved.
Show resolved Hide resolved
}

private function prepareArgument(mixed $argument): mixed
Expand All @@ -56,26 +56,30 @@ private function prepareString(string $argument): string
*/
private function prepareResource($argument): string
{
return (string) $argument;
return (string)$argument;
alnivv-vi marked this conversation as resolved.
Show resolved Hide resolved
}

private function prepareArray(array $argument): array
{
return array_map(
fn (mixed $element): mixed => $this->prepareArgument($element),
fn(mixed $element): mixed => $this->prepareArgument($element),
$argument,
);
}

private function isClosure(object $argument): bool
{
return $argument instanceof \Closure;
}

private function prepareObject(object $argument): string
{
if (isset($argument->__mocked) && is_object($argument->__mocked)) {
if (!$this->isClosure($argument) && isset($argument->__mocked) && is_object($argument->__mocked)) {
$argument = $argument->__mocked;
}
if ($argument instanceof Stringable) {
return (string) $argument;
return (string)$argument;
alnivv-vi marked this conversation as resolved.
Show resolved Hide resolved
}

$webdriverByClass = '\Facebook\WebDriver\WebDriverBy';
if (class_exists($webdriverByClass) && is_a($argument, $webdriverByClass)) {
return $this->webDriverByAsString($argument);
Expand All @@ -95,11 +99,11 @@ public function __toString(): string
private function webDriverByAsString(object $selector): string
{
$type = method_exists($selector, 'getMechanism')
? (string) $selector->getMechanism()
? (string)$selector->getMechanism()
alnivv-vi marked this conversation as resolved.
Show resolved Hide resolved
: null;

$locator = method_exists($selector, 'getValue')
? (string) $selector->getValue()
? (string)$selector->getValue()
alnivv-vi marked this conversation as resolved.
Show resolved Hide resolved
: null;

if (!isset($type, $locator)) {
Expand Down