首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel 8没有运行测试

Laravel 8没有运行测试
EN

Stack Overflow用户
提问于 2021-01-16 20:21:54
回答 1查看 312关注 0票数 0

首先,我现在的环境:

  • 码头版20.10.1
  • docker-撰写版本1.27.4
  • MySql 8.0.21 (码头形象)
  • PHP 7.4.13 -码头形象
  • PHP 7.4.13本地

Composer.json:

代码语言:javascript
复制
"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手工测试
代码语言:javascript
复制
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

我的测试文件(我甚至没有完成我的测试):

代码语言:javascript
复制
<?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);
    }
}
EN

回答 1

Stack Overflow用户

发布于 2021-01-16 20:21:54

嗯,“解决方案”有点简单,在进行大量搜索之前,我在GitHub问题上找到了以下声明

  • “对我来说,这是访问权限。这可能是vm/容器环境的一个问题。”

我试着和苏一起运行,发现了另一个错误:

  • $ sudo php artisan测试
代码语言:javascript
复制
   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在本地运行这个项目,所以我尝试在容器中运行它,它成功了!

  • $ docker exec f546517976f4 php手工测试

TL;DR :在Docker容器中运行测试

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65754327

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档