Skip to content

Commit

Permalink
composer.json文件修改支持hyperf3和加InterWithHttpClientTest类
Browse files Browse the repository at this point in the history
  • Loading branch information
pengxuxu committed Feb 22, 2023
1 parent 91dacd0 commit 0b7f677
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 118 deletions.
42 changes: 0 additions & 42 deletions .travis.yml

This file was deleted.

16 changes: 4 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,15 @@
},
"require": {
"php": ">=8.0",
"w7corp/easywechat": "^6.3",
"ext-swoole": ">=4.5"
"w7corp/easywechat": "^6.11.1",
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.14",
"friendsofphp/php-cs-fixer": "^2.14|^3.0",
"mockery/mockery": "^1.0",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": ">=7.0",
"swoole/ide-helper": "dev-master",
"swow/swow": "dev-develop",
"symfony/var-dumper": "^5.1",
"hyperf/context": "~2.2.0",
"hyperf/http-message":"~2.2.0",
"hyperf/http-server": "~2.2.0",
"hyperf/contract": "~2.2.0",
"hyperf/utils": "~2.2.0",
"psr/http-message": "^1.0"
"swoole/ide-helper": "^4.5",
"hyperf/context": "~2.2.0|^3.0",
},
"conflict": {
"w7corp/easywechat": "<6.0"
Expand Down
52 changes: 6 additions & 46 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
use Hyperf\HttpServer\Contract\RequestInterface;
use Psr\Container\ContainerInterface;
use Psr\SimpleCache\CacheInterface;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\Request;

/**
* Class Factory.
Expand All @@ -40,14 +38,17 @@ class Factory
'work' => 'work',
'openWork' => 'open_work',
];

/**
* @var ContainerInterface
*/
protected $container;

/**
* @var ConfigInterface
*/
protected $config;

/**
* @var CacheInterface
*/
Expand All @@ -60,7 +61,6 @@ public function __construct(ContainerInterface $container)
$this->config = $container->get(ConfigInterface::class);

$this->cache = $container->get(CacheInterface::class);

}

public function __call($functionName, $args)
Expand All @@ -72,6 +72,7 @@ public function __call($functionName, $args)
if (!isset($this->configMap[$functionName])) {
throw new \Exception('方法不存在!');
}

$configName = $this->configMap[$functionName];

$appName = ucfirst($functionName);
Expand All @@ -80,18 +81,14 @@ public function __call($functionName, $args)

$application = "\\EasyWeChat\\{$appName}\\Application";

$symfonyRequest = $this->getRequest();

$symfonyRequest->headers = $this->getHeaders();

$app = new $application($config);

if (method_exists($app, 'setCache')) {
$app->setCache($this->cache);
}

if (method_exists($app, 'setRequestFromSymfonyRequest')) {
$app->setRequestFromSymfonyRequest($symfonyRequest);
if (method_exists($app, 'setRequest')) {
$app->setRequest($this->container->get(RequestInterface::class));
}

return $app;
Expand All @@ -108,41 +105,4 @@ private function getConfig(string $name, array $config = []): array

return array_merge($moduleConfig, $defaultConfig, $config);
}

/**
* 获取Request请求
*/
private function getRequest(): Request
{
$request = $this->container->get(RequestInterface::class);

$uploadFiles = $request->getUploadedFiles() ?? [];

$files = [];

foreach ($uploadFiles as $k => $v) {
$files[$k] = $v->toArray();
}

return new Request(
$request->getQueryParams(),
$request->getParsedBody(),
[],
$request->getCookieParams(),
$files,
$request->getServerParams(),
$request->getBody()->getContents()
);
}

/**
* 获取header
*/
private function getHeaders(): HeaderBag
{
$request = $this->container->get(RequestInterface::class);

return new HeaderBag($request->getHeaders());
}

}
35 changes: 35 additions & 0 deletions tests/Cases/InteractWithHttpClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Cases;

use EasyWeChat\Kernel\Traits\InteractWithHttpClient;
use Pengxuxu\HyperfWechat\HttpClient;

class Http
{
use InteractWithHttpClient;
}


/**
* @internal
* @coversNothing
*/
class InteractWithHttpClientTest extends AbstractTestCase
{
public function testGetHttpClient()
{
$http = new Http();
$client = $http->getHttpClient();
$this->assertInstanceOf(HttpClient::class, $client);
}
}
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
require_once dirname(dirname(__FILE__)) . '/vendor/autoload.php';

require_once __DIR__ . '/../src/ClassMap/InteractWithHttpClient.php';
8 changes: 0 additions & 8 deletions tests/ci.ini

This file was deleted.

10 changes: 0 additions & 10 deletions tests/swoole.install.sh

This file was deleted.

0 comments on commit 0b7f677

Please sign in to comment.