diff --git a/.gitignore b/.gitignore index 50b321e..f1b5974 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ vendor composer.lock .phpunit.result.cache +.idea diff --git a/composer.json b/composer.json index edfb044..0a5bb54 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "library", "keywords": ["php","framework", "upf", "utopia", "platform"], "license": "MIT", - "minimum-stability": "stable", + "minimum-stability": "RC", "autoload": { "psr-4": {"Utopia\\Platform\\": "src/Platform"} }, @@ -18,9 +18,10 @@ "php": ">=8.0", "ext-json": "*", "ext-redis": "*", - "utopia-php/framework": "0.33.*", - "utopia-php/cli": "0.15.*", - "utopia-php/queue": "0.7.*" + "utopia-php/servers": "0.1.0", + "utopia-php/framework": "1.0.*", + "utopia-php/cli": "1.0.*", + "utopia-php/queue": "0.8.*" }, "require-dev": { "phpunit/phpunit": "^9.3", diff --git a/composer.lock b/composer.lock index d86cf85..34dc82a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,31 +4,33 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7ffc022983be0297e47b611f24698f7a", + "content-hash": "48f9f61f545288314aa34d4963e7e863", "packages": [ { "name": "utopia-php/cli", - "version": "0.15.0", + "version": "1.0.0-RC1", "source": { "type": "git", "url": "https://github.com/utopia-php/cli.git", - "reference": "ccb7c8125ffe0254fef8f25744bfa376eb7bd0ea" + "reference": "7664161dcdb9b76a3ece0ae2f36a9aca1e548e80" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cli/zipball/ccb7c8125ffe0254fef8f25744bfa376eb7bd0ea", - "reference": "ccb7c8125ffe0254fef8f25744bfa376eb7bd0ea", + "url": "https://api.github.com/repos/utopia-php/cli/zipball/7664161dcdb9b76a3ece0ae2f36a9aca1e548e80", + "reference": "7664161dcdb9b76a3ece0ae2f36a9aca1e548e80", "shasum": "" }, "require": { "php": ">=7.4", - "utopia-php/framework": "0.*.*" + "utopia-php/di": "0.1.*", + "utopia-php/framework": "1.0.*" }, "require-dev": { "laravel/pint": "1.2.*", + "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^9.3", "squizlabs/php_codesniffer": "^3.6", - "vimeo/psalm": "4.0.1" + "swoole/ide-helper": "4.8.8" }, "type": "library", "autoload": { @@ -51,32 +53,84 @@ ], "support": { "issues": "https://github.com/utopia-php/cli/issues", - "source": "https://github.com/utopia-php/cli/tree/0.15.0" + "source": "https://github.com/utopia-php/cli/tree/1.0.0-RC1" }, - "time": "2023-03-01T05:55:14+00:00" + "time": "2024-08-09T17:35:04+00:00" + }, + { + "name": "utopia-php/di", + "version": "0.1.0", + "source": { + "type": "git", + "url": "https://github.com/utopia-php/di.git", + "reference": "22490c95f7ac3898ed1c33f1b1b5dd577305ee31" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/di/zipball/22490c95f7ac3898ed1c33f1b1b5dd577305ee31", + "reference": "22490c95f7ac3898ed1c33f1b1b5dd577305ee31", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "require-dev": { + "laravel/pint": "^1.2", + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^9.5.25", + "swoole/ide-helper": "4.8.3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Utopia\\": "src/", + "Tests\\E2E\\": "tests/e2e" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A simple and lite library for managing dependency injections", + "keywords": [ + "framework", + "http", + "php", + "upf" + ], + "support": { + "issues": "https://github.com/utopia-php/di/issues", + "source": "https://github.com/utopia-php/di/tree/0.1.0" + }, + "time": "2024-08-08T14:35:19+00:00" }, { "name": "utopia-php/framework", - "version": "0.33.6", + "version": "1.0.0-RC2", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "8fe57da0cecd57e3b17cd395b4a666a24f4c07a6" + "reference": "d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/8fe57da0cecd57e3b17cd395b4a666a24f4c07a6", - "reference": "8fe57da0cecd57e3b17cd395b4a666a24f4c07a6", + "url": "https://api.github.com/repos/utopia-php/http/zipball/d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7", + "reference": "d1e9674dbf33bed03fa53854ec1f2c6e074cf4d7", "shasum": "" }, "require": { - "php": ">=8.0" + "ext-swoole": "*", + "php": ">=8.0", + "utopia-php/servers": "0.1.* " }, "require-dev": { + "ext-xdebug": "*", "laravel/pint": "^1.2", "phpbench/phpbench": "^1.2", "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^9.5.25" + "phpunit/phpunit": "^9.5.25", + "swoole/ide-helper": "4.8.3" }, "type": "library", "autoload": { @@ -88,36 +142,38 @@ "license": [ "MIT" ], - "description": "A simple, light and advanced PHP framework", + "description": "A simple, light and advanced PHP HTTP framework", "keywords": [ "framework", + "http", "php", "upf" ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.33.6" + "source": "https://github.com/utopia-php/http/tree/1.0.0-RC2" }, - "time": "2024-03-21T18:10:57+00:00" + "time": "2024-08-08T14:46:41+00:00" }, { "name": "utopia-php/queue", - "version": "0.7.0", + "version": "0.8.0-RC1", "source": { "type": "git", "url": "https://github.com/utopia-php/queue.git", - "reference": "917565256eb94bcab7246f7a746b1a486813761b" + "reference": "ed85fd26200f07d9b93d18d2fa7f5bbef2984902" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/queue/zipball/917565256eb94bcab7246f7a746b1a486813761b", - "reference": "917565256eb94bcab7246f7a746b1a486813761b", + "url": "https://api.github.com/repos/utopia-php/queue/zipball/ed85fd26200f07d9b93d18d2fa7f5bbef2984902", + "reference": "ed85fd26200f07d9b93d18d2fa7f5bbef2984902", "shasum": "" }, "require": { "php": ">=8.0", - "utopia-php/cli": "0.15.*", - "utopia-php/framework": "0.*.*" + "utopia-php/cli": "1.0.*", + "utopia-php/di": "0.1.*", + "utopia-php/servers": "0.1.*" }, "require-dev": { "laravel/pint": "^0.2.3", @@ -127,6 +183,7 @@ "workerman/workerman": "^4.0" }, "suggest": { + "ext-redis": "Needed to support Redis connections", "ext-swoole": "Needed to support Swoole.", "workerman/workerman": "Needed to support Workerman." }, @@ -157,9 +214,62 @@ ], "support": { "issues": "https://github.com/utopia-php/queue/issues", - "source": "https://github.com/utopia-php/queue/tree/0.7.0" + "source": "https://github.com/utopia-php/queue/tree/0.8.0-RC1" + }, + "time": "2024-09-04T18:19:23+00:00" + }, + { + "name": "utopia-php/servers", + "version": "0.1.0", + "source": { + "type": "git", + "url": "https://github.com/utopia-php/servers.git", + "reference": "7d9e4f364fb1ab1889fb89ca96eb9946467cb09c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/servers/zipball/7d9e4f364fb1ab1889fb89ca96eb9946467cb09c", + "reference": "7d9e4f364fb1ab1889fb89ca96eb9946467cb09c", + "shasum": "" }, - "time": "2024-01-17T19:00:43+00:00" + "require": { + "php": ">=8.0", + "utopia-php/di": "0.1.*" + }, + "require-dev": { + "laravel/pint": "^0.2.3", + "phpstan/phpstan": "^1.8", + "phpunit/phpunit": "^9.5.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Utopia\\Servers\\": "src/Servers" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Team Appwrite", + "email": "team@appwrite.io" + } + ], + "description": "A base library for building Utopia style servers.", + "keywords": [ + "framework", + "php", + "servers", + "upf", + "utopia" + ], + "support": { + "issues": "https://github.com/utopia-php/servers/issues", + "source": "https://github.com/utopia-php/servers/tree/0.1.0" + }, + "time": "2024-08-08T14:31:39+00:00" } ], "packages-dev": [ @@ -301,16 +411,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.11.1", + "version": "1.12.0", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", - "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", "shasum": "" }, "require": { @@ -318,11 +428,12 @@ }, "conflict": { "doctrine/collections": "<1.6.8", - "doctrine/common": "<2.13.3 || >=3,<3.2.2" + "doctrine/common": "<2.13.3 || >=3 <3.2.2" }, "require-dev": { "doctrine/collections": "^1.6.8", "doctrine/common": "^2.13.3 || ^3.2.2", + "phpspec/prophecy": "^1.10", "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" }, "type": "library", @@ -348,7 +459,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" + "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0" }, "funding": [ { @@ -356,20 +467,20 @@ "type": "tidelift" } ], - "time": "2023-03-08T13:26:56+00:00" + "time": "2024-06-12T14:39:25+00:00" }, { "name": "nikic/php-parser", - "version": "v5.0.2", + "version": "v5.1.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13" + "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/139676794dc1e9231bf7bcd123cfc0c99182cb13", - "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/683130c2ff8c2739f4822ff7ac5c873ec529abd1", + "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1", "shasum": "" }, "require": { @@ -380,7 +491,7 @@ }, "require-dev": { "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^9.0" }, "bin": [ "bin/php-parse" @@ -412,9 +523,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.2" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.1.0" }, - "time": "2024-03-05T20:51:40+00:00" + "time": "2024-07-01T20:03:41+00:00" }, { "name": "phar-io/manifest", @@ -536,35 +647,35 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.31", + "version": "9.2.32", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965" + "reference": "85402a822d1ecf1db1096959413d35e1c37cf1a5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/48c34b5d8d983006bd2adc2d0de92963b9155965", - "reference": "48c34b5d8d983006bd2adc2d0de92963b9155965", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/85402a822d1ecf1db1096959413d35e1c37cf1a5", + "reference": "85402a822d1ecf1db1096959413d35e1c37cf1a5", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.18 || ^5.0", + "nikic/php-parser": "^4.19.1 || ^5.1.0", "php": ">=7.3", - "phpunit/php-file-iterator": "^3.0.3", - "phpunit/php-text-template": "^2.0.2", - "sebastian/code-unit-reverse-lookup": "^2.0.2", - "sebastian/complexity": "^2.0", - "sebastian/environment": "^5.1.2", - "sebastian/lines-of-code": "^1.0.3", - "sebastian/version": "^3.0.1", - "theseer/tokenizer": "^1.2.0" + "phpunit/php-file-iterator": "^3.0.6", + "phpunit/php-text-template": "^2.0.4", + "sebastian/code-unit-reverse-lookup": "^2.0.3", + "sebastian/complexity": "^2.0.3", + "sebastian/environment": "^5.1.5", + "sebastian/lines-of-code": "^1.0.4", + "sebastian/version": "^3.0.2", + "theseer/tokenizer": "^1.2.3" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^9.6" }, "suggest": { "ext-pcov": "PHP extension that provides line coverage", @@ -573,7 +684,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.2-dev" + "dev-main": "9.2.x-dev" } }, "autoload": { @@ -602,7 +713,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.31" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.32" }, "funding": [ { @@ -610,7 +721,7 @@ "type": "github" } ], - "time": "2024-03-02T06:37:42+00:00" + "time": "2024-08-22T04:23:01+00:00" }, { "name": "phpunit/php-file-iterator", @@ -855,45 +966,45 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.18", + "version": "9.6.20", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "32c2c2d6580b1d8ab3c10b1e9e4dc263cc69bb04" + "reference": "49d7820565836236411f5dc002d16dd689cde42f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/32c2c2d6580b1d8ab3c10b1e9e4dc263cc69bb04", - "reference": "32c2c2d6580b1d8ab3c10b1e9e4dc263cc69bb04", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/49d7820565836236411f5dc002d16dd689cde42f", + "reference": "49d7820565836236411f5dc002d16dd689cde42f", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.3.1 || ^2", + "doctrine/instantiator": "^1.5.0 || ^2", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.10.1", - "phar-io/manifest": "^2.0.3", - "phar-io/version": "^3.0.2", + "myclabs/deep-copy": "^1.12.0", + "phar-io/manifest": "^2.0.4", + "phar-io/version": "^3.2.1", "php": ">=7.3", - "phpunit/php-code-coverage": "^9.2.28", - "phpunit/php-file-iterator": "^3.0.5", + "phpunit/php-code-coverage": "^9.2.31", + "phpunit/php-file-iterator": "^3.0.6", "phpunit/php-invoker": "^3.1.1", - "phpunit/php-text-template": "^2.0.3", - "phpunit/php-timer": "^5.0.2", - "sebastian/cli-parser": "^1.0.1", - "sebastian/code-unit": "^1.0.6", + "phpunit/php-text-template": "^2.0.4", + "phpunit/php-timer": "^5.0.3", + "sebastian/cli-parser": "^1.0.2", + "sebastian/code-unit": "^1.0.8", "sebastian/comparator": "^4.0.8", - "sebastian/diff": "^4.0.3", - "sebastian/environment": "^5.1.3", - "sebastian/exporter": "^4.0.5", - "sebastian/global-state": "^5.0.1", - "sebastian/object-enumerator": "^4.0.3", - "sebastian/resource-operations": "^3.0.3", - "sebastian/type": "^3.2", + "sebastian/diff": "^4.0.6", + "sebastian/environment": "^5.1.5", + "sebastian/exporter": "^4.0.6", + "sebastian/global-state": "^5.0.7", + "sebastian/object-enumerator": "^4.0.4", + "sebastian/resource-operations": "^3.0.4", + "sebastian/type": "^3.2.1", "sebastian/version": "^3.0.2" }, "suggest": { @@ -938,7 +1049,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.18" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.20" }, "funding": [ { @@ -954,7 +1065,7 @@ "type": "tidelift" } ], - "time": "2024-03-21T12:07:32+00:00" + "time": "2024-07-10T11:45:39+00:00" }, { "name": "sebastian/cli-parser", @@ -1971,7 +2082,7 @@ } ], "aliases": [], - "minimum-stability": "stable", + "minimum-stability": "RC", "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, diff --git a/src/Platform/Action.php b/src/Platform/Action.php index 4c628d2..c4f9069 100644 --- a/src/Platform/Action.php +++ b/src/Platform/Action.php @@ -3,8 +3,8 @@ namespace Utopia\Platform; use Exception; +use Utopia\Http\Validator; use Utopia\Platform\Scope\HTTP; -use Utopia\Validator; abstract class Action { diff --git a/src/Platform/Platform.php b/src/Platform/Platform.php index 385101a..f9711b7 100644 --- a/src/Platform/Platform.php +++ b/src/Platform/Platform.php @@ -3,11 +3,12 @@ namespace Utopia\Platform; use Exception; -use Utopia\App; +use Utopia\CLI\Adapters\Generic; use Utopia\CLI\CLI; -use Utopia\Queue\Adapter\Swoole; -use Utopia\Queue\Server; -use Utopia\Route; +use Utopia\Http\Http; +use Utopia\Http\Route; +use Utopia\Queue\Adapter\Swoole\Server; +use Utopia\Queue\Worker; abstract class Platform { @@ -22,7 +23,7 @@ abstract class Platform protected CLI $cli; - protected Server $worker; + protected Worker $worker; public function __construct(Module $module) { @@ -44,7 +45,8 @@ public function init(string $type, array $params = []): void $this->initHttp($services); break; case Service::TYPE_TASK: - $this->cli ??= new CLI(); + $adapter = $params['adapter'] ?? new Generic(); + $this->cli ??= new CLI($adapter); $this->initTasks($services); break; case Service::TYPE_GRAPHQL: @@ -56,9 +58,10 @@ public function init(string $type, array $params = []): void if (! isset($this->worker)) { $connection = $params['connection'] ?? null; $workersNum = $params['workersNum'] ?? 0; + $workerName = $params['workerName'] ?? null; $queueName = $params['queueName'] ?? 'v1-'.$workerName; - $adapter = new Swoole($connection, $workersNum, $queueName); - $this->worker = new Server($adapter); + $adapter = new Server($connection, $workersNum, $queueName); + $this->worker ??= new Worker($adapter); } $this->initWorker($services, $workerName); break; @@ -81,20 +84,20 @@ protected function initHttp(array $services): void /** @var Action $action */ switch ($action->getType()) { case Action::TYPE_INIT: - $hook = App::init(); + $hook = Http::init(); break; case Action::TYPE_ERROR: - $hook = App::error(); + $hook = Http::error(); break; case Action::TYPE_OPTIONS: - $hook = App::options(); + $hook = Http::options(); break; case Action::TYPE_SHUTDOWN: - $hook = App::shutdown(); + $hook = Http::shutdown(); break; case Action::TYPE_DEFAULT: default: - $hook = App::addRoute($action->getHttpMethod(), $action->getHttpPath()); + $hook = Http::addRoute($action->getHttpMethod(), $action->getHttpPath()); break; } @@ -327,7 +330,7 @@ public function setCli(CLI $cli): self /** * Get the value of worker */ - public function getWorker(): Server + public function getWorker(): Worker { return $this->worker; } @@ -335,7 +338,7 @@ public function getWorker(): Server /** * Set the value of worker */ - public function setWorker(Server $worker): self + public function setWorker(Worker $worker): self { $this->worker = $worker; diff --git a/tests/Platform/MockResponse.php b/tests/Platform/MockResponse.php index a8b4040..f0dab4a 100644 --- a/tests/Platform/MockResponse.php +++ b/tests/Platform/MockResponse.php @@ -2,7 +2,7 @@ namespace Utopia\Tests; -use Utopia\Response; +use Utopia\Http\Response; class MockResponse extends Response { @@ -29,4 +29,28 @@ public function chunk(string $body = '', bool $end = false): void $this->end(); } } + + public function write(string $content): bool + { + if (! is_null($content)) { + echo $content; + } + + return true; + } + + protected function sendStatus(int $statusCode, string $reason): void + { + // TODO: Implement sendStatus() method. + } + + public function sendHeader(string $key, string $value): void + { + // TODO: Implement sendHeader() method. + } + + protected function sendCookie(string $name, string $value, array $options): void + { + // TODO: Implement sendCookie() method. + } } diff --git a/tests/Platform/TestActionCLI.php b/tests/Platform/TestActionCLI.php index 5248451..b1c8c2c 100644 --- a/tests/Platform/TestActionCLI.php +++ b/tests/Platform/TestActionCLI.php @@ -2,9 +2,9 @@ namespace Utopia\Tests; +use Utopia\Http\Validator\ArrayList; +use Utopia\Http\Validator\Text; use Utopia\Platform\Action; -use Utopia\Validator\ArrayList; -use Utopia\Validator\Text; class TestActionCLI extends Action { diff --git a/tests/Platform/TestActionInit.php b/tests/Platform/TestActionInit.php index 79175c2..440dee8 100644 --- a/tests/Platform/TestActionInit.php +++ b/tests/Platform/TestActionInit.php @@ -2,8 +2,8 @@ namespace Utopia\Tests; +use Utopia\Http\Response; use Utopia\Platform\Action; -use Utopia\Response; class TestActionInit extends Action { diff --git a/tests/e2e/CLITest.php b/tests/e2e/CLITest.php index 370b510..f7c6ba1 100644 --- a/tests/e2e/CLITest.php +++ b/tests/e2e/CLITest.php @@ -3,6 +3,7 @@ namespace Utopia\Tests; use PHPUnit\Framework\TestCase; +use Utopia\CLI\Adapters\Generic; use Utopia\CLI\CLI; use Utopia\Platform\Service; @@ -20,7 +21,7 @@ public function testCLISetup() { ob_start(); - $cli = new CLI(['test.php', 'build', '--email=me@example.com', '--list=item1', '--list=item2']); // Mock command request + $cli = new CLI(new Generic(), ['test.php', 'build', '--email=me@example.com', '--list=item1', '--list=item2']); // Mock command request $platform = new TestPlatform(); $platform->setCli($cli); diff --git a/tests/e2e/HTTPServicesTest.php b/tests/e2e/HTTPServicesTest.php index 77707f9..3231b12 100644 --- a/tests/e2e/HTTPServicesTest.php +++ b/tests/e2e/HTTPServicesTest.php @@ -3,29 +3,36 @@ namespace Utopia\Tests; use PHPUnit\Framework\TestCase; -use Utopia\App; -use Utopia\Request; +use Utopia\DI\Container; +use Utopia\DI\Dependency; +use Utopia\Http\Adapter\FPM\Request; +use Utopia\Http\Adapter\FPM\Response; +use Utopia\Http\Adapter\FPM\Server; +use Utopia\Http\Http; class HttpServicesTest extends TestCase { - protected ?App $app = null; - protected ?string $method; protected ?string $uri; + protected ?Http $http; + public function setUp(): void { - App::reset(); + Http::reset(); $platform = new TestPlatform(); $platform->init('http'); - $this->app = new App('UTC'); + $server = new Server(); + $this->http = new Http($server, new Container(), 'UTC'); + $this->http->setRequestClass(Request::class); + $this->http->setResponseClass(Response::class); } public function tearDown(): void { - $this->app = null; + $this->http = null; } public function testRootAction() @@ -33,9 +40,12 @@ public function testRootAction() $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_URI'] = '/'; - $res = new MockResponse(); + $context = new Container(); + $context->set((new Dependency())->setName('response')->setCallback(fn () => new MockResponse())); + $context->set((new Dependency())->setName('request')->setCallback(fn () => new Request())); + \ob_start(); - $this->app->run(new Request(), $res); + $this->http->run($context); $response = \ob_get_contents(); \ob_end_clean(); @@ -47,8 +57,13 @@ public function testChunkedAction() $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_URI'] = '/chunked'; + $res = new MockResponse(); + $context = new Container(); + $context->set((new Dependency())->setName('response')->setCallback(fn () => $res)); + $context->set((new Dependency())->setName('request')->setCallback(fn () => new Request())); + \ob_start(); - $this->app->run(new Request(), new MockResponse()); + $this->http->run($context); $response = \ob_get_contents(); \ob_end_clean(); @@ -61,7 +76,11 @@ public function testRedirectAction() $_SERVER['REQUEST_URI'] = '/redirect'; $res = new MockResponse(); - $this->app->run(new Request(), $res); + $context = new Container(); + $context->set((new Dependency())->setName('response')->setCallback(fn () => $res)); + $context->set((new Dependency())->setName('request')->setCallback(fn () => new Request())); + + $this->http->run($context); $this->assertEquals('/', $res->getHeaders()['Location']); } @@ -72,21 +91,28 @@ public function testHook() $_SERVER['REQUEST_URI'] = '/'; $res = new MockResponse(); + $context = new Container(); + $context->set((new Dependency())->setName('response')->setCallback(fn () => $res)); + $context->set((new Dependency())->setName('request')->setCallback(fn () => new Request())); + \ob_start(); - $this->app->run(new Request(), $res); + $this->http->run($context); $response = \ob_get_contents(); \ob_end_clean(); $this->assertEquals('Hello World!', $response); $this->assertEquals('init-called', $res->getHeaders()['x-init']); - App::reset(); $_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_URI'] = '/chunked'; $res1 = new MockResponse(); + $context = new Container(); + $context->set((new Dependency())->setName('response')->setCallback(fn () => $res1)); + $context->set((new Dependency())->setName('request')->setCallback(fn () => new Request())); + \ob_start(); - $this->app->run(new Request(), $res1); + $this->http->run($context); $response = \ob_get_contents(); \ob_end_clean();