diff --git a/.gitattributes b/.gitattributes index a739380..91e3d90 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,3 +7,5 @@ *.md text eol=lf *.gitattributes text eol=lf *.gitignore text eol=lf +*.php text eol=lf +*.env text eol=lf diff --git a/.github/workflows/build-app-image.yml b/.github/workflows/build-app-image.yml index fefcea1..d77f6a1 100644 --- a/.github/workflows/build-app-image.yml +++ b/.github/workflows/build-app-image.yml @@ -11,10 +11,17 @@ on: inputs: push: description: 'Push Image (true or false)' + type: choice + options: + - "true" + - "false" required: true - default: 'true' run_tests: description: 'Run unit tests (true or false)' + type: choice + options: + - "true" + - "false" required: true default: 'true' diff --git a/.gitignore b/.gitignore index 0eb43ad..eb5195e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,9 @@ node_modules .mysql .phpunit.result.cache TODO + +thunder-tests + +.secrets +.env +ignore.txt diff --git a/.vscode/launch.json b/.vscode/launch.json index 9fa5cd7..78117c6 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -59,6 +59,25 @@ "XDEBUG_MODE": "debug,develop", "XDEBUG_CONFIG": "client_port=${port}" } + }, + { + "name": "PHPUnit Debug (Current file)", + "type": "php", + "request": "launch", + "program": "${workspaceFolder}/vendor/bin/phpunit", + "args": [ + "${file}" + ], + "cwd": "${workspaceFolder}", + "port": 9003, + "runtimeArgs": [ + "-dxdebug.start_with_request=yes" + ], + "env": { + "APP_ENV": "test", + "XDEBUG_MODE": "debug,develop", + "XDEBUG_CONFIG": "client_port=${port}" + } } ] -} \ No newline at end of file +} diff --git a/composer.json b/composer.json index b6a7f17..a047447 100644 --- a/composer.json +++ b/composer.json @@ -8,10 +8,11 @@ "php": ">=8.1", "ext-json": "*", "ext-openssl": "*", + "ext-curl": "*", "byjg/config": "4.9.x-dev", "byjg/anydataset-db": "4.9.x-dev", - "byjg/micro-orm": "4.9.*", - "byjg/authuser": "4.9.*", + "byjg/micro-orm": "4.9.x-dev", + "byjg/authuser": "4.9.x-dev", "byjg/mailwrapper": "4.9.*", "byjg/restserver": "4.9.x-dev", "zircote/swagger-php": "^4.6.1", @@ -35,6 +36,7 @@ "migrate": "Builder\\Scripts::migrate", "codegen": "Builder\\Scripts::codeGenerator", "openapi": "Builder\\Scripts::genOpenApiDocs", + "compile": "composer run openapi && composer run test", "up-local-dev": "docker compose -f docker-compose-dev.yml up -d", "down-local-dev": "docker compose -f docker-compose-dev.yml down", "post-create-project-cmd": "Builder\\PostCreateScript::run" diff --git a/config/config-dev.php b/config/config-dev.php index a93587a..cb8fb48 100644 --- a/config/config-dev.php +++ b/config/config-dev.php @@ -17,7 +17,6 @@ use ByJG\Mail\Wrapper\FakeSenderWrapper; use ByJG\Mail\Wrapper\MailgunApiWrapper; use ByJG\Mail\Wrapper\MailWrapperInterface; -use ByJG\MicroOrm\Literal; use ByJG\RestServer\HttpRequestHandler; use ByJG\RestServer\Middleware\CorsMiddleware; use ByJG\RestServer\OutputProcessor\JsonCleanOutputProcessor; @@ -28,7 +27,7 @@ use RestTemplate\Psr11; use RestTemplate\Repository\DummyHexRepository; use RestTemplate\Repository\DummyRepository; -use RestTemplate\Util\HexUuidLiteral; +use RestTemplate\Repository\UserDefinition as UserDefinitionAlias; return [ @@ -88,7 +87,7 @@ ]]) ->toSingleton(), - UserDefinition::class => DI::bind(UserDefinition::class) + UserDefinition::class => DI::bind(UserDefinitionAlias::class) ->withConstructorArgs( [ 'users', // Table name @@ -96,50 +95,16 @@ UserDefinition::LOGIN_IS_EMAIL, [ // Field name in the User class => Field name in the database - 'userid' => 'userid', - 'name' => 'name', - 'email' => 'email', + 'userid' => 'userid', + 'name' => 'name', + 'email' => 'email', 'username' => 'username', 'password' => 'password', - 'created' => 'created', - 'admin' => 'admin' + 'created' => 'created', + 'admin' => 'admin' ] ] ) - ->withMethodCall("markPropertyAsReadOnly", ["uuid"]) - ->withMethodCall("markPropertyAsReadOnly", ["created"]) - ->withMethodCall("markPropertyAsReadOnly", ["updated"]) - ->withMethodCall("defineGenerateKeyClosure", - [ - function () { - return new Literal("X'" . Psr11::container()->get(DbDriverInterface::class)->getScalar("SELECT hex(uuid_to_bin(uuid()))") . "'"); - } - ] - ) - ->withMethodCall("defineClosureForSelect", [ - "userid", - function ($value, $instance) { - if (!method_exists($instance, 'getUuid')) { - return $value; - } - if (!empty($instance->getUuid())) { - return $instance->getUuid(); - } - return $value; - } - ]) - ->withMethodCall("defineClosureForUpdate", [ - 'userid', - function ($value, $instance) { - if (empty($value)) { - return null; - } - if (!($value instanceof Literal)) { - $value = new HexUuidLiteral($value); - } - return $value; - } - ]) ->toSingleton(), UserPropertiesDefinition::class => DI::bind(UserPropertiesDefinition::class) @@ -149,7 +114,7 @@ function ($value, $instance) { ->withInjectedConstructor() ->toSingleton(), - 'CORS_SERVER_LIST' => function () { + 'CORS_SERVER_LIST' => function () { return preg_split('/,(?![^{}]*})/', Psr11::container()->get('CORS_SERVERS')); }, diff --git a/docs/getting_started_03_create_rest_method.md b/docs/getting_started_03_create_rest_method.md index 6c74e4c..7629c39 100644 --- a/docs/getting_started_03_create_rest_method.md +++ b/docs/getting_started_03_create_rest_method.md @@ -160,6 +160,8 @@ public function putExampleCrudStatus(HttpResponse $response, HttpRequest $reques The last step is to return the result as specified in the OpenAPI attributes. ```php +public function putExampleCrudStatus(HttpResponse $response, HttpRequest $request) +{ ... $response->write([ "result" => "ok" diff --git a/public/app.php b/public/app.php index 20e83ba..6764398 100644 --- a/public/app.php +++ b/public/app.php @@ -2,16 +2,15 @@ require_once __DIR__ . '/../vendor/autoload.php'; -use RestTemplate\Psr11; use ByJG\RestServer\HttpRequestHandler; -use ByJG\RestServer\Middleware\CorsMiddleware; use ByJG\RestServer\Route\OpenApiRouteList; +use RestTemplate\Psr11; class App { public static function run() { - $server = Psr11::container()->get(HttpRequestHandler::class); + $server = Psr11::container()->get(HttpRequestHandler::class); $server->handle(Psr11::container()->get(OpenApiRouteList::class)); } } diff --git a/public/docs/index.html b/public/docs/index.html index 8d2148d..5b384bd 100644 --- a/public/docs/index.html +++ b/public/docs/index.html @@ -3,7 +3,7 @@