From a9940f36ba861cd2cb0ce8ce7effac29d816d154 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 29 Jul 2024 13:48:14 +0200 Subject: [PATCH 1/6] Update test stub to support nullable function call --- monorepo/stubs/helpers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) { } From 710b4c7404a91d4375a6467dd347afc6138adf06 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 30 Jul 2024 13:12:29 +0200 Subject: [PATCH 2/6] Update test stub to support parameters --- monorepo/stubs/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 = []) { } } From 65a3aefc0348a3379d0c88dd287790e653c13c01 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 30 Jul 2024 13:40:00 +0200 Subject: [PATCH 3/6] Add new helper to print and die --- packages/testing/src/FluentTestingHelpers.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/testing/src/FluentTestingHelpers.php b/packages/testing/src/FluentTestingHelpers.php index 5caf66d0c9c..1423b00b96a 100644 --- a/packages/testing/src/FluentTestingHelpers.php +++ b/packages/testing/src/FluentTestingHelpers.php @@ -58,4 +58,20 @@ 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 $var; + } elseif(is_array($var)) { + var_export($var); + } else { + dd($var); + } + + die; + } } From 15a084ce1832ce0b511ec6572b98f9fdbdc65ffc Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 30 Jul 2024 13:41:57 +0200 Subject: [PATCH 4/6] Improve string output --- packages/testing/src/FluentTestingHelpers.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/testing/src/FluentTestingHelpers.php b/packages/testing/src/FluentTestingHelpers.php index 1423b00b96a..b0255a5c8aa 100644 --- a/packages/testing/src/FluentTestingHelpers.php +++ b/packages/testing/src/FluentTestingHelpers.php @@ -65,7 +65,9 @@ protected function assertAllSame(...$vars): void protected function dd($var): void { if (is_string($var)) { - echo $var; + echo "```\n"; + echo $var.($var[-1] === "\n" ? '' : "\n"); + echo "```\n"; } elseif(is_array($var)) { var_export($var); } else { From 79b4efe6c9bf1fd16964ae787f5cd1ba314410ad Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Tue, 30 Jul 2024 13:50:34 +0200 Subject: [PATCH 5/6] Format the array as a PHP array --- packages/testing/src/FluentTestingHelpers.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/testing/src/FluentTestingHelpers.php b/packages/testing/src/FluentTestingHelpers.php index b0255a5c8aa..10ebb8e916f 100644 --- a/packages/testing/src/FluentTestingHelpers.php +++ b/packages/testing/src/FluentTestingHelpers.php @@ -69,11 +69,28 @@ protected function dd($var): void echo $var.($var[-1] === "\n" ? '' : "\n"); echo "```\n"; } elseif(is_array($var)) { - var_export($var); + echo "```php\n"; + echo $this->formatArray($var); + echo "```\n"; } else { dd($var); } die; } + + /** + * @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"; + } } From 7a00e8bf5a636840cff7ef2106fabe67ec69f1c4 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 30 Jul 2024 11:50:47 +0000 Subject: [PATCH 6/6] Apply fixes from StyleCI --- packages/testing/src/FluentTestingHelpers.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/testing/src/FluentTestingHelpers.php b/packages/testing/src/FluentTestingHelpers.php index 10ebb8e916f..77bc23b3fdc 100644 --- a/packages/testing/src/FluentTestingHelpers.php +++ b/packages/testing/src/FluentTestingHelpers.php @@ -68,7 +68,7 @@ protected function dd($var): void echo "```\n"; echo $var.($var[-1] === "\n" ? '' : "\n"); echo "```\n"; - } elseif(is_array($var)) { + } elseif (is_array($var)) { echo "```php\n"; echo $this->formatArray($var); echo "```\n"; @@ -76,7 +76,7 @@ protected function dd($var): void dd($var); } - die; + exit; } /**