From 6aa5b867c38490acadc8513aa01f7750d5df988f Mon Sep 17 00:00:00 2001 From: Mike Date: Fri, 17 Jul 2020 02:51:43 +0800 Subject: [PATCH] init --- .env.example | 17 ++++ .gitignore | 13 +++ .gitlab-ci.yml | 57 ++++++++++++ .php_cs | 91 +++++++++++++++++++ .phpstorm.meta.php | 11 +++ Dockerfile | 61 +++++++++++++ README.md | 36 ++++++++ app/Constants/ErrorCode.php | 26 ++++++ app/Controller/AbstractController.php | 38 ++++++++ app/Controller/CouponController.php | 26 ++++++ app/Controller/IndexController.php | 26 ++++++ app/Exception/BusinessException.php | 28 ++++++ app/Exception/Handler/AppExceptionHandler.php | 43 +++++++++ app/Listener/DbQueryExecutedListener.php | 61 +++++++++++++ app/Model/Coupon.php | 11 +++ app/Model/CouponRec.php | 16 ++++ app/Model/CouponUserRecType.php | 15 +++ app/Model/Model.php | 21 +++++ bin/hyperf.php | 23 +++++ composer.json | 73 +++++++++++++++ config/autoload/annotations.php | 21 +++++ config/autoload/aspects.php | 13 +++ config/autoload/cache.php | 18 ++++ config/autoload/commands.php | 13 +++ config/autoload/databases.php | 47 ++++++++++ config/autoload/dependencies.php | 13 +++ config/autoload/devtool.php | 44 +++++++++ config/autoload/exceptions.php | 19 ++++ config/autoload/listeners.php | 13 +++ config/autoload/logger.php | 30 ++++++ config/autoload/middlewares.php | 15 +++ config/autoload/processes.php | 13 +++ config/autoload/redis.php | 27 ++++++ config/autoload/server.php | 45 +++++++++ config/config.php | 31 +++++++ config/container.php | 24 +++++ config/routes.php | 14 +++ deploy.test.yml | 30 ++++++ phpstan.neon | 8 ++ phpunit.xml | 21 +++++ test/Cases/ExampleTest.php | 27 ++++++ test/HttpTestCase.php | 41 +++++++++ test/bootstrap.php | 29 ++++++ 43 files changed, 1249 insertions(+) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 .gitlab-ci.yml create mode 100644 .php_cs create mode 100644 .phpstorm.meta.php create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 app/Constants/ErrorCode.php create mode 100644 app/Controller/AbstractController.php create mode 100644 app/Controller/CouponController.php create mode 100644 app/Controller/IndexController.php create mode 100644 app/Exception/BusinessException.php create mode 100644 app/Exception/Handler/AppExceptionHandler.php create mode 100644 app/Listener/DbQueryExecutedListener.php create mode 100644 app/Model/Coupon.php create mode 100644 app/Model/CouponRec.php create mode 100644 app/Model/CouponUserRecType.php create mode 100644 app/Model/Model.php create mode 100644 bin/hyperf.php create mode 100644 composer.json create mode 100644 config/autoload/annotations.php create mode 100644 config/autoload/aspects.php create mode 100644 config/autoload/cache.php create mode 100644 config/autoload/commands.php create mode 100644 config/autoload/databases.php create mode 100644 config/autoload/dependencies.php create mode 100644 config/autoload/devtool.php create mode 100644 config/autoload/exceptions.php create mode 100644 config/autoload/listeners.php create mode 100644 config/autoload/logger.php create mode 100644 config/autoload/middlewares.php create mode 100644 config/autoload/processes.php create mode 100644 config/autoload/redis.php create mode 100644 config/autoload/server.php create mode 100644 config/config.php create mode 100644 config/container.php create mode 100644 config/routes.php create mode 100644 deploy.test.yml create mode 100644 phpstan.neon create mode 100644 phpunit.xml create mode 100644 test/Cases/ExampleTest.php create mode 100644 test/HttpTestCase.php create mode 100644 test/bootstrap.php diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..6879583 --- /dev/null +++ b/.env.example @@ -0,0 +1,17 @@ +APP_NAME=skeleton +APP_ENV=dev + +DB_DRIVER=mysql +DB_HOST=localhost +DB_PORT=3306 +DB_DATABASE=hyperf +DB_USERNAME=root +DB_PASSWORD= +DB_CHARSET=utf8mb4 +DB_COLLATION=utf8mb4_unicode_ci +DB_PREFIX= + +REDIS_HOST=localhost +REDIS_AUTH=(null) +REDIS_PORT=6379 +REDIS_DB=0 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c867e8f --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +.buildpath +.settings/ +.project +*.patch +.idea/ +.git/ +runtime/ +vendor/ +.phpintel/ +.env +.DS_Store +*.lock +.phpunit* \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..a5fccae --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,57 @@ +# usermod -aG docker gitlab-runner + +stages: + - build + - deploy + +variables: + PROJECT_NAME: hyperf + REGISTRY_URL: registry-docker.org + +build_test_docker: + stage: build + before_script: +# - git submodule sync --recursive +# - git submodule update --init --recursive + script: + - docker build . -t $PROJECT_NAME + - docker tag $PROJECT_NAME $REGISTRY_URL/$PROJECT_NAME:test + - docker push $REGISTRY_URL/$PROJECT_NAME:test + only: + - test + tags: + - builder + +deploy_test_docker: + stage: deploy + script: + - docker stack deploy -c deploy.test.yml --with-registry-auth $PROJECT_NAME + only: + - test + tags: + - test + +build_docker: + stage: build + before_script: +# - git submodule sync --recursive +# - git submodule update --init --recursive + script: + - docker build . -t $PROJECT_NAME + - docker tag $PROJECT_NAME $REGISTRY_URL/$PROJECT_NAME:$CI_COMMIT_REF_NAME + - docker tag $PROJECT_NAME $REGISTRY_URL/$PROJECT_NAME:latest + - docker push $REGISTRY_URL/$PROJECT_NAME:$CI_COMMIT_REF_NAME + - docker push $REGISTRY_URL/$PROJECT_NAME:latest + only: + - tags + tags: + - builder + +deploy_docker: + stage: deploy + script: + - echo SUCCESS + only: + - tags + tags: + - builder diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..3a4e511 --- /dev/null +++ b/.php_cs @@ -0,0 +1,91 @@ +setRiskyAllowed(true) + ->setRules([ + '@PSR2' => true, + '@Symfony' => true, + '@DoctrineAnnotation' => true, + '@PhpCsFixer' => true, + 'header_comment' => [ + 'commentType' => 'PHPDoc', + 'header' => $header, + 'separate' => 'none', + 'location' => 'after_declare_strict', + ], + 'array_syntax' => [ + 'syntax' => 'short' + ], + 'list_syntax' => [ + 'syntax' => 'short' + ], + 'concat_space' => [ + 'spacing' => 'one' + ], + 'blank_line_before_statement' => [ + 'statements' => [ + 'declare', + ], + ], + 'general_phpdoc_annotation_remove' => [ + 'annotations' => [ + 'author' + ], + ], + 'ordered_imports' => [ + 'imports_order' => [ + 'class', 'function', 'const', + ], + 'sort_algorithm' => 'alpha', + ], + 'single_line_comment_style' => [ + 'comment_types' => [ + ], + ], + 'yoda_style' => [ + 'always_move_variable' => false, + 'equal' => false, + 'identical' => false, + ], + 'phpdoc_align' => [ + 'align' => 'left', + ], + 'multiline_whitespace_before_semicolons' => [ + 'strategy' => 'no_multi_line', + ], + 'constant_case' => [ + 'case' => 'lower', + ], + 'class_attributes_separation' => true, + 'combine_consecutive_unsets' => true, + 'declare_strict_types' => true, + 'linebreak_after_opening_tag' => true, + 'lowercase_static_reference' => true, + 'no_useless_else' => true, + 'no_unused_imports' => true, + 'not_operator_with_successor_space' => true, + 'not_operator_with_space' => false, + 'ordered_class_elements' => true, + 'php_unit_strict' => false, + 'phpdoc_separation' => false, + 'single_quote' => true, + 'standardize_not_equals' => true, + 'multiline_comment_opening_closing' => true, + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->exclude('public') + ->exclude('runtime') + ->exclude('vendor') + ->in(__DIR__) + ) + ->setUsingCache(false); diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php new file mode 100644 index 0000000..5ba7d5f --- /dev/null +++ b/.phpstorm.meta.php @@ -0,0 +1,11 @@ +" version="1.0" license="MIT" app.name="Hyperf" + +## +# ---------- env settings ---------- +## +# --build-arg timezone=Asia/Shanghai +ARG timezone + +ENV TIMEZONE=${timezone:-"Asia/Shanghai"} \ + COMPOSER_VERSION=1.9.1 \ + APP_ENV=prod \ + SCAN_CACHEABLE=(true) + +# update +RUN set -ex \ + && apk update \ + # install composer + && cd /tmp \ + && wget https://github.com/composer/composer/releases/download/${COMPOSER_VERSION}/composer.phar \ + && chmod u+x composer.phar \ + && mv composer.phar /usr/local/bin/composer \ + # show php version and extensions + && php -v \ + && php -m \ + && php --ri swoole \ + # ---------- some config ---------- + && cd /etc/php7 \ + # - config PHP + && { \ + echo "upload_max_filesize=100M"; \ + echo "post_max_size=108M"; \ + echo "memory_limit=1024M"; \ + echo "date.timezone=${TIMEZONE}"; \ + } | tee conf.d/99_overrides.ini \ + # - config timezone + && ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \ + && echo "${TIMEZONE}" > /etc/timezone \ + # ---------- clear works ---------- + && rm -rf /var/cache/apk/* /tmp/* /usr/share/man \ + && echo -e "\033[42;37m Build Completed :).\033[0m\n" + +WORKDIR /opt/www + +# Composer Cache +# COPY ./composer.* /opt/www/ +# RUN composer install --no-dev --no-scripts + +COPY . /opt/www +RUN composer install --no-dev -o && php bin/hyperf.php + +EXPOSE 9501 + +ENTRYPOINT ["php", "/opt/www/bin/hyperf.php", "start"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..0d858eb --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# Introduction + +This is a skeleton application using the Hyperf framework. This application is meant to be used as a starting place for those looking to get their feet wet with Hyperf Framework. + +# Requirements + +Hyperf has some requirements for the system environment, it can only run under Linux and Mac environment, but due to the development of Docker virtualization technology, Docker for Windows can also be used as the running environment under Windows. + +The various versions of Dockerfile have been prepared for you in the [hyperf\hyperf-docker](https://github.com/hyperf/hyperf-docker) project, or directly based on the already built [hyperf\hyperf](https://hub.docker.com/r/hyperf/hyperf) Image to run. + +When you don't want to use Docker as the basis for your running environment, you need to make sure that your operating environment meets the following requirements: + + - PHP >= 7.2 + - Swoole PHP extension >= 4.4,and Disabled `Short Name` + - OpenSSL PHP extension + - JSON PHP extension + - PDO PHP extension (If you need to use MySQL Client) + - Redis PHP extension (If you need to use Redis Client) + - Protobuf PHP extension (If you need to use gRPC Server of Client) + +# Installation using Composer + +The easiest way to create a new Hyperf project is to use Composer. If you don't have it already installed, then please install as per the documentation. + +To create your new Hyperf project: + +$ composer create-project hyperf/hyperf-skeleton path/to/install + +Once installed, you can run the server immediately using the command below. + +$ cd path/to/install +$ php bin/hyperf.php start + +This will start the cli-server on port `9501`, and bind it to all network interfaces. You can then visit the site at `http://localhost:9501/` + +which will bring up Hyperf default home page. diff --git a/app/Constants/ErrorCode.php b/app/Constants/ErrorCode.php new file mode 100644 index 0000000..0651e85 --- /dev/null +++ b/app/Constants/ErrorCode.php @@ -0,0 +1,26 @@ +request->input('user', 'Hyperf'); + $method = $this->request->getMethod(); + + return [ + 'method' => $method, + 'message' => "Hello {$user}.", + ]; + } +} diff --git a/app/Controller/IndexController.php b/app/Controller/IndexController.php new file mode 100644 index 0000000..60c3235 --- /dev/null +++ b/app/Controller/IndexController.php @@ -0,0 +1,26 @@ +request->input('user', 'Hyperf'); + $method = $this->request->getMethod(); + + return [ + 'method' => $method, + 'message' => "Hello {$user}.", + ]; + } +} diff --git a/app/Exception/BusinessException.php b/app/Exception/BusinessException.php new file mode 100644 index 0000000..7380502 --- /dev/null +++ b/app/Exception/BusinessException.php @@ -0,0 +1,28 @@ +logger = $logger; + } + + public function handle(Throwable $throwable, ResponseInterface $response) + { + $this->logger->error(sprintf('%s[%s] in %s', $throwable->getMessage(), $throwable->getLine(), $throwable->getFile())); + $this->logger->error($throwable->getTraceAsString()); + return $response->withHeader('Server', 'Hyperf')->withStatus(500)->withBody(new SwooleStream('Internal Server Error.')); + } + + public function isValid(Throwable $throwable): bool + { + return true; + } +} diff --git a/app/Listener/DbQueryExecutedListener.php b/app/Listener/DbQueryExecutedListener.php new file mode 100644 index 0000000..8999902 --- /dev/null +++ b/app/Listener/DbQueryExecutedListener.php @@ -0,0 +1,61 @@ +logger = $container->get(LoggerFactory::class)->get('sql'); + } + + public function listen(): array + { + return [ + QueryExecuted::class, + ]; + } + + /** + * @param QueryExecuted $event + */ + public function process(object $event) + { + if ($event instanceof QueryExecuted) { + $sql = $event->sql; + if (! Arr::isAssoc($event->bindings)) { + foreach ($event->bindings as $key => $value) { + $sql = Str::replaceFirst('?', "'{$value}'", $sql); + } + } + + $this->logger->info(sprintf('[%s] %s', $event->time, $sql)); + } + } +} diff --git a/app/Model/Coupon.php b/app/Model/Coupon.php new file mode 100644 index 0000000..90e550b --- /dev/null +++ b/app/Model/Coupon.php @@ -0,0 +1,11 @@ +hasOne('App\Models\CouponUser','id','system_coupon_user_id'); + } +} diff --git a/app/Model/CouponUserRecType.php b/app/Model/CouponUserRecType.php new file mode 100644 index 0000000..0617260 --- /dev/null +++ b/app/Model/CouponUserRecType.php @@ -0,0 +1,15 @@ +hasOne('App\Models\CouponUser','id','system_coupon_user_id'); + } +} diff --git a/app/Model/Model.php b/app/Model/Model.php new file mode 100644 index 0000000..82ebdb5 --- /dev/null +++ b/app/Model/Model.php @@ -0,0 +1,21 @@ +get(\Hyperf\Contract\ApplicationInterface::class); + $application->run(); +})(); diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..f16fdd1 --- /dev/null +++ b/composer.json @@ -0,0 +1,73 @@ +{ + "name": "hyperf/hyperf-skeleton", + "type": "project", + "keywords": [ + "php", + "swoole", + "framework", + "hyperf", + "microservice", + "middleware" + ], + "description": "A coroutine framework that focuses on hyperspeed and flexible, specifically use for build microservices and middlewares.", + "license": "Apache-2.0", + "require": { + "php": ">=7.2", + "ext-swoole": ">=4.5", + "hyperf/cache": "~2.0.0", + "hyperf/command": "~2.0.0", + "hyperf/config": "~2.0.0", + "hyperf/db-connection": "~2.0.0", + "hyperf/framework": "~2.0.0", + "hyperf/guzzle": "~2.0.0", + "hyperf/http-server": "~2.0.0", + "hyperf/logger": "~2.0.0", + "hyperf/memory": "~2.0.0", + "hyperf/process": "~2.0.0", + "hyperf/redis": "~2.0.0", + "hyperf/constants": "~2.0.0", + "hyperf/model-cache": "~2.0.0" + }, + "require-dev": { + "swoole/ide-helper": "^4.5", + "friendsofphp/php-cs-fixer": "^2.14", + "mockery/mockery": "^1.0", + "doctrine/common": "^2.9", + "phpstan/phpstan": "^0.12", + "hyperf/devtool": "~2.0.0", + "hyperf/testing": "~2.0.0" + }, + "suggest": { + "ext-openssl": "Required to use HTTPS.", + "ext-json": "Required to use JSON.", + "ext-pdo": "Required to use MySQL Client.", + "ext-pdo_mysql": "Required to use MySQL Client.", + "ext-redis": "Required to use Redis Client." + }, + "autoload": { + "psr-4": { + "App\\": "app/" + }, + "files": [] + }, + "autoload-dev": { + "psr-4": { + "HyperfTest\\": "./test/" + } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "extra": [], + "scripts": { + "post-root-package-install": [ + "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" + ], + "post-autoload-dump": [ + "rm -rf runtime/container" + ], + "test": "co-phpunit -c phpunit.xml --colors=always", + "cs-fix": "php-cs-fixer fix $1", + "analyse": "phpstan analyse --memory-limit 300M -l 0 -c phpstan.neon ./app ./config", + "start": "php ./bin/hyperf.php start" + } +} diff --git a/config/autoload/annotations.php b/config/autoload/annotations.php new file mode 100644 index 0000000..1e2f0b4 --- /dev/null +++ b/config/autoload/annotations.php @@ -0,0 +1,21 @@ + [ + 'paths' => [ + BASE_PATH . '/app', + ], + 'ignore_annotations' => [ + 'mixin', + ], + ], +]; diff --git a/config/autoload/aspects.php b/config/autoload/aspects.php new file mode 100644 index 0000000..55b80d5 --- /dev/null +++ b/config/autoload/aspects.php @@ -0,0 +1,13 @@ + [ + 'driver' => Hyperf\Cache\Driver\RedisDriver::class, + 'packer' => Hyperf\Utils\Packer\PhpSerializerPacker::class, + 'prefix' => 'c:', + ], +]; diff --git a/config/autoload/commands.php b/config/autoload/commands.php new file mode 100644 index 0000000..55b80d5 --- /dev/null +++ b/config/autoload/commands.php @@ -0,0 +1,13 @@ + [ + 'driver' => env('DB_DRIVER', 'mysql'), + 'host' => env('DB_HOST', 'localhost'), + 'port' => env('DB_PORT', 3306), + 'database' => env('DB_DATABASE', 'hyperf'), + 'username' => env('DB_USERNAME', 'root'), + 'password' => env('DB_PASSWORD', ''), + 'charset' => env('DB_CHARSET', 'utf8'), + 'collation' => env('DB_COLLATION', 'utf8_unicode_ci'), + 'prefix' => env('DB_PREFIX', ''), + 'pool' => [ + 'min_connections' => 1, + 'max_connections' => 10, + 'connect_timeout' => 10.0, + 'wait_timeout' => 3.0, + 'heartbeat' => -1, + 'max_idle_time' => (float) env('DB_MAX_IDLE_TIME', 60), + ], + 'cache' => [ + 'handler' => Hyperf\ModelCache\Handler\RedisHandler::class, + 'cache_key' => 'mc:%s:m:%s:%s:%s', + 'prefix' => 'default', + 'ttl' => 3600 * 24, + 'empty_model_ttl' => 600, + 'load_script' => true, + ], + 'commands' => [ + 'gen:model' => [ + 'path' => 'app/Model', + 'force_casts' => true, + 'inheritance' => 'Model', + ], + ], + ], +]; diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php new file mode 100644 index 0000000..55b80d5 --- /dev/null +++ b/config/autoload/dependencies.php @@ -0,0 +1,13 @@ + [ + 'amqp' => [ + 'consumer' => [ + 'namespace' => 'App\\Amqp\\Consumer', + ], + 'producer' => [ + 'namespace' => 'App\\Amqp\\Producer', + ], + ], + 'aspect' => [ + 'namespace' => 'App\\Aspect', + ], + 'command' => [ + 'namespace' => 'App\\Command', + ], + 'controller' => [ + 'namespace' => 'App\\Controller', + ], + 'job' => [ + 'namespace' => 'App\\Job', + ], + 'listener' => [ + 'namespace' => 'App\\Listener', + ], + 'middleware' => [ + 'namespace' => 'App\\Middleware', + ], + 'Process' => [ + 'namespace' => 'App\\Processes', + ], + ], +]; diff --git a/config/autoload/exceptions.php b/config/autoload/exceptions.php new file mode 100644 index 0000000..895bda9 --- /dev/null +++ b/config/autoload/exceptions.php @@ -0,0 +1,19 @@ + [ + 'http' => [ + Hyperf\HttpServer\Exception\Handler\HttpExceptionHandler::class, + App\Exception\Handler\AppExceptionHandler::class, + ], + ], +]; diff --git a/config/autoload/listeners.php b/config/autoload/listeners.php new file mode 100644 index 0000000..55b80d5 --- /dev/null +++ b/config/autoload/listeners.php @@ -0,0 +1,13 @@ + [ + 'handler' => [ + 'class' => Monolog\Handler\StreamHandler::class, + 'constructor' => [ + 'stream' => BASE_PATH . '/runtime/logs/hyperf.log', + 'level' => Monolog\Logger::DEBUG, + ], + ], + 'formatter' => [ + 'class' => Monolog\Formatter\LineFormatter::class, + 'constructor' => [ + 'format' => null, + 'dateFormat' => 'Y-m-d H:i:s', + 'allowInlineLineBreaks' => true, + ], + ], + ], +]; diff --git a/config/autoload/middlewares.php b/config/autoload/middlewares.php new file mode 100644 index 0000000..81b1887 --- /dev/null +++ b/config/autoload/middlewares.php @@ -0,0 +1,15 @@ + [ + ], +]; diff --git a/config/autoload/processes.php b/config/autoload/processes.php new file mode 100644 index 0000000..55b80d5 --- /dev/null +++ b/config/autoload/processes.php @@ -0,0 +1,13 @@ + [ + 'host' => env('REDIS_HOST', 'localhost'), + 'auth' => env('REDIS_AUTH', null), + 'port' => (int) env('REDIS_PORT', 6379), + 'db' => (int) env('REDIS_DB', 0), + 'pool' => [ + 'min_connections' => 1, + 'max_connections' => 10, + 'connect_timeout' => 10.0, + 'wait_timeout' => 3.0, + 'heartbeat' => -1, + 'max_idle_time' => (float) env('REDIS_MAX_IDLE_TIME', 60), + ], + ], +]; diff --git a/config/autoload/server.php b/config/autoload/server.php new file mode 100644 index 0000000..d6211cc --- /dev/null +++ b/config/autoload/server.php @@ -0,0 +1,45 @@ + SWOOLE_PROCESS, + 'servers' => [ + [ + 'name' => 'http', + 'type' => Server::SERVER_HTTP, + 'host' => '0.0.0.0', + 'port' => 9501, + 'sock_type' => SWOOLE_SOCK_TCP, + 'callbacks' => [ + SwooleEvent::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'], + ], + ], + ], + 'settings' => [ + 'enable_coroutine' => true, + 'worker_num' => swoole_cpu_num(), + 'pid_file' => BASE_PATH . '/runtime/hyperf.pid', + 'open_tcp_nodelay' => true, + 'max_coroutine' => 100000, + 'open_http2_protocol' => true, + 'max_request' => 100000, + 'socket_buffer_size' => 2 * 1024 * 1024, + 'buffer_output_size' => 2 * 1024 * 1024, + ], + 'callbacks' => [ + SwooleEvent::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'], + SwooleEvent::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'], + SwooleEvent::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'], + ], +]; diff --git a/config/config.php b/config/config.php new file mode 100644 index 0000000..7d0c07e --- /dev/null +++ b/config/config.php @@ -0,0 +1,31 @@ + env('APP_NAME', 'skeleton'), + 'app_env' => env('APP_ENV', 'dev'), + 'scan_cacheable' => env('SCAN_CACHEABLE', false), + StdoutLoggerInterface::class => [ + 'log_level' => [ + LogLevel::ALERT, + LogLevel::CRITICAL, + LogLevel::DEBUG, + LogLevel::EMERGENCY, + LogLevel::ERROR, + LogLevel::INFO, + LogLevel::NOTICE, + LogLevel::WARNING, + ], + ], +]; diff --git a/config/container.php b/config/container.php new file mode 100644 index 0000000..aab53b5 --- /dev/null +++ b/config/container.php @@ -0,0 +1,24 @@ + + + + + ./test + + + + + ./app + + + diff --git a/test/Cases/ExampleTest.php b/test/Cases/ExampleTest.php new file mode 100644 index 0000000..1c8d028 --- /dev/null +++ b/test/Cases/ExampleTest.php @@ -0,0 +1,27 @@ +assertTrue(true); + $this->assertTrue(is_array($this->get('/'))); + } +} diff --git a/test/HttpTestCase.php b/test/HttpTestCase.php new file mode 100644 index 0000000..d22b243 --- /dev/null +++ b/test/HttpTestCase.php @@ -0,0 +1,41 @@ +client = make(Client::class); + } + + public function __call($name, $arguments) + { + return $this->client->{$name}(...$arguments); + } +} diff --git a/test/bootstrap.php b/test/bootstrap.php new file mode 100644 index 0000000..7fdee84 --- /dev/null +++ b/test/bootstrap.php @@ -0,0 +1,29 @@ +get(Hyperf\Contract\ApplicationInterface::class);