Compare commits

...

3 Commits

Author SHA1 Message Date
Abel Hoogeveen 016fa03ac2
Updated to PHP 8.0.
continuous-integration/drone/push Build is passing Details
- Release version 1.3.3.
- Most property, argument and return types have been defined and are now enforced.
- Drone now performs tests for both PHP 7.4 and 8.0. Extend for future versions.
2021-11-24 19:31:59 +01:00
Abel Hoogeveen 51153520e2
Added absolute pathing for unit tests.
continuous-integration/drone/push Build is passing Details
2021-01-28 16:07:48 +01:00
Abel Hoogeveen 3f522c55fa
Added categories to the router, without breaking (most) backwards compatibility.
continuous-integration/drone/push Build is failing Details
Categories can be added using the routeConfig, by using a 'category' key. Router::route() can then distinguish between them using its second parameter.
Also added drone support.
2021-01-28 15:42:38 +01:00
32 changed files with 214 additions and 152 deletions

30
.drone.yml Normal file
View File

@ -0,0 +1,30 @@
kind: pipeline
type: docker
name: test
steps:
- name: composer
image: composer:latest
commands:
- composer install
- name: php74test
image: registry.i15.nl/i15/fuzephp:7.4-alpine
commands:
- docker-php-ext-enable xdebug
- vendor/bin/phpunit -c test/phpunit.xml
- name: php80test
image: registry.i15.nl/i15/fuzephp:8.0-alpine
commands:
- docker-php-ext-enable xdebug
- vendor/bin/phpunit -c test/phpunit.xml
- name: coverage
image: registry.i15.nl/i15/fuzephp:8.0-alpine
commands:
- docker-php-ext-enable xdebug
- vendor/bin/phpunit -c test/phpunit.xml --coverage-text
image_pull_secrets:
- dockerconfig

1
.gitattributes vendored
View File

@ -1,4 +1,5 @@
.gitattributes export-ignore
.gitignore export-ignore
.gitlab-ci.yml export-ignore
.drone.yml export-ignore
test/ export-ignore

View File

@ -4,17 +4,13 @@
"license": ["MIT"],
"authors": [
{
"name": "TechFuze",
"homepage": "https://techfuze.net"
},
{
"name": "FuzeWorks Community",
"homepage": "https://techfuze.net/fuzeworks/contributors"
"name": "Abel Hoogeveen",
"homepage": "https://i15.nl"
}
],
"require": {
"php": ">=7.4.0",
"fuzeworks/core": "~1.2.0"
"fuzeworks/core": "~1.3.0"
},
"require-dev": {
"phpunit/phpunit": "^9",

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
/**
@ -44,7 +44,7 @@
* Custom callable: Adds a route that sends all matches to the provided callable. Allows user to replace defaultCallable
* 'routingString' => array('callable' => array(CALLABLE))
*
* Dynamic rewrite: Adds a route that rewrites an URL to a specific controller and method configuration, using a callable. The callable can dynamically determine which page to load.
* Dynamic rewrite: Adds a route that rewrites a URL to a specific controller and method configuration, using a callable. The callable can dynamically determine which page to load.
* 'routingString' => CALLABLE
*
* Static rewrite: Adds a route that rewrites and URL to a specific controller and method using a fixed route. This allows for pre-determined rewrites of pages.

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace FuzeWorks;
@ -49,22 +49,22 @@ abstract class Controller
/**
* @var Plugins
*/
protected $plugins;
protected Plugins $plugins;
/**
* @var Libraries
*/
protected $libraries;
protected Libraries $libraries;
/**
* @var Helpers
*/
protected $helpers;
protected Helpers $helpers;
/**
* @var Config
*/
protected $config;
protected Config $config;
/**
* @var Controllers

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace FuzeWorks;
@ -45,7 +45,7 @@ use FuzeWorks\Exception\NotFoundException;
* Controllers Class.
*
* Simple loader class for MVC Controllers.
* Typically loads controllers from Application\Controller unless otherwise specified.
* Typically, loads controllers from Application\Controller unless otherwise specified.
*
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace FuzeWorks\Event;
@ -52,28 +52,28 @@ class ControllerGetEvent extends Event
*
* @var array
*/
public $controllerPaths = array();
public array $controllerPaths = array();
/**
* The name of the controller to be loaded.
*
* @var string|null
*/
public $controllerName = null;
public ?string $controllerName = null;
/**
* The namespace of the controller to be loaded. Defaults to Application\Controller
*
* @var string
*/
public $namespace = '\Application\Controller\\';
public string $namespace = '\Application\Controller\\';
/**
* Arguments provided to the constructor
*
* @var array
*/
public $arguments = [];
public array $arguments = [];
public function init($controllerName, $controllerPaths, $namespace, $arguments)
{

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace FuzeWorks\Event;
@ -53,28 +53,28 @@ class ModelGetEvent extends Event
*
* @var array
*/
public $modelPaths = array();
public array $modelPaths = array();
/**
* The name of the model to be loaded.
*
* @var string|null
*/
public $modelName = null;
public ?string $modelName = null;
/**
* The namespace of the model to be loaded. Defaults to Application\Model
*
* @var string
*/
public $namespace = '\Application\Model\\';
public string $namespace = '\Application\Model\\';
/**
* Arguments provided to the constructor
*
* @var array
*/
public $arguments = [];
public array $arguments = [];
public function init($modelName, $modelPaths, $namespace, $arguments)
{

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace FuzeWorks\Event;
@ -46,7 +46,7 @@ use FuzeWorks\View;
*
* Use this to cancel the calling of a view method.
*
* Currently only used by Router::defaultCallable();
* Currently, only used by Router::defaultCallable();
*
* This event is currently used in the WebComponent project. It allows the component to stop loading when
* a CSRFException is thrown, and the view has no method of handling this request
@ -61,35 +61,35 @@ class RouterCallViewEvent extends Event
*
* @var array
*/
public $viewMethods;
public array $viewMethods;
/**
* The parameters that will be provided to the function in the view
*
* @var array
*/
public $viewParameters;
public array $viewParameters;
/**
* The route that resulted in this controller and view
*
* @var string
*/
public $route;
public string $route;
/**
* The view the method will be called on
*
* @var View
*/
public $view;
public View $view;
/**
* The controller that's associated with this View
*
* @var Controller
*/
public $controller;
public Controller $controller;
public function init(View $view, Controller $controller, array $viewMethods, array $viewParameters, string $route)
{

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace FuzeWorks\Event;
@ -41,9 +41,9 @@ use FuzeWorks\Event;
/**
* Event that gets fired when a callable is to be loaded by the Router class
*
* Use this to cancel the modify the loading of a custom callable or the defaultCallable
* Use this to cancel the modification the loading of a custom callable or the defaultCallable
*
* Currently only used by Router::loadCallable();
* Currently, only used by Router::loadCallable();
*
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
@ -63,21 +63,21 @@ class RouterLoadCallableEvent extends Event
*
* @var array
*/
public $matches;
public array $matches;
/**
* The static route configuration
*
* @var array
*/
public $routeData;
public array $routeData;
/**
* The route which resulted in this callable being loaded
*
* @var string
*/
public $route;
public string $route;
public function init(callable $callable, array $matches, array $routeData, string $route)
{

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace FuzeWorks\Event;
@ -44,7 +44,7 @@ use FuzeWorks\Priority;
*
* Use this to cancel the loading of a combination, or change the details of what is loaded.
*
* Currently only used by Router::defaultCallable();
* Currently, only used by Router::defaultCallable();
*
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
@ -56,49 +56,49 @@ class RouterLoadViewAndControllerEvent extends Event
*
* @var string
*/
public $viewName;
public string $viewName;
/**
* The type of view to be loaded
*
* @var string
*/
public $viewType;
public string $viewType;
/**
* The function that will be loaded in the view
*
* @var array
*/
public $viewMethods;
public array $viewMethods;
/**
* The parameters that will be provided to the function in the view
*
* @var array
*/
public $viewParameters;
public array $viewParameters;
/**
* The namespace to use to load the View and Controller
*
* @var string
*/
public $namespacePrefix;
public string $namespacePrefix;
/**
* The route that resulted in this controller and view
*
* @var string
*/
public $route;
public string $route;
/**
* A controller to be injected.
*
* @var Controller|null
*/
public $controller;
public ?Controller $controller = null;
public function init(string $viewName, string $viewType, array $viewMethods, array $viewParameters, string $namespacePrefix, string $route)
{

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace FuzeWorks\Event;
@ -53,40 +53,40 @@ class ViewGetEvent extends Event
*
* @var array
*/
public $viewPaths = [];
public array $viewPaths = [];
/**
* The name of the view to be loaded.
*
* @var string|null
*/
public $viewName = null;
public ?string $viewName = null;
/**
* The type of view to be loaded. Eg: html, json, cli.
*
* @var string|null
*/
public $viewType = null;
public ?string $viewType = null;
/**
* The namespace of the View to be loaded. Defaults to Application\View
*
* @var string
*/
public $namespace = '\Application\View\\';
public string $namespace = '\Application\View\\';
/**
* Arguments provided to the constructor
*
* @var array
*/
public $arguments = [];
public array $arguments = [];
/**
* @var Controller
*/
public $controller;
public Controller $controller;
public function init($viewName, $viewType, $viewPaths, $namespace, $controller, $arguments)
{

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace FuzeWorks;
@ -50,22 +50,22 @@ abstract class Model
/**
* @var Plugins
*/
protected $plugins;
protected Plugins $plugins;
/**
* @var Libraries
*/
protected $libraries;
protected Libraries $libraries;
/**
* @var Helpers
*/
protected $helpers;
protected Helpers $helpers;
/**
* @var Config
*/
protected $config;
protected Config $config;
/**
* @var Models

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace FuzeWorks;
@ -45,7 +45,7 @@ use FuzeWorks\Exception\NotFoundException;
* Models Class.
*
* Simple loader class for MVC Models.
* Typically loads models from Application\Model unless otherwise specified.
* Typically, loads models from Application\Model unless otherwise specified.
*
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace FuzeWorks;
@ -54,7 +54,7 @@ class Router
*
* @var array
*/
protected $routes = [];
protected array $routes = [];
/**
* The current callable used
@ -68,10 +68,10 @@ class Router
*
* @var array|null
*/
protected $matches = null;
protected ?array $matches = null;
/**
* @var array|null
* @var array|Closure|null
*/
protected $routeData = null;
@ -80,36 +80,36 @@ class Router
*
* @var string|null
*/
protected $route = null;
protected ?string $route = null;
/**
* The current View
*
* @var View|null
*/
protected $view = null;
protected ?View $view = null;
/**
* The current Controller
*
* @var Controller|null
*/
protected $controller = null;
protected ?Controller $controller = null;
/**
* @var Config
*/
private $config;
private Config $config;
/**
* @var Controllers
*/
private $controllers;
private Controllers $controllers;
/**
* @var Views
*/
private $views;
private Views $views;
/**
* Router constructor.
@ -156,7 +156,7 @@ class Router
$routeConfig = ['callable' => [$this, 'defaultCallable']];
}
// Finally add the route
// Finally, add the route
$this->addRoute($route, $routeConfig);
}
}
@ -165,7 +165,7 @@ class Router
* Add a route to the Router
*
* @param string $route
* @param null $routeConfig
* @param mixed $routeConfig
* @param int $priority
*/
public function addRoute(string $route, $routeConfig = null, int $priority = Priority::NORMAL)
@ -174,14 +174,19 @@ class Router
if (is_null($routeConfig))
$routeConfig = ['callable' => [$this, 'defaultCallable']];
// Select the category
$category = is_array($routeConfig) && isset($routeConfig['category']) ? $routeConfig['category'] : 'default';
if (!isset($this->routes[$category]))
$this->routes[$category] = [];
// Convert wildcards to Regex
$route = str_replace([':any',':num'], ['[^/]+', '[0-9]+'], $route);
if (!isset($this->routes[$priority]))
$this->routes[$priority] = [];
if (!isset($this->routes[$category][$priority]))
$this->routes[$category][$priority] = [];
if (!isset($this->routes[$priority][$route]))
$this->routes[$priority][$route] = $routeConfig;
if (!isset($this->routes[$category][$priority][$route]))
$this->routes[$category][$priority][$route] = $routeConfig;
Logger::log('Route added with ' . Priority::getPriority($priority) . ": '" . $route."'");
}
@ -189,30 +194,33 @@ class Router
/**
* Removes a route from the array based on the given route.
*
* @param $route string The route to remove
* @param int $priority
* @param string $route The route to remove
* @param string $category The category to remove it from (defaults to 'default')
* @param int $priority The priority to remove it from (defaults to Priority::NORMAL)
*/
public function removeRoute(string $route, int $priority = Priority::NORMAL)
public function removeRoute(string $route, string $category = 'default', int $priority = Priority::NORMAL)
{
if (!isset($this->routes[$priority][$route]))
if (!isset($this->routes[$category][$priority][$route]))
return;
unset($this->routes[$priority][$route]);
unset($this->routes[$category][$priority][$route]);
Logger::log('Route removed: '.$route);
}
/**
* @param string $path
* @param array $routes Optional routes for not using the default
* @return mixed
* @throws NotFoundException
* @throws RouterException
* @throws HaltException
* @param string $path The string to route using Router
* @param string $category The category of routes to search in (defaults to 'default')
* @param array $routes Alternative routes if using global routes is not desired
* @return mixed The output of the callable
* @throws NotFoundException Thrown if route failed to deliver
* @throws RouterException Thrown if things fatally break
* @throws HaltException Thrown if route results in an unauthorised request
*/
public function route(string $path, array $routes = [])
public function route(string $path, string $category = 'default', array $routes = [])
{
// Select the routes to use
$routes = empty($routes) ? $this->routes : $routes;
$globalRoutes = $this->routes[$category] ?? [];
$routes = empty($routes) ? $globalRoutes : $routes;
// Check all the provided custom paths, ordered by priority
for ($i=Priority::getHighestPriority(); $i<=Priority::getLowestPriority(); $i++) {
@ -415,7 +423,7 @@ class Router
if (method_exists($this->view, $method))
{
// Execute this method on the view
Logger::newLevel("Calling method '{$method}' on " . get_class($this->view) . ' with ' . get_class($this->controller));
Logger::newLevel("Calling method '$method' on " . get_class($this->view) . ' with ' . get_class($this->controller));
$output = call_user_func_array([$this->view, $method], $event->viewParameters);
Logger::stopLevel();
return $output;
@ -433,13 +441,17 @@ class Router
/**
* Returns an array with all the routes.
*
* @param string $category
* @param int $priority
* @return array
* @codeCoverageIgnore
*/
public function getRoutes(int $priority = Priority::NORMAL): array
public function getRoutes(string $category = 'default', int $priority = Priority::NORMAL): array
{
return $this->routes[$priority];
if (isset($this->routes[$category][$priority]))
return $this->routes[$category][$priority];
return [];
}
/**
@ -448,7 +460,7 @@ class Router
* @return string|null
* @codeCoverageIgnore
*/
public function getCurrentRoute()
public function getCurrentRoute(): ?string
{
return $this->route;
}
@ -459,7 +471,7 @@ class Router
* @return null|array
* @codeCoverageIgnore
*/
public function getCurrentMatches()
public function getCurrentMatches(): ?array
{
return $this->matches;
}
@ -470,7 +482,7 @@ class Router
* @return View|null
* @codeCoverageIgnore
*/
public function getCurrentView()
public function getCurrentView(): ?View
{
return $this->view;
}
@ -481,7 +493,7 @@ class Router
* @return Controller|null
* @codeCoverageIgnore
*/
public function getCurrentController()
public function getCurrentController(): ?Controller
{
return $this->controller;
}

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace FuzeWorks;
@ -61,29 +61,29 @@ abstract class View
/**
* @var Plugins
*/
protected $plugins;
protected Plugins $plugins;
/**
* @var Libraries
*/
protected $libraries;
protected Libraries $libraries;
/**
* @var Helpers
*/
protected $helpers;
protected Helpers $helpers;
/**
* @var Config
*/
protected $config;
protected Config $config;
/**
* The controller associated with this view
*
* @var Controller
*/
protected $controller;
protected Controller $controller;
/**
* Provide the View with its associated Controller

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace FuzeWorks;
@ -44,7 +44,7 @@ use FuzeWorks\Exception\ViewException;
* Views Class.
*
* Simple loader class for MVC Views.
* Typically loads views from Application\View unless otherwise specified.
* Typically, loads views from Application\View unless otherwise specified.
*
* @author Abel Hoogeveen <abel@techfuze.net>
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
@ -130,7 +130,7 @@ class Views
// If the class already exists, return a new instance directly
$class = ucfirst($class);
$className = $namespace . $class . $viewType . 'View';
$className = $namespace . $class . ucfirst($viewType) . 'View';
if (class_exists($className, true)) {
/** @var View $view */
$view = new $className(...$arguments);

View File

@ -31,9 +31,11 @@
* @link http://techfuze.net/fuzeworks
* @since Version 0.0.1
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
use FuzeWorks\MVCRComponent;
require_once(dirname(__DIR__) . '/vendor/autoload.php');
$configurator = new FuzeWorks\Configurator();
@ -44,14 +46,11 @@ $configurator->setLogDirectory(dirname(__FILE__) . '/temp');
// Other values
$configurator->setTimeZone('Europe/Amsterdam');
$configurator->setDebugAddress('NONE');
$configurator->setDebugAddress();
// Implement the MVCR Component
$configurator->addComponent(new \FuzeWorks\MVCRComponent());
$configurator->addComponent(new MVCRComponent());
// Create container
$container = $configurator->createContainer();
// And return the result
return $container;
return $configurator->createContainer();

View File

@ -40,5 +40,5 @@ use FuzeWorks\Controller;
class TestDifferentComponentPathPriorityController extends Controller
{
public $type = 'highest';
public string $type = 'highest';
}

View File

@ -40,5 +40,5 @@ use FuzeWorks\Controller;
class TestDifferentComponentPathPriorityController extends Controller
{
public $type = 'lowest';
public string $type = 'lowest';
}

View File

@ -53,12 +53,12 @@ class ControllersTest extends TestCase
/**
* @var Controllers
*/
protected $controllers;
protected Controllers $controllers;
public function setUp(): void
{
$this->controllers = new Controllers();
$this->controllers->addComponentPath('controllers');
$this->controllers->addComponentPath(dirname(__DIR__) . DS . 'controllers');
}
/**
@ -171,8 +171,8 @@ class ControllersTest extends TestCase
public function testDifferentComponentPathPriority()
{
// Add the directories for this test
$this->controllers->addComponentPath('controllers'.DS.'TestDifferentComponentPathPriority'.DS.'Lowest', Priority::LOWEST);
$this->controllers->addComponentPath('controllers'.DS.'TestDifferentComponentPathPriority'.DS.'Highest', Priority::HIGHEST);
$this->controllers->addComponentPath(dirname(__DIR__) . DS . 'controllers'.DS.'TestDifferentComponentPathPriority'.DS.'Lowest', Priority::LOWEST);
$this->controllers->addComponentPath(dirname(__DIR__) . DS . 'controllers'.DS.'TestDifferentComponentPathPriority'.DS.'Highest', Priority::HIGHEST);
// Load the controller and assert it is the correct type
$controller = $this->controllers->get('TestDifferentComponentPathPriority');

View File

@ -54,12 +54,12 @@ class ModelsTest extends TestCase
/**
* @var Models
*/
protected $models;
protected Models $models;
public function setUp(): void
{
$this->models = new Models();
$this->models->addComponentPath('models');
$this->models->addComponentPath(dirname(__DIR__) . DS . 'models');
}
/**
@ -172,8 +172,8 @@ class ModelsTest extends TestCase
public function testDifferentComponentPathPriority()
{
// Add the directories for this test
$this->models->addComponentPath('models'.DS.'TestDifferentComponentPathPriority'.DS.'Lowest', Priority::LOWEST);
$this->models->addComponentPath('models'.DS.'TestDifferentComponentPathPriority'.DS.'Highest', Priority::HIGHEST);
$this->models->addComponentPath(dirname(__DIR__) . DS . 'models'.DS.'TestDifferentComponentPathPriority'.DS.'Lowest', Priority::LOWEST);
$this->models->addComponentPath(dirname(__DIR__) . DS . 'models'.DS.'TestDifferentComponentPathPriority'.DS.'Highest', Priority::HIGHEST);
// Load the model and assert it is the correct type
$model = $this->models->get('TestDifferentComponentPathPriority');

View File

@ -55,14 +55,14 @@ class RouterTest extends TestCase
*
* @var Router
*/
protected $router;
protected Router $router;
/**
* Holds the Config object
*
* @var Config
*/
protected $config;
protected Config $config;
public function setUp(): void
{
@ -71,8 +71,8 @@ class RouterTest extends TestCase
$this->config = Factory::getInstance()->config;
// Append required routes
Factory::getInstance()->controllers->addComponentPath('controllers');
Factory::getInstance()->views->addComponentPath('views');
Factory::getInstance()->controllers->addComponentPath(dirname(__DIR__) . DS . 'controllers');
Factory::getInstance()->views->addComponentPath(dirname(__DIR__) . DS . 'views');
}
/**
@ -139,10 +139,25 @@ class RouterTest extends TestCase
// Test if the order is correct
// First for Priority::NORMAL
$this->assertSame(['testRoute' => $testRouteFunction], $this->router->getRoutes(Priority::NORMAL));
$this->assertSame(['testRoute' => $testRouteFunction], $this->router->getRoutes('default', Priority::NORMAL));
// Then for Priority::LOW
$this->assertSame(['testAppendRoute' => $testAppendRouteFunction], $this->router->getRoutes(Priority::LOW));
$this->assertSame(['testAppendRoute' => $testAppendRouteFunction], $this->router->getRoutes('default', Priority::LOW));
}
/**
* @depends testAddRoutes
* @covers ::addRoute
* @covers ::getRoutes
*/
public function testRouteCategories()
{
$this->router->addRoute('defaultRoute', []);
$this->router->addRoute('defaultRoute2', ['category' => 'default']);
$this->router->addRoute('otherRoute', ['category' => 'other']);
$this->assertEquals(['defaultRoute' => [], 'defaultRoute2' => ['category' => 'default']], $this->router->getRoutes('default'));
$this->assertEquals(['otherRoute' => ['category' => 'other']], $this->router->getRoutes('other'));
}
/**
@ -154,13 +169,22 @@ class RouterTest extends TestCase
public function testRemoveRoutes()
{
// First add routes
$this->router->addRoute('testRemoveRoute', function () {
});
$this->router->addRoute('testRemoveRoute', function () {});
$this->assertArrayHasKey('testRemoveRoute', $this->router->getRoutes());
// Add a route with a category
$this->router->addRoute('categoryRoute', ['category' => 'other']);
$this->assertArrayHasKey('categoryRoute', $this->router->getRoutes('other'));
// Check if the categories do not cross
$this->assertArrayNotHasKey('testRemoveRoute', $this->router->getRoutes('other'));
$this->assertArrayNotHasKey('categoryRoute', $this->router->getRoutes('default'));
// Then remove
$this->router->removeRoute('testRemoveRoute');
$this->assertArrayNotHasKey('testRemoveRoute', $this->router->getRoutes());
$this->router->removeRoute('categoryRoute', 'other');
$this->assertArrayNotHasKey('categoryRoute', $this->router->getRoutes('other'));
}
/**
@ -496,7 +520,7 @@ class RouterTest extends TestCase
class_alias(get_class($mockController), '\Application\Controller\TestDistinctRouteController');
class_alias(get_class($mockView), '\Application\View\TestDistinctRouteTestView');
$this->assertNull($this->router->route('testDistinctRoute/testMethod/testParameters.test', [
$this->assertNull($this->router->route('testDistinctRoute/testMethod/testParameters.test', 'default', [
3 => [
'(?P<viewName>.*?)(|\/(?P<viewMethod>.*?)(|\/(?P<viewParameters>.*?))).test' => ['viewType' => 'test']
]

View File

@ -55,7 +55,7 @@ class ViewsTest extends TestCase
/**
* @var Views
*/
protected $views;
protected Views $views;
/**
* @var Controller
@ -65,7 +65,7 @@ class ViewsTest extends TestCase
public function setUp(): void
{
$this->views = new Views();
$this->views->addComponentPath('views');
$this->views->addComponentPath(dirname(__DIR__) . DS . 'views');
$this->mockController = $this->getMockBuilder(Controller::class)->getMock();
}
@ -179,8 +179,8 @@ class ViewsTest extends TestCase
public function testDifferentComponentPathPriority()
{
// Add the directories for this test
$this->views->addComponentPath('views'.DS.'TestDifferentComponentPathPriority'.DS.'Lowest', Priority::LOWEST);
$this->views->addComponentPath('views'.DS.'TestDifferentComponentPathPriority'.DS.'Highest', Priority::HIGHEST);
$this->views->addComponentPath(dirname(__DIR__) . DS . 'views'.DS.'TestDifferentComponentPathPriority'.DS.'Lowest', Priority::LOWEST);
$this->views->addComponentPath(dirname(__DIR__) . DS . 'views'.DS.'TestDifferentComponentPathPriority'.DS.'Highest', Priority::HIGHEST);
// Load the view and assert it is the correct type
$view = $this->views->get('TestDifferentComponentPathPriority', $this->mockController);

View File

@ -40,5 +40,5 @@ use FuzeWorks\Model;
class TestDifferentComponentPathPriorityModel extends Model
{
public $type = 'highest';
public string $type = 'highest';
}

View File

@ -40,5 +40,5 @@ use FuzeWorks\Model;
class TestDifferentComponentPathPriorityModel extends Model
{
public $type = 'lowest';
public string $type = 'lowest';
}

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace Application\View;
@ -40,5 +40,5 @@ use FuzeWorks\View;
class TestDifferentComponentPathPriorityStandardView extends View
{
public $type = 'highest';
public string $type = 'highest';
}

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace Application\View;
@ -40,5 +40,5 @@ use FuzeWorks\View;
class TestDifferentComponentPathPriorityStandardView extends View
{
public $type = 'lowest';
public string $type = 'lowest';
}

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace Application\View;
@ -41,7 +41,7 @@ use FuzeWorks\View;
class TestDefaultCallableTestView extends View
{
public function someMethod()
public function someMethod(): string
{
return "Verify Output";
}

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace Application\View;
@ -40,12 +40,12 @@ use FuzeWorks\View;
class TestDefaultCallableChangeMethodTestView extends View
{
public function index()
public function index(): string
{
return "Not altered!";
}
public function altered(string $param1, string $param2)
public function altered(string $param1, string $param2): array
{
return ["Altered", $param1, $param2];
}

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace Custom\View;
@ -41,7 +41,7 @@ use FuzeWorks\View;
class TestDefaultCallableCustomNamespaceTestView extends View
{
public function someMethod()
public function someMethod(): string
{
return "Verify Output, with custom namespace!";
}

View File

@ -31,7 +31,7 @@
* @link http://techfuze.net/fuzeworks
* @since Version 1.2.0
*
* @version Version 1.2.0
* @version Version 1.3.3
*/
namespace Application\View;
@ -40,6 +40,6 @@ use FuzeWorks\View;
class TestDefaultCallableHaltTestView extends View
{
public $halt = true;
public bool $halt = true;
}