В Laravel Phpunit BindingResolutionException генерируется при вызове помощника Illuminate config () внутри Guzzle Promise - PullRequest
0 голосов
/ 31 марта 2020

Я получил BindingResolutionException () при вызове глобальной вспомогательной функции config () в Guzzle Promise внутри контроллера.

Похоже, что помощники Illuminate. php не загружается под Guzzle Promise при запуске phpunit , Это ошибка или я что-то неправильно использовал?

Ниже приведен мой код. (Это новый Laravel проект)

Сценарий

./vendor/phpunit/phpunit/phpunit tests/MyTest.php

Исключение

Illuminate\Contracts\Container\BindingResolutionException {#448
  #message: "Target class [config] does not exist."
  #code: 0
  #file: "./vendor/laravel/framework/src/Illuminate/Container/Container.php"
  #line: 809
  -previous: ReflectionException {#540
    #message: "Class config does not exist"
    #code: -1
    #file: "./vendor/laravel/framework/src/Illuminate/Container/Container.php"
    #line: 807
    trace: {
      ./vendor/laravel/framework/src/Illuminate/Container/Container.php:807 { …}
      ./vendor/laravel/framework/src/Illuminate/Container/Container.php:685 { …}
      ./vendor/laravel/framework/src/Illuminate/Foundation/Application.php:794 { …}
      ./vendor/laravel/framework/src/Illuminate/Container/Container.php:633 { …}
      ./vendor/laravel/framework/src/Illuminate/Foundation/Application.php:779 { …}
      ./vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:119 { …}
      ./vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:275 { …}
      ./app/Http/Controllers/Controller.php:22 {
        App\Http\Controllers\Controller->App\Http\Controllers\{closure}
        › try {
        ›     dump(config('app.env'));
        › } catch (\Exception $e) {
        arguments: {
          $key: "app.env"
        }
      }
      ./vendor/guzzlehttp/promises/src/FulfilledPromise.php:39 { …}
      ./vendor/guzzlehttp/promises/src/TaskQueue.php:47 { …}
      ./vendor/guzzlehttp/promises/src/TaskQueue.php:26 { …}
      GuzzleHttp\Promise\TaskQueue->GuzzleHttp\Promise\{closure}() {}
    }
  }
  trace: {
    ./vendor/laravel/framework/src/Illuminate/Container/Container.php:809 { …}
    ./vendor/laravel/framework/src/Illuminate/Container/Container.php:685 { …}
    ./vendor/laravel/framework/src/Illuminate/Foundation/Application.php:794 { …}
    ./vendor/laravel/framework/src/Illuminate/Container/Container.php:633 { …}
    ./vendor/laravel/framework/src/Illuminate/Foundation/Application.php:779 { …}
    ./vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:119 { …}
    ./vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:275 { …}
    ./app/Http/Controllers/Controller.php:22 {
      App\Http\Controllers\Controller->App\Http\Controllers\{closure}
      › try {
      ›     dump(config('app.env'));
      › } catch (\Exception $e) {
      arguments: {
        $key: "app.env"
      }
    }
    ./vendor/guzzlehttp/promises/src/FulfilledPromise.php:39 { …}
    ./vendor/guzzlehttp/promises/src/TaskQueue.php:47 { …}
    ./vendor/guzzlehttp/promises/src/TaskQueue.php:26 { …}
    GuzzleHttp\Promise\TaskQueue->GuzzleHttp\Promise\{closure}() {}
  }
}

Контроллер

...
    public function index()
    {
        dump(config('app.env'));

        $promise = new FulfilledPromise(null);
        $promise->then(function () {
            try {
                dump(config('app.env'));
            } catch (\Exception $e) {
                dump($e);
            }
        });
        return response('ok', 200);
    }
...

Тест

...
    public function testExample()
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }
...

composer. json

...
    "require": {
        "php": "^7.2.5",
        "fideloper/proxy": "^4.2",
        "fruitcake/laravel-cors": "^1.0",
        "guzzlehttp/guzzle": "^6.3",
        "laravel/framework": "^7.0",
        "laravel/tinker": "^2.0"
    },
    "require-dev": {
        "facade/ignition": "^2.0",
        "fzaninotto/faker": "^1.9.1",
        "mockery/mockery": "^1.3.1",
        "nunomaduro/collision": "^4.1",
        "phpunit/phpunit": "^8.5"
    },
...
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },

веб. php

...
Route::get('/', 'Controller@index');
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...