Simplified tests

pull/532/head
fadrian06 1 year ago
parent 0eac13f4fa
commit 8d6d0f08da

@ -1,20 +1,13 @@
<?php <?php
/** declare(strict_types=1);
* Flight: An extensible micro-framework.
*
* @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com>
* @license MIT, http://flightphp.com/license
*/
use flight\Engine; use flight\Engine;
use PHPUnit\Framework\TestCase;
class AutoloadTest extends PHPUnit\Framework\TestCase class AutoloadTest extends TestCase
{ {
/** private Engine $app;
* @var Engine
*/
private $app;
protected function setUp(): void protected function setUp(): void
{ {

@ -1,21 +1,17 @@
<?php <?php
/** declare(strict_types=1);
* Flight: An extensible micro-framework.
* use flight\util\Collection;
* @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com> use PHPUnit\Framework\TestCase;
* @license MIT, http://flightphp.com/license
*/ class CollectionTest extends TestCase
class CollectionTest extends PHPUnit\Framework\TestCase
{ {
/** private Collection $collection;
* @var \flight\util\Collection
*/
private $collection;
protected function setUp(): void protected function setUp(): void
{ {
$this->collection = new \flight\util\Collection(['a' => 1, 'b' => 2]); $this->collection = new Collection(['a' => 1, 'b' => 2]);
} }
// Get an item // Get an item

@ -1,19 +1,12 @@
<?php <?php
/** declare(strict_types=1);
* Flight: An extensible micro-framework.
*
* @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com>
* @license MIT, http://flightphp.com/license
*/
use flight\core\Dispatcher; use flight\core\Dispatcher;
use PHPUnit\Framework\TestCase;
class DispatcherTest extends PHPUnit\Framework\TestCase class DispatcherTest extends TestCase
{ {
/**
* @var Dispatcher|null
*/
private Dispatcher $dispatcher; private Dispatcher $dispatcher;
protected function setUp(): void protected function setUp(): void
@ -131,7 +124,7 @@ class DispatcherTest extends PHPUnit\Framework\TestCase
return "Hello, $name!"; return "Hello, $name!";
}); });
$this->dispatcher->hook('hello', 'before', function (&$params, &$output) { $this->dispatcher->hook('hello', 'before', function (&$params) {
// Manipulate the parameter // Manipulate the parameter
$params[0] = 'Fred'; $params[0] = 'Fred';
}); });

@ -1,11 +1,6 @@
<?php <?php
/** declare(strict_types=1);
* Flight: An extensible micro-framework.
*
* @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com>
* @license MIT, http://flightphp.com/license
*/
use flight\Engine; use flight\Engine;
use flight\net\Response; use flight\net\Response;
@ -263,7 +258,7 @@ class EngineTest extends TestCase
$this->assertEquals(200, $engine->response()->status()); $this->assertEquals(200, $engine->response()->status());
} }
public function testJsonPBadParam() public function testJsonpBadParam()
{ {
$engine = new Engine(); $engine = new Engine();
$engine->jsonp(['key1' => 'value1', 'key2' => 'value2']); $engine->jsonp(['key1' => 'value1', 'key2' => 'value2']);

@ -1,20 +1,13 @@
<?php <?php
/** declare(strict_types=1);
* Flight: An extensible micro-framework.
*
* @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com>
* @license MIT, http://flightphp.com/license
*/
use flight\Engine; use flight\Engine;
use PHPUnit\Framework\TestCase;
class FilterTest extends PHPUnit\Framework\TestCase class FilterTest extends TestCase
{ {
/** private Engine $app;
* @var Engine
*/
private $app;
protected function setUp(): void protected function setUp(): void
{ {
@ -28,7 +21,7 @@ class FilterTest extends PHPUnit\Framework\TestCase
return "Hello, $name!"; return "Hello, $name!";
}); });
$this->app->before('hello', function (&$params, &$output) { $this->app->before('hello', function (&$params) {
// Manipulate the parameter // Manipulate the parameter
$params[0] = 'Fred'; $params[0] = 'Fred';
}); });
@ -50,15 +43,15 @@ class FilterTest extends PHPUnit\Framework\TestCase
return "Bye, $name!"; return "Bye, $name!";
}); });
$this->app->before('bye', function (&$params, &$output) { $this->app->before('bye', function (&$params) {
$params[0] = 'Bob'; $params[0] = 'Bob';
}); });
$this->app->before('bye', function (&$params, &$output) { $this->app->before('bye', function (&$params) {
$params[0] = 'Fred'; $params[0] = 'Fred';
return false; return false;
}); });
$this->app->before('bye', function (&$params, &$output) { $this->app->before('bye', function (&$params) {
$params[0] = 'Ted'; $params[0] = 'Ted';
}); });

@ -1,18 +1,15 @@
<?php <?php
declare(strict_types=1);
use flight\Engine; use flight\Engine;
use flight\net\Request; use flight\net\Request;
use flight\net\Response; use flight\net\Response;
use flight\net\Router; use flight\net\Router;
use flight\template\View; use flight\template\View;
use PHPUnit\Framework\TestCase;
/** class FlightTest extends TestCase
* Flight: An extensible micro-framework.
*
* @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com>
* @license MIT, http://flightphp.com/license
*/
class FlightTest extends PHPUnit\Framework\TestCase
{ {
protected function setUp(): void protected function setUp(): void
{ {
@ -79,11 +76,11 @@ class FlightTest extends PHPUnit\Framework\TestCase
self::assertIsObject($user); self::assertIsObject($user);
self::assertInstanceOf(User::class, $user); self::assertInstanceOf(User::class, $user);
Flight::unregister('user'); Flight::unregister('user');
self::expectException(Exception::class); self::expectException(Exception::class);
self::expectExceptionMessage('user must be a mapped method.'); self::expectExceptionMessage('user must be a mapped method.');
$user = Flight::user(); $user = Flight::user();
} }
// Map a function // Map a function

@ -1,11 +1,6 @@
<?php <?php
/** declare(strict_types=1);
* Flight: An extensible micro-framework.
*
* @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com>
* @license MIT, http://flightphp.com/license
*/
use flight\core\Loader; use flight\core\Loader;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;

@ -1,11 +1,6 @@
<?php <?php
/** declare(strict_types=1);
* Flight: An extensible micro-framework.
*
* @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com>
* @license MIT, http://flightphp.com/license
*/
use flight\Engine; use flight\Engine;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;

@ -1,22 +1,13 @@
<?php <?php
use flight\database\PdoWrapper; declare(strict_types=1);
/**
* Flight: An extensible micro-framework.
*
* @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com>
* @license MIT, http://flightphp.com/license
*/
use flight\database\PdoWrapper;
use PHPUnit\Framework\TestCase;
class PdoWrapperTest extends PHPUnit\Framework\TestCase class PdoWrapperTest extends TestCase
{ {
/** private PdoWrapper $pdo_wrapper;
* @var Pdo_Wrapper
*/
private $pdo_wrapper;
protected function setUp(): void protected function setUp(): void
{ {

@ -1,15 +1,11 @@
<?php <?php
/** declare(strict_types=1);
* Flight: An extensible micro-framework.
*
* @copyright Copyright (c) 2013, Mike Cao <mike@mikecao.com>
* @license MIT, http://flightphp.com/license
*/
use flight\Engine; use flight\Engine;
use PHPUnit\Framework\TestCase;
class RedirectTest extends PHPUnit\Framework\TestCase class RedirectTest extends TestCase
{ {
private Engine $app; private Engine $app;

@ -1,11 +1,6 @@
<?php <?php
/** declare(strict_types=1);
* Flight: An extensible micro-framework.
*
* @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com>
* @license MIT, http://flightphp.com/license
*/
use flight\Engine; use flight\Engine;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;

@ -1,15 +1,11 @@
<?php <?php
/** declare(strict_types=1);
* Flight: An extensible micro-framework.
*
* @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com>
* @license MIT, http://flightphp.com/license
*/
use flight\Engine; use flight\Engine;
use PHPUnit\Framework\TestCase;
class RenderTest extends PHPUnit\Framework\TestCase class RenderTest extends TestCase
{ {
private Engine $app; private Engine $app;

@ -1,16 +1,12 @@
<?php <?php
/** declare(strict_types=1);
* Flight: An extensible micro-framework.
*
* @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com>
* @license MIT, http://flightphp.com/license
*/
use flight\net\Request; use flight\net\Request;
use flight\util\Collection; use flight\util\Collection;
use PHPUnit\Framework\TestCase;
class RequestTest extends PHPUnit\Framework\TestCase class RequestTest extends TestCase
{ {
private Request $request; private Request $request;

@ -1,17 +1,13 @@
<?php <?php
/** declare(strict_types=1);
* Flight: An extensible micro-framework.
*
* @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com>
* @license MIT, http://flightphp.com/license
*/
use flight\net\Request; use flight\net\Request;
use flight\net\Response; use flight\net\Response;
use flight\util\Collection; use flight\util\Collection;
use PHPUnit\Framework\TestCase;
class ResponseTest extends PHPUnit\Framework\TestCase class ResponseTest extends TestCase
{ {
protected function setUp(): void protected function setUp(): void
{ {
@ -177,7 +173,7 @@ class ResponseTest extends PHPUnit\Framework\TestCase
'max-age=0', 'max-age=0',
] ]
]; ];
public function setRealHeader(string $header_string, bool $replace = true, int $response_code = 0): Response public function setRealHeader(string $header_string, bool $replace = true, int $response_code = 0): self
{ {
$this->test_sent_headers[] = $header_string; $this->test_sent_headers[] = $header_string;
return $this; return $this;
@ -216,7 +212,7 @@ class ResponseTest extends PHPUnit\Framework\TestCase
$response = new class extends Response { $response = new class extends Response {
protected $test_sent_headers = []; protected $test_sent_headers = [];
public function setRealHeader(string $header_string, bool $replace = true, int $response_code = 0): Response public function setRealHeader(string $header_string, bool $replace = true, int $response_code = 0): self
{ {
$this->test_sent_headers[] = $header_string; $this->test_sent_headers[] = $header_string;
return $this; return $this;

@ -1,17 +1,13 @@
<?php <?php
/** declare(strict_types=1);
* Flight: An extensible micro-framework.
*
* @copyright Copyright (c) 2011, Mike Cao <mike@mikecao.com>
* @license MIT, http://flightphp.com/license
*/
use flight\core\Dispatcher; use flight\core\Dispatcher;
use flight\net\Request; use flight\net\Request;
use flight\net\Router; use flight\net\Router;
use PHPUnit\Framework\TestCase;
class RouterTest extends PHPUnit\Framework\TestCase class RouterTest extends TestCase
{ {
private Router $router; private Router $router;
@ -43,15 +39,14 @@ class RouterTest extends PHPUnit\Framework\TestCase
// Checks if a route was matched with a given output // Checks if a route was matched with a given output
public function check($str = '') public function check($str = '')
{ {
/*
$route = $this->router->route($this->request); /*$route = $this->router->route($this->request);
$params = array_values($route->params); $params = array_values($route->params);
$this->assertTrue(is_callable($route->callback)); $this->assertTrue(is_callable($route->callback));
call_user_func_array($route->callback, $params); call_user_func_array($route->callback, $params);*/
*/
$this->routeRequest(); $this->routeRequest();
$this->expectOutputString($str); $this->expectOutputString($str);

@ -1,21 +1,17 @@
<?php <?php
/** declare(strict_types=1);
* Flight: An extensible micro-framework.
* use flight\Engine;
* @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com> use PHPUnit\Framework\TestCase;
* @license MIT, http://flightphp.com/license
*/ class VariableTest extends TestCase
class VariableTest extends PHPUnit\Framework\TestCase
{ {
/** private Engine $app;
* @var \flight\Engine
*/
private $app;
protected function setUp(): void protected function setUp(): void
{ {
$this->app = new \flight\Engine(); $this->app = new Engine();
} }
// Set and get a variable // Set and get a variable

@ -1,5 +1,7 @@
<?php <?php
declare(strict_types=1);
use flight\template\View; use flight\template\View;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -117,7 +119,7 @@ class ViewTest extends TestCase
$this->assertEquals('&lt;script&gt;', $result); $this->assertEquals('&lt;script&gt;', $result);
} }
public function testENoNeedToEscape() public function testeNoNeedToEscape()
{ {
$this->expectOutputString('script'); $this->expectOutputString('script');
$result = $this->view->e('script'); $result = $this->view->e('script');

@ -1,6 +1,9 @@
<?php <?php
declare(strict_types=1);
$path = file_exists(__DIR__ . '/../vendor/autoload.php') $path = file_exists(__DIR__ . '/../vendor/autoload.php')
? __DIR__ . '/../vendor/autoload.php' ? __DIR__ . '/../vendor/autoload.php'
: __DIR__ . '/../flight/autoload.php'; : __DIR__ . '/../flight/autoload.php';
require_once($path); require_once($path);

Loading…
Cancel
Save