gpt4 book ai didi

laravel - ReflectionException : Class env does not exist. 我做错了什么吗?

转载 作者:行者123 更新时间:2023-12-04 16:02:36 27 4
gpt4 key购买 nike

我目前正在尝试设置 phpunit 测试来测试我的 API。问题是我以某种方式无法在没有问题的情况下发送完全相同的请求两次。

我曾尝试更改 phpunit.xml 以查看是否存在问题但没有成功,所以我现在怀疑自己认为我在代码本身做错了什么。

public function test_can_register_user() {
$this->consoleLog('test_can_register_user');
$generatedUser = str_random(5) . '@example.com';

$data = [
'name' => 'Test User',
'email' => $generatedUser,
'password' => 'test',
];

var_dump($data);

$expect = [
'success' => true,
'message' => 'Thanks for signing up! Please check your email to complete your registration.',
];

$request = $this->post('/api/auth/register', $data)
->assertStatus(200)
->assertJson($expect);

return $generatedUser;
}

/**
* @depends test_can_register_user
* @param $generatedUser
*/
public function test_can_not_register_same_email($generatedUser) {
$this->consoleLog('test_can_not_register_same_email');

$data = [
'name' => 'Test User',
'email' => $generatedUser,
'password' => 'test',
];

var_dump($data);

$expect = [
'success' => false,
"error" => [
"email" => [
"The email has already been taken."
]
]
];

$request = $this->post('/api/auth/register', $data);
var_dump($request->json());
$request->assertStatus(200);
}

     <php>
<env name="DB_CONNECTION" value="mysql"/>
<env name="APP_DEBUG" value="false"/>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
</php>

预期结果是返回状态 200。控制台中的实际结果如下:
Running test:
test_can_not_register_same_email
array(3) {
["name"]=>
string(9) "Test User"
["email"]=>
string(17) "C4v67@example.com"
["password"]=>
string(4) "test"
}

ReflectionException : Class env does not exist
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Container\Container.php:779
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Container\Container.php:658
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Container\Container.php:609
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:759
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Container\Container.php:1222
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:519
D:\Yeagger\yeagger-api\app\Providers\TelescopeServiceProvider.php:24
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Support\HigherOrderCollectionProxy.php:60
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Support\HigherOrderCollectionProxy.php:60
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Support\Collection.php:455
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Support\HigherOrderCollectionProxy.php:61
D:\Yeagger\yeagger-api\vendor\laravel\telescope\src\Telescope.php:263
D:\Yeagger\yeagger-api\vendor\laravel\telescope\src\Telescope.php:222
D:\Yeagger\yeagger-api\vendor\laravel\telescope\src\Telescope.php:270
D:\Yeagger\yeagger-api\vendor\laravel\telescope\src\Telescope.php:294
D:\Yeagger\yeagger-api\vendor\laravel\telescope\src\Watchers\CacheWatcher.php:45
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php:360
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php:209
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Cache\Repository.php:497
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Cache\Repository.php:107
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Cache\RateLimiter.php:82
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Cache\RateLimiter.php:39
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Routing\Middleware\ThrottleRequests.php:52
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:151
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:104
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Routing\Router.php:684
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Routing\Router.php:659
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Routing\Router.php:625
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Routing\Router.php:614
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:176
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:30
D:\Yeagger\yeagger-api\vendor\barryvdh\laravel-cors\src\HandleCors.php:36
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:151
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
D:\Yeagger\yeagger-api\vendor\fideloper\proxy\src\TrustProxies.php:57
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:151
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php:31
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:151
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php:31
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:151
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php:27
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:151
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php:62
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:151
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:104
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:151
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:116
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\MakesHttpRequests.php:345
D:\Yeagger\yeagger-api\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\MakesHttpRequests.php:195
D:\Yeagger\yeagger-api\tests\Unit\UserTest.php:67

最佳答案

dd($exception);App\Exceptions\Handler::report()它为您提供了更好的错误消息。filesystem 中出现错误给我配置!

关于laravel - ReflectionException : Class env does not exist. 我做错了什么吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55355707/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com