diff --git a/composer.json b/composer.json index 1a454a4..ba24e60 100755 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/phpunit.xml b/phpunit.xml index b4d7686..e1c18f1 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,16 +1,20 @@ - - - - ./app - - + + ./tests - \ No newline at end of file + + + ./app + + + diff --git a/tests/Api/ExampleTest.php b/tests/Api/ExampleTest.php deleted file mode 100644 index f3cef58..0000000 --- a/tests/Api/ExampleTest.php +++ /dev/null @@ -1,28 +0,0 @@ -assertTrue(true); - $this->assertTrue(is_array($this->get('/'))); - } -} diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php new file mode 100644 index 0000000..61cd84c --- /dev/null +++ b/tests/Feature/ExampleTest.php @@ -0,0 +1,5 @@ +toBeTrue(); +}); diff --git a/tests/HttpTestCase.php b/tests/HttpTestCase.php index c7a61b3..d38358a 100644 --- a/tests/HttpTestCase.php +++ b/tests/HttpTestCase.php @@ -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 $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 $arguments - * @return array - */ - 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); } } diff --git a/tests/Pest.php b/tests/Pest.php index f788733..fffbbf0 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -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() +// { +// // .. +// } diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php new file mode 100644 index 0000000..61cd84c --- /dev/null +++ b/tests/Unit/ExampleTest.php @@ -0,0 +1,5 @@ +toBeTrue(); +});