1. Go to this page and download the library: Download emeset/test library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
emeset / test example snippets
use Emeset\Test\TestCase;
class ExempleTest extends TestCase
{
public function test_exemple()
{
$request = $this->makeRequest($get, $post, $session);
$response = $this->makeResponse();
// ...
}
}
// Carrega l'autoload de Composer (Emeset, el teu projecte, etc.)
G=1');
// Zona horària per evitar avisos
date_default_timezone_set('Europe/Madrid');
use PHPUnit\Framework\TestCase;
class SmokeTest extends TestCase
{
public function test_phpunit_funciona()
{
$this->assertTrue(true);
}
}
namespace Tests\Controllers;
use Emeset\Test\TestCase;
use App\Controllers\Portada;
class PortadaControllerTest extends TestCase
{
public function test_index()
{
$request = $this->makeRequest($get, $post, $session);
$response = $this->makeResponse();
$controller = new Portada();
$response = $controller->index($request, $response, $this->container);
// Asserts aquí...
}
}
$this->container // Contenidor del projecte
$this->makeRequest($get, $post, $session) // Obté una Request del contenidor passem un array per get, post i ssession per inicialitzar els valors.
$this->makeResponse() // Obté una Response del contenidor
use Emeset\Test\TestCase;
use App\Controllers\Portada;
use Emeset\Views\ViewsPHP;
class ExamplePortadaControllerTest extends TestCase
{
public function test_index_carrega_la_plantilla_portada()
{
$request = $this->makeRequest();
$response = $this->makeResponse();
$controller = new Portada();
$response = $controller->index($request, $response, $this->container);
$view = $response->getView();
$this->assertSame('portada.php', $view->getTemplate());
}
}
$app = new \Emeset\Emeset($contenidor);
$app->middleware([\App\Middleware\App::class, "execute"]);
/* Definim les rutes de la nostra aplicació */
$app->get("", [\App\Controllers\Portada::class, "index"]);
$app->get("login", [\App\Controllers\Login::class, "login"]);
$app->post("validar-login", [\App\Controllers\Login::class, "validarLogin"]);
$app->get("privat", [\App\Controllers\Privat::class, "privat"], ["auth"]);
$app->get("tancar-sessio", [\App\Controllers\Login::class, "tancarSessio"], ["auth"]);
$app->get("ajax", function ($request, $response) {
$response->set("result", "ok");
return $response;
});
$app->get("/hola/{id}", function ($request, $response) {
$id = $request->getParam("id");
$response->setBody("Hola {$id}!");
return $response;
});
$app->route(\Emeset\Router::DEFAULT_ROUTE, "ctrlError");
$app->execute();