mirror of
http://124.126.16.154:8888/singularity/composer-template.git
synced 2026-01-15 00:35:08 +08:00
build: 引入 pest
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -5,4 +5,5 @@
|
|||||||
# Build Dists
|
# Build Dists
|
||||||
vendor/
|
vendor/
|
||||||
composer.phar
|
composer.phar
|
||||||
.phpunit.result.cache
|
.phpunit.result.cache
|
||||||
|
runtime/
|
||||||
@@ -32,32 +32,39 @@
|
|||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Singularity\\HDK\\Test\\Boilerplate\\": "tests/"
|
"Tests\\": "tests/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.0",
|
"php": "^8.0",
|
||||||
"composer/composer": ">=2.0",
|
"composer/composer": ">=2.0",
|
||||||
"singularity/hdk-core": "^0.2.9",
|
"singularity/hdk-core": "^1.0.0",
|
||||||
"symfony/polyfill-php81": "^1.27"
|
"symfony/polyfill-php81": "^1.27",
|
||||||
|
"symfony/polyfill-php82": "^1.27"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"brainmaestro/composer-git-hooks": "^2.8",
|
"brainmaestro/composer-git-hooks": "^2.8",
|
||||||
|
"cooper/hyperf-pest": "^1.1",
|
||||||
"friendsofphp/php-cs-fixer": "^3.0",
|
"friendsofphp/php-cs-fixer": "^3.0",
|
||||||
"hyperf/devtool": "3.0.*",
|
"hyperf/devtool": "~3.0.37",
|
||||||
"hyperf/testing": "3.0.*",
|
"hyperf/testing": "~3.0.38",
|
||||||
"phpstan/phpstan": "^1.10.6",
|
"phpstan/phpstan": "^1.10.6",
|
||||||
"swoole/ide-helper": "^4.8.12"
|
"swoole/ide-helper": "^4.8.12"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"singularity/hdk-auth": "用户、鉴权相关逻辑必需",
|
"singularity/hdk-auth": "用户、鉴权相关逻辑必需",
|
||||||
"singularity/hyperf-saml": "接入单点登录必需"
|
"singularity/hyperf-saml": "接入单点登录必需",
|
||||||
|
"singularity/hdk-pay": "接入支付平台必需"
|
||||||
},
|
},
|
||||||
"prefer-stable": true,
|
"prefer-stable": true,
|
||||||
|
"minimum-stability": "dev",
|
||||||
"config": {
|
"config": {
|
||||||
"optimize-autoloader": true,
|
"optimize-autoloader": true,
|
||||||
"sort-packages": true,
|
"sort-packages": true,
|
||||||
"secure-http": false
|
"secure-http": false,
|
||||||
|
"allow-plugins": {
|
||||||
|
"pestphp/pest-plugin": true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"post-root-package-install": [
|
"post-root-package-install": [
|
||||||
@@ -66,10 +73,10 @@
|
|||||||
"test": [
|
"test": [
|
||||||
"rm -rf runtime",
|
"rm -rf runtime",
|
||||||
"Composer\\Config::disableProcessTimeout",
|
"Composer\\Config::disableProcessTimeout",
|
||||||
"co-phpunit --prepend tests/bootstrap.php -c phpunit.xml --colors=always"
|
"co-pest --prepend tests/bootstrap.php -c phpunit.xml --colors=always $1"
|
||||||
],
|
],
|
||||||
"cs-fix": "vendor/bin/php-cs-fixer fix $1 --rules=@PSR12 --allow-risky=yes",
|
"cs-fix": "php-cs-fixer fix $1 --rules=@PSR12 --allow-risky=yes",
|
||||||
"analyse": "vendor/bin/phpstan analyse $1",
|
"analyse": "phpstan analyse $1",
|
||||||
"ci": [
|
"ci": [
|
||||||
"@analyse publish/ src/ tests/",
|
"@analyse publish/ src/ tests/",
|
||||||
"@cs-fix",
|
"@cs-fix",
|
||||||
@@ -85,14 +92,6 @@
|
|||||||
"packagist": {
|
"packagist": {
|
||||||
"type": "composer",
|
"type": "composer",
|
||||||
"url": "https://mirrors.aliyun.com/composer/"
|
"url": "https://mirrors.aliyun.com/composer/"
|
||||||
},
|
|
||||||
"packagist-tx": {
|
|
||||||
"type": "composer",
|
|
||||||
"url": "https://mirrors.cloud.tencent.com/composer/"
|
|
||||||
},
|
|
||||||
"packagist-hw": {
|
|
||||||
"type": "composer",
|
|
||||||
"url": "https://repo.huaweicloud.com/repository/php/"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version": "0.2.2"
|
"version": "0.2.2"
|
||||||
|
|||||||
5497
composer.lock
generated
5497
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@ parameters:
|
|||||||
paths:
|
paths:
|
||||||
- publish
|
- publish
|
||||||
- src
|
- src
|
||||||
- testsi
|
- tests
|
||||||
ignoreErrors:
|
ignoreErrors:
|
||||||
- '#Constant BASE_PATH not found#'
|
- '#Constant BASE_PATH not found#'
|
||||||
- '#Property [a-zA-Z0-9\\_]+::\$[a-zA-Z0-9]+ is never written, only read\.#'
|
- '#Property [a-zA-Z0-9\\_]+::\$[a-zA-Z0-9]+ is never written, only read\.#'
|
||||||
|
|||||||
15
phpunit.xml
15
phpunit.xml
@@ -1,9 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd">
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false"
|
||||||
<coverage/>
|
colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd">
|
||||||
<testsuites>
|
<coverage/>
|
||||||
<testsuite name="Example">
|
<testsuites>
|
||||||
<directory>./tests/Example/</directory>
|
<testsuite name="Tests">
|
||||||
</testsuite>
|
<directory>./tests</directory>
|
||||||
</testsuites>
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
docker login harbor.luxcreo.cn -u php -p fTr6oVvqqdzVlYgnZhRPPAP54u7SmqGA
|
|
||||||
|
|
||||||
image_name=harbor.luxcreo.cn/php/hdk-boilerplate
|
|
||||||
docker build --tag $image_name .
|
|
||||||
|
|
||||||
#docker push $image_name
|
|
||||||
#docker push ${image_name}-dev
|
|
||||||
55
tests/HttpTestCase.php
Normal file
55
tests/HttpTestCase.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?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 Tests;
|
||||||
|
|
||||||
|
use Hyperf\Testing\Client;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
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 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 = '')
|
||||||
|
{
|
||||||
|
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
|
||||||
|
{
|
||||||
|
return $this->client->{$name}(...$arguments);
|
||||||
|
}
|
||||||
|
}
|
||||||
32
tests/Pest.php
Normal file
32
tests/Pest.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Test Case
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
|
||||||
|
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
|
||||||
|
| need to change it using the "uses()" function to bind a different classes or traits.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Tests\HttpTestCase;
|
||||||
|
|
||||||
|
// uses(HttpTestCase::class)->in('Api');
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Functions
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
|
||||||
|
| project that you don't want to repeat in every file. Here you can also expose helpers as
|
||||||
|
| global functions to help you to reduce the number of lines of code in your test files.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*function something()
|
||||||
|
{
|
||||||
|
// ..
|
||||||
|
}*/
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Singularity\HDK\Test\Boilerplate\Example;
|
namespace Tests\Unit;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Singularity\HDK\Boilerplate\Example\Greeting;
|
use Singularity\HDK\Boilerplate\Example\Greeting;
|
||||||
@@ -9,8 +9,29 @@ declare(strict_types=1);
|
|||||||
* @contact group@hyperf.io
|
* @contact group@hyperf.io
|
||||||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
* @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_errors', 'on');
|
||||||
ini_set('display_startup_errors', 'on');
|
ini_set('display_startup_errors', 'on');
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
date_default_timezone_set('Asia/Shanghai');
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user