build(composer): 更新到 hyperf3.1 和 pest2

Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
This commit is contained in:
李东云
2023-12-18 15:46:04 +08:00
parent 047867cbf5
commit e67c7aa2ea
7 changed files with 95 additions and 85 deletions

View File

@@ -33,34 +33,34 @@
},
"autoload-dev": {
"psr-4": {
"Test\\": "tests/"
"Tests\\": "tests/"
}
},
"require": {
"php": "^8.2",
"composer/composer": ">=2.6.4",
"hyperf/constants": "~3.0.37",
"hyperf/db-connection": "~3.0.37",
"hyperf/di": "~3.0.37",
"hyperf/paginator": "~3.0.37",
"hyperf/session": "~3.0.37",
"hyperf/translation": "~3.0.37",
"hyperf/validation": "~3.0.37",
"composer/composer": ">=2.6.5",
"hyperf/constants": "~3.1.0",
"hyperf/db-connection": "~3.1.0",
"hyperf/di": "~3.1.0",
"hyperf/framework": "~3.1.0",
"hyperf/paginator": "~3.1.2",
"hyperf/session": "~3.1.0",
"hyperf/translation": "~3.1.0",
"hyperf/validation": "~3.1.0",
"singularity/hdk-core": "^1.0.0",
"symfony/polyfill-php81": "^1.28.0",
"symfony/polyfill-php82": "^1.28.0"
"symfony/polyfill-php83": "^1.28.0"
},
"require-dev": {
"brainmaestro/composer-git-hooks": "^2.8.5",
"cooper/hyperf-pest": "^1.1.0",
"daodao97/hyperf-watch": "dev-master",
"friendsofphp/php-cs-fixer": "^3.35.1",
"hyperf/devtool": "~3.0.37",
"hyperf/testing": "~3.0.38",
"brainmaestro/composer-git-hooks": "^3.0.0",
"friendsofhyperf/pest-plugin-hyperf": "~3.1.1",
"friendsofphp/php-cs-fixer": "^3.41.1",
"hyperf/devtool": "~3.1.2",
"hyperf/testing": "~3.1.0",
"mockery/mockery": "^1.6.6",
"phpstan/phpstan": "^1.10.37",
"phpstan/phpstan": "^1.10.49",
"rector/rector": "^0.15.25",
"roave/security-advisories": "dev-latest",
"swoole/ide-helper": "^5.0.3"
"swoole/ide-helper": "^5.1.1"
},
"prefer-stable": true,
"minimum-stability": "alpha",
@@ -85,7 +85,7 @@
"test": [
"rm -rf runtime",
"Composer\\Config::disableProcessTimeout",
"APP_STATUS=false co-pest --prepend tests/bootstrap.php -c phpunit.xml --colors=always $1"
"APP_STATUS=false pest --coroutine --prepend=tests/bootstrap.php --colors=always $1"
],
"cs-fix": "php-cs-fixer fix $1 --rules=@PSR12 --allow-risky=yes",
"analyse": "phpstan analyse $1",

View File

@@ -1,16 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="./tests/bootstrap.php"
colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./app</directory>
</include>
</coverage>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="./tests/bootstrap.php"
colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd"
cacheDirectory=".phpunit.cache"
>
<coverage/>
<testsuites>
<testsuite name="Tests">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>
<source>
<include>
<directory>./app</directory>
</include>
</source>
</phpunit>

View File

@@ -1,28 +0,0 @@
<?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 Test\Api;
use Test\HttpTestCase;
/**
* @internal
* @coversNothing
*/
class ExampleTest extends HttpTestCase
{
public function testExample(): void
{
$this->assertTrue(true);
$this->assertTrue(is_array($this->get('/')));
}
}

View File

@@ -0,0 +1,5 @@
<?php
test('example', function () {
expect(true)->toBeTrue();
});

View File

@@ -10,46 +10,55 @@ declare(strict_types=1);
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Test;
namespace Tests;
use Hyperf\Testing\Client;
use Lmc\HttpConstants\Header;
use PHPUnit\Framework\TestCase;
use Singularity\HDK\Core\Enumerations\Http\Header\RFCs\RFC7617;
use function Hyperf\Support\make;
/**
* Class HttpTestCase.
* @method get($uri, $data = [], $headers = [])
* @method post($uri, $data = [], $headers = [])
* @method json($uri, $data = [], $headers = [])
* @method file($uri, $data = [], $headers = [])
* @method get($uri, $data = [], $headers = [], $uid = 'TDD_MOCK_PERSONAL_USER_1')
* @method post($uri, $data = [], $headers = [], $uid = 'TDD_MOCK_PERSONAL_USER_1')
* @method put($uri, $data = [], $headers = [], $uid = 'TDD_MOCK_PERSONAL_USER_1')
* @method patch($uri, $data = [], $headers = [], $uid = 'TDD_MOCK_PERSONAL_USER_1')
* @method delete($uri, $data = [], $headers = [], $uid = 'TDD_MOCK_PERSONAL_USER_1')
* @method json($uri, $data = [], $headers = [], $uid = 'TDD_MOCK_PERSONAL_USER_1')
* @method file($uri, $data = [], $headers = [], $uid = 'TDD_MOCK_PERSONAL_USER_1')
* @method request($method, $path, $options = [])
*/
abstract class HttpTestCase extends TestCase
{
/**
* @var Client
*/
protected Client $client;
/**
* @param string|null $name
* @param array<int, mixed> $data
* @param int|string $dataName
*/
public function __construct(?string $name = null, array $data = [], int|string $dataName = '')
public function __construct($name = null, array $data = [], $dataName = '')
{
parent::__construct($name, $data, $dataName);
$this->client = make(Client::class);
}
/**
* @param string $name
* @param array<string, mixed> $arguments
* @return array<string, mixed>
*/
public function __call(string $name, array $arguments): array
public function __call($name, $arguments)
{
return $this->client->{$name}(...$arguments);
$uri = $arguments[0];
$data = $arguments[1] ?? [];
$headers = $arguments[2] ?? [];
$uid = $arguments[3] ?? 'TDD_MOCK_PERSONAL_USER_1';
$headers[Header::ACCEPT] ??= 'application/json';
$headers[Header::AUTHORIZATION] ??= sprintf(
'%s %s',
RFC7617::BASIC,
base64_encode(
sprintf(
'%s:%s',
$uid,
md5($uid . \Hyperf\Config\config('common.token.basic.salt'))
)
)
);
return $this->client->{$name}($uri, $data, $headers);
}
}

View File

@@ -11,9 +11,24 @@
|
*/
use Test\HttpTestCase;
use Tests\HttpTestCase;
uses(HttpTestCase::class);
uses(HttpTestCase::class)->in('Feature');
/*
|--------------------------------------------------------------------------
| Expectations
|--------------------------------------------------------------------------
|
| When you're writing tests, you often need to check that values meet certain conditions. The
| "expect()" function gives you access to a set of "expectations" methods that you can use
| to assert different things. Of course, you may extend the Expectation API at any time.
|
*/
// expect()->extend('toBeOne', function () {
// return $this->toBe(1);
// });
/*
|--------------------------------------------------------------------------
@@ -26,7 +41,7 @@ uses(HttpTestCase::class);
|
*/
/*function something()
{
// ..
}*/
// function something()
// {
// // ..
// }

View File

@@ -0,0 +1,5 @@
<?php
test('example', function () {
expect(true)->toBeTrue();
});