Skip to content

Commit

Permalink
Merge branch 'master' into 2.x-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jul 30, 2024
2 parents 51aaf2b + f68c5ef commit 04f55ef
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion monorepo/stubs/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Application
* @param class-string<T> $abstract
* @return T
*/
public function make(string $abstract)
public function make(string $abstract, array $parameters = [])
{
}
}
2 changes: 1 addition & 1 deletion monorepo/stubs/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @param class-string<T> $abstract
* @return T
*/
function app(string $abstract)
function app(string $abstract = null)
{
}

Expand Down
35 changes: 35 additions & 0 deletions packages/testing/src/FluentTestingHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,39 @@ protected function assertAllSame(...$vars): void
$this->assertSame($first, $var);
}
}

/**
* @experimental Helper to print and die.
*/
protected function dd($var): void
{
if (is_string($var)) {
echo "```\n";
echo $var.($var[-1] === "\n" ? '' : "\n");
echo "```\n";
} elseif (is_array($var)) {
echo "```php\n";
echo $this->formatArray($var);
echo "```\n";
} else {
dd($var);
}

exit;
}

/**
* @experimental Helper function to format an array as a plain PHP array with [] syntax.
*/
private function formatArray(array $array): string
{
$json = json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);

// Transform JSON to PHP array syntax
$php = preg_replace('/^(\s*)\"(\w+)\":/m', '$1$2:', $json); // Remove quotes from keys
$php = str_replace('{', '[', $php); // Replace { with [
$php = str_replace('}', ']', $php); // Replace } with ]

return $php."\n";
}
}

0 comments on commit 04f55ef

Please sign in to comment.