feat(pest): 支持了依赖注入

This commit is contained in:
李东云
2023-09-19 18:22:47 +08:00
parent 4b5e1740bc
commit eb9c9557c5
5 changed files with 91 additions and 46 deletions

View File

@@ -21,7 +21,7 @@ test(
* @throws GuzzleException
*/
function () {
$service = new GoodsRpc('http://localhost:9611');
$service = new GoodsRpc('http://192.168.2.218:9611');
$goods = $service->find(
1,
[

View File

@@ -1,6 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
@@ -9,8 +10,28 @@ declare(strict_types=1);
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use Hyperf\Context\ApplicationContext;
use Hyperf\Di\Container;
use Hyperf\Di\Definition\DefinitionSource;
use Psr\Container\ContainerInterface;
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
error_reporting(E_ALL);
date_default_timezone_set('Asia/Shanghai');
!defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 1));
!defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL);
Swoole\Runtime::enableCoroutine(true);
require BASE_PATH . '/vendor/autoload.php';
Hyperf\Di\ClassLoader::init();
$container = new Container(new DefinitionSource([]));
if (!$container instanceof ContainerInterface) {
throw new RuntimeException('The dependency injection container is invalid.');
}
$container = ApplicationContext::setContainer($container);