1
Guys I’m starting with Phpunit, I’m implementing the first tests in my applications but I’m with the following doubt.
All classes should actually be tested, or there are some exceptions, if yes which are?
For example. I have an MVC structure that implements a route system with the following classes:
abstract class Bootstrap
{
private $routes;
public function __construct()
{
$this->initRoutes();
$this->run($this->getUrl());
}
abstract protected function initRoutes();
protected function run($url)
{
array_walk($this->routes, function($route) use ($url){
if($url == $route['route']){
$class = "App\\Controllers\\".ucfirst($route['controller']);
$controller = new $class;
$action = $route['action'];
$controller->$action();
}
});
}
protected function setRoutes(array $routes)
{
$this->routes = $routes;
}
protected function getUrl()
{
return parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
}
}
and...
class Route extends Bootstrap
{
protected function initRoutes()
{
$routes['home'] = array(
'route' =>'/',
'controller'=>'indexController',
'action' =>'index'
);
// Mais rotas..
$this->setRoutes($routes);
}
}
Do these classes really need to be tested?. If so, how can I implement these tests. Any examples? Something you can read? I did a lot of research but I couldn’t find anything to solve that question.
These classes are from some framework or you have implemented?
– Renan Oliveira
It is a microframework developed for studies!
– wDrik