[英]Laravel 8 not running tests
First of all, my current environment:首先,我现在的环境:
Composer.json:作曲家.json:
"require": {
"php": "^7.4|^8.0",
"doctrine/dbal": "^3.0",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "7.0",
"laravel-lang/lang": "~8.0",
"laravel/framework": "^8.12",
"laravel/tinker": "^2.5",
"ramsey/uuid": "^4.1"
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^2.9",
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/breeze": "^1.0",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.3.3"
}
I'm receiving the following errors when running:我在运行时收到以下错误:
$ php artisan test
$ php 工匠测试
PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException:
Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable.
in /home/______/proj/php//______/vendor/laravel/framework/src/Illuminate/Container/Container.php:1038
My Test file(I didn't even finished writing my test):我的测试文件(我什至没有写完我的测试):
<?php
namespace Tests\Unit;
use App\Models\Pessoa;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class __________ extends TestCase
{
use RefreshDatabase;
protected Pessoa $pessoa;
/**
* A basic unit test example.
*
* @return void
*/
public function testExample()
{
$this->pessoa = factory(Pessoa::class);
$this->assertTrue(true);
}
}
Well, the "solution" was kinda of easy, before searching a lot, I found the following statement on GitHub issues :好吧,“解决方案”有点简单,在搜索很多之前,我找到了关于GitHub 问题的以下声明:
I tried running it with SU, and got another error:我尝试使用 SU 运行它,但又遇到了另一个错误:
$ sudo php artisan test
$ sudo php 工匠测试
FAIL Tests\Unit\____________
⨯ example
---
• Tests\Unit\_____________ > example
Illuminate\Database\QueryException
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
674▕ // If an exception occurs when attempting to run a query, we'll format the error
675▕ // message to include the bindings with SQL, which will make this exception a
676▕ // lot more helpful to the developer instead of just the database's errors.
677▕ catch (Exception $e) {
➜ 678▕ throw new QueryException(
679▕ $query, $this->prepareBindings($bindings), $e
680▕ );
681▕ }
682▕
Tests: 1 failed
Time: 0.12s
Well, and it didn't work either, but because I was using docker to run this project locally, I tried to run it inside the Container, and it worked!好吧,它也不起作用,但是因为我使用 docker 在本地运行这个项目,所以我尝试在 Container 中运行它,它起作用了!
TL;DR: Run the tests inside the Docker Container TL;DR:在 Docker 容器内运行测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.