diff --git a/monorepo/stubs/Application.php b/monorepo/stubs/Application.php index aeb29f35484..2d9e5fc2da7 100644 --- a/monorepo/stubs/Application.php +++ b/monorepo/stubs/Application.php @@ -10,7 +10,7 @@ class Application * @param class-string $abstract * @return T */ - public function make(string $abstract) + public function make(string $abstract, array $parameters = []) { } } diff --git a/monorepo/stubs/helpers.php b/monorepo/stubs/helpers.php index 821a819bebd..5aeaaf54ed0 100644 --- a/monorepo/stubs/helpers.php +++ b/monorepo/stubs/helpers.php @@ -6,7 +6,7 @@ * @param class-string $abstract * @return T */ -function app(string $abstract) +function app(string $abstract = null) { } diff --git a/packages/testing/src/FluentTestingHelpers.php b/packages/testing/src/FluentTestingHelpers.php index 5caf66d0c9c..77bc23b3fdc 100644 --- a/packages/testing/src/FluentTestingHelpers.php +++ b/packages/testing/src/FluentTestingHelpers.php @@ -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"; + } }