首先,我现在的环境:
Composer.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"
}在运行时,我会收到以下错误:
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我的测试文件(我甚至没有完成我的测试):
<?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);
}
}发布于 2021-01-16 20:21:54
嗯,“解决方案”有点简单,在进行大量搜索之前,我在GitHub问题上找到了以下声明
我试着和苏一起运行,发现了另一个错误:
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嗯,而且它也不起作用,但是因为我使用docker在本地运行这个项目,所以我尝试在容器中运行它,它成功了!
TL;DR :在Docker容器中运行测试
https://stackoverflow.com/questions/65754327
复制相似问题