Skip to content

Commit 389202b

Browse files
committed
chore(deps): replace illuminate/testing with orchestra/testbench
Adds orchestra/testbench as the dev dependency for Laravel integration tests. Laravel framework (pulled in transitively) already provides the TestResponse class previously sourced from illuminate/testing, so the former dev dep is removed. The namespace-level config() mock used by unit tests now delegates to the real framework helper when a Laravel app is bootstrapped (via testbench), so integration tests see actual config values instead of the empty $GLOBALS stub.
1 parent e0088f0 commit 389202b

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"require-dev": {
1313
"friendsofphp/php-cs-fixer": "^3.94",
14-
"illuminate/testing": "^11.0 || ^12.0",
14+
"orchestra/testbench": "^9.0 || ^10.0 || ^11.0",
1515
"phpstan/phpstan": "^2.0",
1616
"symfony/http-foundation": "^6.4 || ^7.0 || ^8.0"
1717
},

tests/Helpers/LaravelConfigMock.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
namespace Studio\OpenApiContractTesting\Laravel;
66

7+
use Throwable;
8+
9+
use function array_key_exists;
10+
use function function_exists;
11+
712
/**
813
* Namespace-level config() mock for unit testing.
914
*
@@ -21,9 +26,33 @@
2126
* in ValidatesOpenApiSchema.php (i.e., no "use function config" import).
2227
* Adding such an import would bypass namespace resolution and break this mock.
2328
*
24-
* Test values are read from $GLOBALS['__openapi_testing_config'].
29+
* Resolution order:
30+
* 1. A unit-test override in $GLOBALS['__openapi_testing_config'] wins — unit
31+
* tests set this explicitly to control what the trait sees.
32+
* 2. Otherwise, defer to the real framework helper when an app is running
33+
* (integration tests using orchestra/testbench). The global helper is
34+
* invoked via a variable function to bypass both PHP namespace resolution
35+
* (which would recurse into this mock) and cs-fixer's global_namespace_import
36+
* rule (which would strip a leading backslash and break the call).
2537
*/
2638
function config(string $key, mixed $default = null): mixed
2739
{
28-
return $GLOBALS['__openapi_testing_config'][$key] ?? $default;
40+
if (
41+
isset($GLOBALS['__openapi_testing_config']) &&
42+
array_key_exists($key, $GLOBALS['__openapi_testing_config'])
43+
) {
44+
return $GLOBALS['__openapi_testing_config'][$key];
45+
}
46+
47+
if (function_exists('config')) {
48+
$globalConfig = 'config';
49+
50+
try {
51+
return $globalConfig($key, $default);
52+
} catch (Throwable) {
53+
return $default;
54+
}
55+
}
56+
57+
return $default;
2958
}

0 commit comments

Comments
 (0)