diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 8c85584..1db2ef7 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,3 +1,3 @@ # These are supported funding model platforms - -custom: ["https://miladrahimi.com/pay.html"] +github: miladrahimi +custom: ["https://miladrahimi.com/pay.html", "https://www.paypal.com/paypalme/realmiladrahimi"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2620463 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ +name: CI +on: [push, pull_request] +jobs: + run: + strategy: + matrix: + include: + - php: '7.4' + - php: '8.0' + - php: '8.1' + - php: '8.2' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + - name: Install dependencies + run: composer self-update && composer install && composer dump-autoload + - name: Run tests and collect coverage + run: vendor/bin/phpunit --coverage-clover coverage.xml . + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4-beta + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d317df6..0000000 --- a/.travis.yml +++ /dev/null @@ -1,30 +0,0 @@ -sudo: required - -language: php - -php: - - 7.4 - - 8.0 - - 8.1 - -branches: - only: - - master - -before_script: - - composer install --no-interaction --no-suggest - - composer require php-coveralls/php-coveralls - -script: - - mkdir -p build/logs - - vendor/bin/phpunit --coverage-clover build/logs/clover.xml tests - -after_success: - - travis_retry php vendor/bin/php-coveralls -v - -notifications: - email: - recipients: - - info@miladrahimi.com - on_success: change - on_failure: always diff --git a/composer.json b/composer.json index fb54cf7..519909f 100644 --- a/composer.json +++ b/composer.json @@ -16,21 +16,21 @@ "authors": [ { "name": "Milad Rahimi", - "email": "info@miladrahimi.com", + "email": "i@miladrahimi.com", "homepage": "https://miladrahimi.com", "role": "Developer" } ], "support": { - "email": "info@miladrahimi.com", + "email": "i@miladrahimi.com", "source": "https://github.com/miladrahimi/phprouter/issues" }, "require": { - "php": ">=7.1", + "php": ">=7.4", "ext-json": "*", "ext-mbstring": "*", "laminas/laminas-diactoros": "^2.2", - "miladrahimi/phpcontainer": "^5.3.1" + "miladrahimi/phpcontainer": "^5.3.3" }, "require-dev": { "phpunit/phpunit": "^7|^8|^9" diff --git a/phpunit.xml b/phpunit.xml index e52954f..1458cd9 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,16 +1,18 @@ - + + + + + ./src + + + + + ./tests - - - ./src - - - - - + diff --git a/src/Dispatching/Caller.php b/src/Dispatching/Caller.php index 2c39bee..aabe06d 100644 --- a/src/Dispatching/Caller.php +++ b/src/Dispatching/Caller.php @@ -10,23 +10,12 @@ use Psr\Http\Message\ServerRequestInterface; /** - * Class Caller * It calls (runs) middleware and controllers - * - * @package MiladRahimi\PhpRouter\Dispatching */ class Caller { - /** - * @var Container - */ - private $container; + private Container $container; - /** - * Constructor - * - * @param Container $container - */ public function __construct(Container $container) { $this->container = $container; @@ -75,13 +64,13 @@ public function call($callable) [$class, $method] = $callable; - if (class_exists($class) == false) { + if (!class_exists($class)) { throw new InvalidCallableException("Class `$class` not found."); } $object = $this->container->instantiate($class); - if (method_exists($object, $method) == false) { + if (!method_exists($object, $method)) { throw new InvalidCallableException("Method `$class::$method` is not declared."); } @@ -104,7 +93,7 @@ public function call($callable) } } - if (is_callable($callable) == false) { + if (!is_callable($callable)) { throw new InvalidCallableException('Invalid callable.'); } diff --git a/src/Dispatching/Matcher.php b/src/Dispatching/Matcher.php index 4db5a51..f1af85d 100644 --- a/src/Dispatching/Matcher.php +++ b/src/Dispatching/Matcher.php @@ -8,23 +8,12 @@ use Psr\Http\Message\ServerRequestInterface; /** - * Class Matcher * It finds an appropriate route for HTTP requests - * - * @package MiladRahimi\PhpRouter\Dispatching */ class Matcher { - /** - * @var Repository - */ - private $repository; + private Repository $repository; - /** - * Constructor - * - * @param Repository $repository - */ public function __construct(Repository $repository) { $this->repository = $repository; @@ -38,7 +27,7 @@ public function __construct(Repository $repository) * @return Route * @throws RouteNotFoundException */ - public function find(ServerRequestInterface $request, array $patterns) + public function find(ServerRequestInterface $request, array $patterns): Route { foreach ($this->repository->findByMethod($request->getMethod()) as $route) { $parameters = []; @@ -59,7 +48,6 @@ public function find(ServerRequestInterface $request, array $patterns) * * @param string[] $parameters * @return string[] - * @noinspection PhpUnusedParameterInspection */ private function pruneRouteParameters(array $parameters): array { diff --git a/src/Exceptions/InvalidCallableException.php b/src/Exceptions/InvalidCallableException.php index 51bda61..d4526c8 100644 --- a/src/Exceptions/InvalidCallableException.php +++ b/src/Exceptions/InvalidCallableException.php @@ -5,10 +5,7 @@ use Exception; /** - * Class InvalidCallableException * It'd be thrown when a callable (controller or middleware) is not valid - * - * @package MiladRahimi\PhpRouter\Exceptions */ class InvalidCallableException extends Exception { diff --git a/src/Exceptions/RouteNotFoundException.php b/src/Exceptions/RouteNotFoundException.php index 7c718fb..5c8313e 100644 --- a/src/Exceptions/RouteNotFoundException.php +++ b/src/Exceptions/RouteNotFoundException.php @@ -5,10 +5,7 @@ use Exception; /** - * Class RouteNotFoundException * It'd be thrown when no route that matches the user request - * - * @package MiladRahimi\PhpRouter\Exceptions */ class RouteNotFoundException extends Exception { diff --git a/src/Exceptions/UndefinedRouteException.php b/src/Exceptions/UndefinedRouteException.php index b933737..34f3d1a 100644 --- a/src/Exceptions/UndefinedRouteException.php +++ b/src/Exceptions/UndefinedRouteException.php @@ -5,10 +5,7 @@ use Exception; /** - * Class UndefinedRouteException * It'd be thrown when cannot find a route to generate URL from - * - * @package MiladRahimi\PhpRouter\Exceptions */ class UndefinedRouteException extends Exception { diff --git a/src/Publisher/HttpPublisher.php b/src/Publisher/HttpPublisher.php index cca97a9..00f3e07 100644 --- a/src/Publisher/HttpPublisher.php +++ b/src/Publisher/HttpPublisher.php @@ -5,10 +5,7 @@ use Psr\Http\Message\ResponseInterface; /** - * Class HttpPublisher * It publishes responses provided by controllers and middleware as HTTP responses - * - * @package MiladRahimi\PhpRouter\Services */ class HttpPublisher implements Publisher { diff --git a/src/Publisher/Publisher.php b/src/Publisher/Publisher.php index e62645a..cb0f4d3 100644 --- a/src/Publisher/Publisher.php +++ b/src/Publisher/Publisher.php @@ -3,10 +3,7 @@ namespace MiladRahimi\PhpRouter\Publisher; /** - * Interface Publisher * It publishes responses provided by controllers and middleware - * - * @package MiladRahimi\PhpRouter\Services */ interface Publisher { diff --git a/src/Router.php b/src/Router.php index f085d74..839a2bf 100644 --- a/src/Router.php +++ b/src/Router.php @@ -20,54 +20,27 @@ use Laminas\Diactoros\ServerRequestFactory; /** - * Class Router * It defines the application routes and dispatches them (runs the application). - * - * @package MiladRahimi\PhpRouter */ class Router { - /** - * @var Container - */ - private $container; + private Container $container; - /** - * @var Storekeeper - */ - private $storekeeper; + private Storekeeper $storekeeper; - /** - * @var Matcher - */ - private $matcher; + private Matcher $matcher; - /** - * @var Caller - */ - private $caller; + private Caller $caller; - /** - * @var Publisher - */ - private $publisher; + private Publisher $publisher; /** * List of defined parameter patterns with `pattern()` method * * @var string[] */ - private $patterns = []; + private array $patterns = []; - /** - * Constructor - * - * @param Container $container - * @param Storekeeper $storekeeper - * @param Matcher $matcher - * @param Caller $caller - * @param Publisher $publisher - */ public function __construct( Container $container, Storekeeper $storekeeper, diff --git a/src/Routing/Attributes.php b/src/Routing/Attributes.php index 3626744..eb55985 100644 --- a/src/Routing/Attributes.php +++ b/src/Routing/Attributes.php @@ -3,10 +3,7 @@ namespace MiladRahimi\PhpRouter\Routing; /** - * Class Attributes * It is an Enum that holds route attributes - * - * @package MiladRahimi\PhpRouter\Routing */ class Attributes { diff --git a/src/Routing/Repository.php b/src/Routing/Repository.php index fd0cda5..447e77e 100644 --- a/src/Routing/Repository.php +++ b/src/Routing/Repository.php @@ -5,10 +5,7 @@ use Closure; /** - * Class Repository * It is a repository for the defined routes - * - * @package MiladRahimi\PhpRouter\Routing */ class Repository { @@ -17,7 +14,7 @@ class Repository * * @var Route[] */ - private $routes = []; + private array $routes = []; /** * Save a new route diff --git a/src/Routing/Route.php b/src/Routing/Route.php index 1845152..2e7e3d6 100644 --- a/src/Routing/Route.php +++ b/src/Routing/Route.php @@ -5,33 +5,24 @@ use Closure; /** - * Class Route * It is a single defined route - * - * @package MiladRahimi\PhpRouter\Routing */ class Route { /** * The route name - * - * @var string|null */ - private $name; + private ?string $name; /** * The route path - * - * @var string */ - private $path; + private string $path; /** * The route http method - * - * @var string */ - private $method; + private ?string $method; /** * The route controller @@ -42,31 +33,25 @@ class Route /** * The route middleware - * - * @var array */ - private $middleware; + private array $middleware; /** * The route domain - * - * @var string|null */ - private $domain; + private ?string $domain; /** * The route uri from user request (post-property) - * - * @var string */ - private $uri = null; + private ?string $uri = null; /** * The route parameters from user request (post-property) * * @var string[] */ - private $parameters = []; + private array $parameters = []; /** * Constructor @@ -112,97 +97,61 @@ public function toArray(): array ]; } - /** - * @return string - */ public function toJson(): string { return json_encode($this->toArray()); } - /** - * @return string - */ - public function __toString() + public function __toString(): string { return $this->toJson(); } - /** - * @return string|null - */ public function getName(): ?string { return $this->name; } - /** - * @return string - */ public function getPath(): string { return $this->path; } - /** - * @return string - */ public function getMethod(): string { return $this->method; } - /** - * @return Closure|string|array - */ public function getController() { return $this->controller; } - /** - * @return array - */ public function getMiddleware(): array { return $this->middleware; } - /** - * @return string|null - */ public function getDomain(): ?string { return $this->domain; } - /** - * @return string[] - */ public function getParameters(): array { return $this->parameters; } - /** - * @param string[] $parameters - */ public function setParameters(array $parameters): void { $this->parameters = $parameters; } - /** - * @return ?string - */ public function getUri(): ?string { return $this->uri; } - /** - * @param ?string $uri - */ public function setUri(?string $uri): void { $this->uri = $uri; diff --git a/src/Routing/State.php b/src/Routing/State.php index d30e6fe..db0c4bf 100644 --- a/src/Routing/State.php +++ b/src/Routing/State.php @@ -3,27 +3,15 @@ namespace MiladRahimi\PhpRouter\Routing; /** - * Class State * It is state (attributes) of routes - * - * @package MiladRahimi\PhpRouter\Routing */ class State { - /** - * @var string - */ - private $prefix; + private string $prefix; - /** - * @var array - */ - private $middleware; + private array $middleware; - /** - * @var string|null - */ - private $domain; + private ?string $domain; /** * Constructor @@ -41,8 +29,6 @@ public function __construct(string $prefix = '', array $middleware = [], ?string /** * Append new attributes to the existing ones - * - * @param array $attributes */ public function append(array $attributes): void { @@ -51,25 +37,16 @@ public function append(array $attributes): void $this->middleware = array_merge($this->middleware, $attributes[Attributes::MIDDLEWARE] ?? []); } - /** - * @return string - */ public function getPrefix(): string { return $this->prefix; } - /** - * @return array - */ public function getMiddleware(): array { return $this->middleware; } - /** - * @return string|null - */ public function getDomain(): ?string { return $this->domain; diff --git a/src/Routing/Storekeeper.php b/src/Routing/Storekeeper.php index e2271d5..d881ba8 100644 --- a/src/Routing/Storekeeper.php +++ b/src/Routing/Storekeeper.php @@ -5,29 +5,14 @@ use Closure; /** - * Class Storekeeper * It adds new routes with an existing state (attributes) into a Route repository - * - * @package MiladRahimi\PhpRouter\Routing */ class Storekeeper { - /** - * @var Repository - */ - private $repository; + private Repository $repository; - /** - * @var State - */ - private $state; + private State $state; - /** - * Constructor - * - * @param Repository $repository - * @param State $state - */ public function __construct(Repository $repository, State $state) { $this->repository = $repository; @@ -54,25 +39,16 @@ public function add(string $method, string $path, $controller, ?string $name = n ); } - /** - * @return State - */ public function getState(): State { return $this->state; } - /** - * @param State $state - */ public function setState(State $state): void { $this->state = $state; } - /** - * @return Repository - */ public function getRepository(): Repository { return $this->repository; diff --git a/src/Url.php b/src/Url.php index 7300725..2fa9c33 100644 --- a/src/Url.php +++ b/src/Url.php @@ -6,23 +6,12 @@ use MiladRahimi\PhpRouter\Routing\Repository; /** - * Class Url * It generates URLs by name based on the defined routes - * - * @package MiladRahimi\PhpRouter */ class Url { - /** - * @var Repository - */ - private $repository; + private Repository $repository; - /** - * Constructor - * - * @param Repository $repository - */ public function __construct(Repository $repository) { $this->repository = $repository; @@ -49,8 +38,6 @@ public function make(string $name, array $parameters = []): string } $uri = preg_replace('/{[^}]+\?}/', '', $uri); - $uri = str_replace('/?', '', $uri); - - return $uri; + return str_replace('/?', '', $uri); } } diff --git a/src/View/PhpView.php b/src/View/PhpView.php index dfe6e7c..d7a7f49 100644 --- a/src/View/PhpView.php +++ b/src/View/PhpView.php @@ -2,28 +2,16 @@ namespace MiladRahimi\PhpRouter\View; -use Laminas\Diactoros\Response\EmptyResponse; - /** - * Class PhpView * It makes views from PHP and HTML/PHP files - * - * @package MiladRahimi\PhpRouter\Services */ class PhpView implements View { /** * The root directory of view files - * - * @var string */ - private $directory; + private string $directory; - /** - * Constructor - * - * @param string $directory - */ public function __construct(string $directory) { $this->directory = $directory; @@ -45,7 +33,6 @@ public function make(string $name, array $data = [], int $httpStatus = 200, arra extract($data); - /** @noinspection PhpIncludeInspection */ require $path; return null; diff --git a/src/View/View.php b/src/View/View.php index 1b0d0cf..2e13778 100644 --- a/src/View/View.php +++ b/src/View/View.php @@ -3,19 +3,13 @@ namespace MiladRahimi\PhpRouter\View; /** - * Interface View * It makes views - * - * @package MiladRahimi\PhpRouter\Services */ interface View { /** * Make a view * - * @param string $name - * @param array $data - * @param int $httpStatus * @param string[] $httpHeaders * @return mixed */ diff --git a/tests/Common/SampleConstructorController.php b/tests/Common/SampleConstructorController.php index 32ed2ea..f099883 100644 --- a/tests/Common/SampleConstructorController.php +++ b/tests/Common/SampleConstructorController.php @@ -4,10 +4,7 @@ class SampleConstructorController { - /** - * @var SampleInterface - */ - public $sample; + public SampleInterface $sample; public function __construct(SampleInterface $sample) { @@ -18,4 +15,4 @@ public function getSampleClassName(): string { return get_class($this->sample); } -} \ No newline at end of file +} diff --git a/tests/Common/SampleController.php b/tests/Common/SampleController.php index d30f806..7bec955 100644 --- a/tests/Common/SampleController.php +++ b/tests/Common/SampleController.php @@ -4,17 +4,17 @@ class SampleController { - public function home() + public function home(): string { return 'Home'; } - public function page() + public function page(): string { return 'Page'; } - public function ok() + public function ok(): string { return 'OK'; } diff --git a/tests/Common/SampleMiddleware.php b/tests/Common/SampleMiddleware.php index 59eb341..1c6162b 100644 --- a/tests/Common/SampleMiddleware.php +++ b/tests/Common/SampleMiddleware.php @@ -6,22 +6,11 @@ class SampleMiddleware { - /** - * @var string - */ - public $content; - - /** - * @var array - */ - public static $output = []; - - /** - * SampleMiddleware constructor. - * - * @param string|null $content - */ - public function __construct(string $content = null) + public string $content; + + public static array $output = []; + + public function __construct(?string $content = null) { static::$output = []; diff --git a/tests/Common/StopperMiddleware.php b/tests/Common/StopperMiddleware.php index 8903072..ed89c63 100644 --- a/tests/Common/StopperMiddleware.php +++ b/tests/Common/StopperMiddleware.php @@ -2,35 +2,23 @@ namespace MiladRahimi\PhpRouter\Tests\Common; -use Closure; -use Psr\Http\Message\ServerRequestInterface; use Laminas\Diactoros\Response\TextResponse; class StopperMiddleware { - /** - * @var string - */ - public $content; + public string $content; /** * @var array */ - public static $output = []; + public static array $output = []; - /** - * SampleMiddleware constructor. - * @param string $content - */ public function __construct(string $content = null) { $this->content = $content ?: mt_rand(1, 9999999); } - /** - * @inheritdoc - */ - public function handle(ServerRequestInterface $request, Closure $next) + public function handle(): TextResponse { static::$output[] = $this->content; diff --git a/tests/Common/TrapPublisher.php b/tests/Common/TrapPublisher.php index 25d7c86..6e7a3b5 100644 --- a/tests/Common/TrapPublisher.php +++ b/tests/Common/TrapPublisher.php @@ -7,20 +7,14 @@ class TrapPublisher implements Publisher { - /** - * @var string - */ - public $output = ''; + public string $output = ''; - /** - * @var int - */ - public $responseCode = 0; + public int $responseCode = 0; /** * @var string[] */ - public $headerLines = []; + public array $headerLines = []; /** * @inheritdoc diff --git a/tests/Features/GroupingTest.php b/tests/Features/GroupingTest.php index 6d1be2c..196607d 100644 --- a/tests/Features/GroupingTest.php +++ b/tests/Features/GroupingTest.php @@ -67,7 +67,7 @@ public function test_nested_groups_with_middleware() */ public function test_with_a_prefix() { - $this->mockRequest('GET', 'http://example.com/group/page'); + $this->mockRequest('GET', 'https://example.com/group/page'); $router = $this->router(); $router->group(['prefix' => '/group'], function (Router $router) { @@ -83,7 +83,7 @@ public function test_with_a_prefix() */ public function test_nested_groups_with_prefix() { - $this->mockRequest('GET', 'http://example.com/group1/group2/page'); + $this->mockRequest('GET', 'https://example.com/group1/group2/page'); $router = $this->router(); $router->group(['prefix' => '/group1'], function (Router $router) { @@ -101,7 +101,7 @@ public function test_nested_groups_with_prefix() */ public function test_with_domain() { - $this->mockRequest('GET', 'http://sub.domain.tld/'); + $this->mockRequest('GET', 'https://sub.domain.tld/'); $router = $this->router(); $router->group(['domain' => 'sub.domain.tld'], function (Router $router) { @@ -117,7 +117,7 @@ public function test_with_domain() */ public function test_nested_groups_with_domain_it_should_consider_the_inner_group_domain() { - $this->mockRequest('GET', 'http://sub2.domain.com/'); + $this->mockRequest('GET', 'https://sub2.domain.com/'); $router = $this->router(); $router->group(['domain' => 'sub1.domain.com'], function (Router $router) { diff --git a/tests/Features/HttpMethodTest.php b/tests/Features/HttpMethodTest.php index da2f8f2..aa67e1a 100644 --- a/tests/Features/HttpMethodTest.php +++ b/tests/Features/HttpMethodTest.php @@ -14,7 +14,7 @@ class HttpMethodTest extends TestCase */ public function test_a_get_route() { - $this->mockRequest('GET', 'http://example.com/'); + $this->mockRequest('GET', 'https://example.com/'); $router = $this->router(); $router->get('/', [SampleController::class, 'home']); @@ -28,7 +28,7 @@ public function test_a_get_route() */ public function test_a_post_route() { - $this->mockRequest('POST', 'http://example.com/'); + $this->mockRequest('POST', 'https://example.com/'); $router = $this->router(); $router->post('/', [SampleController::class, 'home']); @@ -42,7 +42,7 @@ public function test_a_post_route() */ public function test_a_put_route() { - $this->mockRequest('PUT', 'http://example.com/'); + $this->mockRequest('PUT', 'https://example.com/'); $router = $this->router(); $router->put('/', [SampleController::class, 'home']); @@ -56,7 +56,7 @@ public function test_a_put_route() */ public function test_a_patch_route() { - $this->mockRequest('PATCH', 'http://example.com/'); + $this->mockRequest('PATCH', 'https://example.com/'); $router = $this->router(); $router->patch('/', [SampleController::class, 'home']); @@ -70,7 +70,7 @@ public function test_a_patch_route() */ public function test_a_delete_route() { - $this->mockRequest('DELETE', 'http://example.com/'); + $this->mockRequest('DELETE', 'https://example.com/'); $router = $this->router(); $router->delete('/', [SampleController::class, 'home']); @@ -84,7 +84,7 @@ public function test_a_delete_route() */ public function test_map_a_post_route() { - $this->mockRequest('POST', 'http://example.com/'); + $this->mockRequest('POST', 'https://example.com/'); $router = $this->router(); $router->define('POST', '/', [SampleController::class, 'home']); @@ -98,7 +98,7 @@ public function test_map_a_post_route() */ public function test_map_a_custom_method() { - $this->mockRequest('CUSTOM', 'http://example.com/'); + $this->mockRequest('CUSTOM', 'https://example.com/'); $router = $this->router(); $router->define('CUSTOM', '/', [SampleController::class, 'home']); @@ -117,11 +117,11 @@ public function test_any_with_some_methods() return $request->getMethod(); }); - $this->mockRequest('GET', 'http://example.com/'); + $this->mockRequest('GET', 'https://example.com/'); $router->dispatch(); $this->assertEquals('GET', $this->output($router)); - $this->mockRequest('POST', 'http://example.com/'); + $this->mockRequest('POST', 'https://example.com/'); $router->dispatch(); $this->assertEquals('POST', $this->output($router)); } diff --git a/tests/Features/ParametersTest.php b/tests/Features/ParametersTest.php index 15009ba..7bb1219 100644 --- a/tests/Features/ParametersTest.php +++ b/tests/Features/ParametersTest.php @@ -13,7 +13,7 @@ class ParametersTest extends TestCase public function test_with_a_required_parameter() { $id = random_int(1, 100); - $this->mockRequest('GET', "http://example.com/products/$id"); + $this->mockRequest('GET', "https://example.com/products/$id"); $router = $this->router(); $router->get('/products/{id}', function ($id) { @@ -31,7 +31,7 @@ public function test_with_some_required_parameters() { $pid = random_int(1, 100); $cid = random_int(1, 100); - $this->mockRequest('GET', "http://example.com/products/$pid/comments/$cid"); + $this->mockRequest('GET', "https://example.com/products/$pid/comments/$cid"); $router = $this->router(); $router->get('/products/{pid}/comments/{cid}', function ($pid, $cid) { @@ -48,7 +48,7 @@ public function test_with_some_required_parameters() public function test_with_a_provided_optional_parameter() { $id = random_int(1, 100); - $this->mockRequest('GET', "http://example.com/products/$id"); + $this->mockRequest('GET', "https://example.com/products/$id"); $router = $this->router(); $router->get('/products/{id?}', function ($id = 'default') { @@ -64,7 +64,7 @@ public function test_with_a_provided_optional_parameter() */ public function test_with_a_unprovided_optional_parameter() { - $this->mockRequest('GET', "http://example.com/products/"); + $this->mockRequest('GET', "https://example.com/products/"); $router = $this->router(); $router->get('/products/{id?}', function ($id = 'default') { @@ -80,7 +80,7 @@ public function test_with_a_unprovided_optional_parameter() */ public function test_with_a_unprovided_optional_parameter_and_slash() { - $this->mockRequest('GET', "http://example.com/products"); + $this->mockRequest('GET', "https://example.com/products"); $router = $this->router(); $router->get('/products/?{id?}', function ($id = 'default') { @@ -98,7 +98,7 @@ public function test_with_some_optional_parameters() { $pid = random_int(1, 100); $cid = random_int(1, 100); - $this->mockRequest('GET', "http://example.com/products/$pid/comments/$cid"); + $this->mockRequest('GET', "https://example.com/products/$pid/comments/$cid"); $router = $this->router(); $router->get('/products/{pid?}/comments/{cid?}', function ($pid, $cid) { @@ -116,7 +116,7 @@ public function test_with_mixin_parameters() { $pid = random_int(1, 100); $cid = random_int(1, 100); - $this->mockRequest('GET', "http://example.com/products/$pid/comments/$cid"); + $this->mockRequest('GET', "https://example.com/products/$pid/comments/$cid"); $router = $this->router(); $router->get('/products/{pid}/comments/{cid?}', function ($pid, $cid = 'default') { diff --git a/tests/Features/PatternsTest.php b/tests/Features/PatternsTest.php index e762fc6..878dfef 100644 --- a/tests/Features/PatternsTest.php +++ b/tests/Features/PatternsTest.php @@ -14,7 +14,7 @@ class PatternsTest extends TestCase public function test_with_a_single_digit_pattern() { $id = random_int(1, 9); - $this->mockRequest('GET', "http://example.com/products/$id"); + $this->mockRequest('GET', "https://example.com/products/$id"); $router = $this->router(); $router->pattern('id', '[0-9]'); @@ -32,7 +32,7 @@ public function test_with_a_single_digit_pattern() public function test_with_a_single_digit_pattern_given_more() { $id = random_int(10, 100); - $this->mockRequest('GET', "http://example.com/products/$id"); + $this->mockRequest('GET', "https://example.com/products/$id"); $router = $this->router(); $router->pattern('id', '[0-9]'); @@ -50,7 +50,7 @@ public function test_with_a_single_digit_pattern_given_more() public function test_with_a_multi_digits_pattern() { $id = random_int(10, 100); - $this->mockRequest('GET', "http://example.com/products/$id"); + $this->mockRequest('GET', "https://example.com/products/$id"); $router = $this->router(); $router->pattern('id', '[0-9]+'); @@ -67,7 +67,7 @@ public function test_with_a_multi_digits_pattern() */ public function test_with_a_multi_digits_pattern_given_string() { - $this->mockRequest('GET', "http://example.com/products/string"); + $this->mockRequest('GET', "https://example.com/products/string"); $router = $this->router(); $router->pattern('id', '[0-9]+'); @@ -85,7 +85,7 @@ public function test_with_a_multi_digits_pattern_given_string() public function test_with_a_alphanumeric_pattern() { $id = 'abc123xyz'; - $this->mockRequest('GET', "http://example.com/products/$id"); + $this->mockRequest('GET', "https://example.com/products/$id"); $router = $this->router(); $router->pattern('id', '[0-9a-z]+'); @@ -103,7 +103,7 @@ public function test_with_a_alphanumeric_pattern() public function test_with_a_alphanumeric_pattern_given_invalid() { $id = 'abc$$$'; - $this->mockRequest('GET', "http://example.com/products/$id"); + $this->mockRequest('GET', "https://example.com/products/$id"); $router = $this->router(); $router->pattern('id', '[0-9a-z]+'); diff --git a/tests/Features/RouteTest.php b/tests/Features/RouteTest.php index 8398d71..871ab01 100644 --- a/tests/Features/RouteTest.php +++ b/tests/Features/RouteTest.php @@ -16,7 +16,7 @@ class RouteTest extends TestCase */ public function test_current_route_for_a_route_with_all_attributes() { - $this->mockRequest('POST', 'http://shop.com/admin/profile/666'); + $this->mockRequest('POST', 'https://shop.com/admin/profile/666'); $router = $this->router(); @@ -55,7 +55,7 @@ public function test_current_route_for_a_route_with_all_attributes() */ public function test_lately_added_attributes_of_route() { - $this->mockRequest('POST', 'http://shop.com/admin/profile/666'); + $this->mockRequest('POST', 'https://shop.com/admin/profile/666'); $router = $this->router(); diff --git a/tests/Features/UrlTest.php b/tests/Features/UrlTest.php index 50165b9..644081a 100644 --- a/tests/Features/UrlTest.php +++ b/tests/Features/UrlTest.php @@ -28,7 +28,7 @@ public function test_generating_url_for_the_homepage() */ public function test_generating_url_for_a_page() { - $this->mockRequest('GET', 'http://web.com/page'); + $this->mockRequest('GET', 'https://web.com/page'); $router = $this->router(); $router->get('/', function (Url $url) { @@ -47,7 +47,7 @@ public function test_generating_url_for_a_page() */ public function test_generating_url_for_a_page_with_required_parameter() { - $this->mockRequest('GET', 'http://web.com/'); + $this->mockRequest('GET', 'https://web.com/'); $router = $this->router(); $router->get('/', function (Url $url) { @@ -66,7 +66,7 @@ public function test_generating_url_for_a_page_with_required_parameter() */ public function test_generating_url_for_a_page_with_optional_parameter() { - $this->mockRequest('GET', 'http://web.com/'); + $this->mockRequest('GET', 'https://web.com/'); $router = $this->router(); $router->get('/', function (Url $url) { @@ -85,7 +85,7 @@ public function test_generating_url_for_a_page_with_optional_parameter() */ public function test_generating_url_for_a_page_with_optional_parameter_ignored() { - $this->mockRequest('GET', 'http://web.com/'); + $this->mockRequest('GET', 'https://web.com/'); $router = $this->router(); $router->get('/', function (Url $url) { @@ -104,7 +104,7 @@ public function test_generating_url_for_a_page_with_optional_parameter_ignored() */ public function test_generating_url_for_a_page_with_optional_parameter_and_slash_ignored() { - $this->mockRequest('GET', 'http://web.com/'); + $this->mockRequest('GET', 'https://web.com/'); $router = $this->router(); $router->get('/', function (Url $url) { diff --git a/tests/TestCase.php b/tests/TestCase.php index 2ce2b76..162abab 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -17,7 +17,7 @@ protected function setUp(): void { parent::setUp(); - $this->mockRequest('GET', 'http://example.com/'); + $this->mockRequest('GET', 'https://example.com/'); } /** @@ -55,7 +55,7 @@ protected function router(): Router * @param Router $router * @return string */ - protected function output(Router $router) + protected function output(Router $router): string { return $this->publisher($router)->output; }