Я реализую пакет Laravel 7, но при запуске модульного теста я получаю исключение RuntimeException
{
"name": "",
"license": "MIT",
"authors": [
{
"name": "",
"email": ""
}
],
"require": {
"php": "^7.3",
"guzzlehttp/guzzle": "^7.0",
"illuminate/config": "^7.19",
"illuminate/contracts": "^7.19",
"illuminate/http": "^7.19",
"moneyphp/money": "^3.3"
},
"autoload": {
"psr-4": {
"QuickPay\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"QuickPay\\Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"require-dev": {
"phpunit/phpunit": "^9.0",
"mockery/mockery": "dev-master",
"nunomaduro/collision": "^5.0",
"pestphp/pest": "^0.2.3"
},
"config": {
"sort-packages": true
}
}
Класс, который я тестирую
namespace QuickPay\Ping;
use Illuminate\Support\Facades\Http;
class Ping {
/**
* Send ping request to https://api.quickpay.net/ping
*/
public static function send() {
$response = Http::get('https://api.quickpay.net/ping');
return $response;
}
}
Мой модульный тест
use QuickPay\Ping\Ping;
test('ping request returns pong', function () {
assertEquals([], Ping::send());
});
Исключение
• Tests\Unit\PingTest > ping request returns pong
RuntimeException
A facade root has not been set.
at vendor/illuminate/support/Facades/Facade.php:258
254▕ {
255▕ $instance = static::getFacadeRoot();
256▕
257▕ if (! $instance) {
➜ 258▕ throw new RuntimeException('A facade root has not been set.');
259▕ }
260▕
261▕ return $instance->$method(...$args);
262▕ }
1 src/Ping/Ping.php:16
Illuminate\Support\Facades\Facade::__callStatic("get")
2 tests/Unit/PingTest.php:6
QuickPay\Ping\Ping::send()
Я выполнил команду composer dump-autoload.