When writing the automated test case of Lighthouse 5, split the test method in a file into two test methods, and report an error: Error: call to undefined method IlluMinate\Support\Facads\Config::set()
1. When writing the automated test case of Lighthouse 5, split a test method into two test methods. The present stage is a method
public function testGetThemeById(): void
{
$response = $this->graphQL('
query GetThemeById($id: ID!) {
onlineStoreTheme(themeId: $id) {
id
editable
createdAt
name
themeAssets {
id
themeId
version
key
mimeType
category
schema
createdAt
updatedAt
}
}
}
',
[
'id' => 'vogue',
]
);
$response->assertJson(
[
'data' => [
'onlineStoreTheme' => [
'id' => 'vogue'
],
],
]
)->assertJsonStructure([
'data' => [
'onlineStoreTheme' => [
'themeAssets' => [
[
'id',
'themeId',
'version',
'key',
'mimeType',
'category',
'schema',
'createdAt',
'updatedAt',
]
]
]
],
]
);
}
2, split into two methods
graphQL('
query GetThemeById($id: ID!) {
onlineStoreTheme(themeId: $id) {
id
editable
createdAt
name
}
}
',
[
'id' => 'vogue',
]
);
$response->assertJson(
[
'data' => [
'onlineStoreTheme' => [
'id' => 'vogue'
],
],
]
);
}
public function testGetThemeAssetsById(): void
{
$response = $this->graphQL('
query GetThemeAssetsById($id: ID!) {
onlineStoreTheme(themeId: $id) {
themeAssets {
id
themeId
version
key
mimeType
category
schema
createdAt
updatedAt
}
}
}
',
[
'id' => 'vogue',
]
);
$response->assertJsonStructure(
[
'data' => [
'onlineStoreTheme' => [
'themeAssets' => [
[
'id',
'themeId',
'version',
'key',
'mimeType',
'category',
'schema',
'createdAt',
'updatedAt',
]
]
]
],
]
);
}
protected function setUp(): void
{
parent::setUp();
$this->bootClearsSchemaCache();
}
}
3. Run the test and report an error: Error: Error: call to undefined method illuminate\support\facades\config::set(). as shown in Figure 1
PS E:\wwwroot\object> ./vendor/bin/phpunit .\Modules\ThemeStore\Tests\Functional\GraphQl\OnlineStoreThemeGraphQlApiTest.php
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
.E 2 / 2 (100%)
Time: 1.02 seconds, Memory: 70.00 MB
There was 1 error:
1) Modules\ThemeStore\Tests\Functional\GraphQl\OnlineStoreThemeGraphQlApiTest::testGetThemeAssetsById
Error: Call to undefined method Illuminate\Support\Facades\Config::set()
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Support\ServiceProvider.php:63
E:\wwwroot\object\Modules\ThemeSetting\Providers\ThemeServiceProvider.php:103
E:\wwwroot\object\Modules\ThemeSetting\Providers\ThemeServiceProvider.php:37
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:616
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\ProviderRepository.php:75
E:\wwwroot\object\vendor\nwidart\laravel-modules\src\Laravel\Module.php:33
E:\wwwroot\object\vendor\nwidart\laravel-modules\src\Module.php:264
E:\wwwroot\object\vendor\nwidart\laravel-modules\src\FileRepository.php:321
E:\wwwroot\object\vendor\nwidart\laravel-modules\src\Providers\BootstrapServiceProvider.php:23
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:616
E:\wwwroot\object\vendor\nwidart\laravel-modules\src\ModulesServiceProvider.php:31
E:\wwwroot\object\vendor\nwidart\laravel-modules\src\LaravelModulesServiceProvider.php:17
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:36
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Container\Util.php:37
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:93
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:37
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Container\Container.php:590
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:856
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:839
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:840
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\BootProviders.php:17
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:219
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php:320
E:\wwwroot\object\tests\CreatesApplication.php:18
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestCase.php:102
E:\wwwroot\object\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestCase.php:81
E:\wwwroot\object\Modules\ThemeStore\Tests\Functional\GraphQl\OnlineStoreThemeGraphQlApiTest.php:74
phpvfscomposer://E:\wwwroot\object\vendor\phpunit\phpunit\phpunit:60
ERRORS!
Tests: 2, Assertions: 1, Errors: 1.
PS E:\wwwroot\object>
4. At this time, if any of the methods in the method are deleted, they can be tested to pass.
5. Print the $this->app in the first line of the two methods, respectively[‘config’], to confirm that only the first method is printed successfully, the second method reports an error: Error: call to undefined method IlluMinate\Support\Facads\config::set(). It can be confirmed that in the second method, the application instance has ceased to exist.
6. Reference URL:https://phpunit.readthedocs.io/en/9.5/configuration.html. ProcessIsolation property. This attribute configures whether each test should be run in a separate php process for increased isolation. Possible values: true or false (default: false). This property configures whether each test should run in a separate PHP process to increase isolation.
7. Edit the file /phpunit.xml and set processisolation=”true”. as shown in Figure 2
8. Run the test again, the test passes. as shown in Figure 3
9. If processisolation=”true” is not set, you can add the option –process-isolation when running the test. Still can test pass. as shown in Figure 4
PS E:\wwwroot\object> ./vendor/bin/phpunit --process-isolation .\Modules\ThemeStore\Tests\Functional\GraphQl\OnlineStoreThemeGraphQlApiTest.php
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
.. 2 / 2 (100%)
Time: 2.56 seconds, Memory: 16.00 MB
OK (2 tests, 14 assertions)
PS E:\wwwroot\object>



