Skip to content

Commit

Permalink
#79 fix testUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
bfoujols committed May 6, 2024
1 parent 55ff907 commit e83bc30
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 19 deletions.
4 changes: 4 additions & 0 deletions app/Config/routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
home:
uri: /home
controller: Controller\HomeController
httpMethod: [GET]
23 changes: 23 additions & 0 deletions app/Controller/HomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Controller;

use Studoo\EduFramework\Core\Controller\ControllerInterface;
use Studoo\EduFramework\Core\Controller\Request;
use Studoo\EduFramework\Core\View\TwigCore;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;

class HomeController implements ControllerInterface
{
public function execute(Request $request): string|null
{
return TwigCore::getEnvironment()->render('home/home.html.twig',
[
"titre" => 'HomeController',
"request" => $request
]
);
}
}
7 changes: 7 additions & 0 deletions app/Template/home/home.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "base.html.twig" %}

{% block title %}{{ titre }}{% endblock %}

{% block content %}
<h1>{{ titre }}</h1>
{% endblock %}
4 changes: 2 additions & 2 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ services:
restart: always
environment:
MYSQL_DATABASE: app_db
#MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_ROOT_PASSWORD: root
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
#MYSQL_ROOT_PASSWORD: root
#MYSQL_USER: app_db_user
#MYSQL_PASSWORD: app_db_password
volumes:
Expand Down
17 changes: 8 additions & 9 deletions src/EduFramework/Core/Controller/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,31 @@

class Route
{

/**
* Chemin du fichier de configuration des routes
*/
private const ROUTE_FILE_PATH = './app/Config/';

/**
* @var array $listRoutes Tableau contenant les informations des routes
* @var array<mixed> $listRoutes Tableau contenant les informations des routes
*/
private array $listRoutes = [];

/**
* Récupère le nom de la route et les paramètres pour renvoyer le chemin de la route
* @param string $name Nom de la route à récupérer dans le fichier config/routes.yaml
* @param array $param Tableau associatif des paramètres de la route
* @param array<mixed> $param Tableau associatif des paramètres de la route
* @return string URL
* @throws ParseException
* @throws BadRouteException
* @throws ParseException
* @throws BadRouteException
*/
public function getNameToPath(string $name, array $param = []): string
{
if (count($this->listRoutes) === 0) {
$this->getRouteInfo();
}
if (array_key_exists($name, $this->listRoutes)) {
$url = "";
$url = "";
foreach ($this->listRoutes[$name]["uri_parse"][0] as $uri) {
if (is_string($uri)) {
$url .= $uri;
Expand All @@ -54,14 +53,14 @@ public function getNameToPath(string $name, array $param = []): string
}
}
return $url;
}
}
throw new BadRouteException("La route $name n'existe pas");
}


/**
* Renseigne et renvoi un tableau contenant les informations des route du fichier config/routes.yaml
* @return array Tableau contenant les informations des routes
* @return array<mixed> Tableau contenant les informations des routes
*/
public function getRouteInfo(): array
{
Expand All @@ -76,7 +75,7 @@ public function getRouteInfo(): array
/**
* Récupération du fichier config/routes.yaml
* @param string $pathConfigFile
* @return array|bool Tableau des routes ou false si le fichier n'existe pas
* @return array<mixed>|bool Tableau des routes ou false si le fichier n'existe pas
*/
public function loadRoute(string $pathConfigFile): array|bool
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Command/AppCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public function testCommandDefault(): void
$commandeTester->execute([]);
$output = $commandeTester->getDisplay();

$this->assertStringContainsString('Liste des commandes :', $output);
$this->assertStringContainsString('Liste :', $output);
}
}
14 changes: 7 additions & 7 deletions tests/Controller/FastRouteCoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testGetDispatcher()

$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/';
$this->assertEquals('ae6360270b7dcefbf34d532945857ce80db09501', sha1($route->getRoute()));
$this->assertEquals('d7045e6af8910d38af6c42f0b610e51c644e5ec1', sha1($route->getRoute()));
}

public function testGetDispatcherWithExceptionNotFound()
Expand All @@ -37,7 +37,7 @@ public function testGetDispatcherWithExceptionNotFound()

$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/test';
$this->assertEquals('f2bb0fc64c96efcc763fa677baf54f160448f7c0', sha1($route->getRoute()));
$this->assertEquals('1ab50275de77fa6215e882b0833350c32cfcd7a2', sha1($route->getRoute()));
}

public function testGetDispatcherWithExceptionMethodNotAllowed()
Expand All @@ -47,7 +47,7 @@ public function testGetDispatcherWithExceptionMethodNotAllowed()

$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REQUEST_URI'] = '/';
$this->assertEquals('b66101b47494d181b51cf0bf2f6988e40ab2e95f', sha1($route->getRoute()));
$this->assertEquals('ed2ad24f02864b53319ab611d414ceac5c322751', sha1($route->getRoute()));
}

public function testGetDispatcherWithExceptionMethodNotAllowedAndNotFound()
Expand All @@ -57,7 +57,7 @@ public function testGetDispatcherWithExceptionMethodNotAllowedAndNotFound()

$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REQUEST_URI'] = '/test';
$this->assertEquals('f2bb0fc64c96efcc763fa677baf54f160448f7c0', sha1($route->getRoute()));
$this->assertEquals('1ab50275de77fa6215e882b0833350c32cfcd7a2', sha1($route->getRoute()));
}

public function testLoadRoutesMatchSuccess()
Expand All @@ -67,7 +67,7 @@ public function testLoadRoutesMatchSuccess()

$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/';
$this->assertEquals('ae6360270b7dcefbf34d532945857ce80db09501', sha1($route->getRoute()));
$this->assertEquals('d7045e6af8910d38af6c42f0b610e51c644e5ec1', sha1($route->getRoute()));
}

public function testLoadRoutesMatchSuccessWithExceptionNotFound()
Expand All @@ -77,7 +77,7 @@ public function testLoadRoutesMatchSuccessWithExceptionNotFound()

$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/test';
$this->assertEquals('f2bb0fc64c96efcc763fa677baf54f160448f7c0', sha1($route->getRoute()));
$this->assertEquals('1ab50275de77fa6215e882b0833350c32cfcd7a2', sha1($route->getRoute()));
}

public function testLoadRoutesMatchSuccessWithExceptionMethodNotAllowedAndNotFound()
Expand All @@ -87,6 +87,6 @@ public function testLoadRoutesMatchSuccessWithExceptionMethodNotAllowedAndNotFou

$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REQUEST_URI'] = '/';
$this->assertEquals('b66101b47494d181b51cf0bf2f6988e40ab2e95f', sha1($route->getRoute()));
$this->assertEquals('ed2ad24f02864b53319ab611d414ceac5c322751', sha1($route->getRoute()));
}
}

0 comments on commit e83bc30

Please sign in to comment.