Boilerplate to use a Directus Instance to Build a Custom Website, Content will be Manage by Directus
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.1 KiB

5 years ago
  1. <?php
  2. /**
  3. * Flight: An extensible micro-framework.
  4. *
  5. * @copyright Copyright (c) 2012, Mike Cao <mike@mikecao.com>
  6. * @license MIT, http://flightphp.com/license
  7. */
  8. require_once 'vendor/autoload.php';
  9. require_once __DIR__.'/../flight/Flight.php';
  10. class FlightTest extends PHPUnit_Framework_TestCase
  11. {
  12. function setUp() {
  13. Flight::init();
  14. }
  15. // Checks that default components are loaded
  16. function testDefaultComponents(){
  17. $request = Flight::request();
  18. $response = Flight::response();
  19. $router = Flight::router();
  20. $view = Flight::view();
  21. $this->assertEquals('flight\net\Request', get_class($request));
  22. $this->assertEquals('flight\net\Response', get_class($response));
  23. $this->assertEquals('flight\net\Router', get_class($router));
  24. $this->assertEquals('flight\template\View', get_class($view));
  25. }
  26. // Test get/set of variables
  27. function testGetAndSet(){
  28. Flight::set('a', 1);
  29. $var = Flight::get('a');
  30. $this->assertEquals(1, $var);
  31. Flight::clear();
  32. $vars = Flight::get();
  33. $this->assertEquals(0, count($vars));
  34. Flight::set('a', 1);
  35. Flight::set('b', 2);
  36. $vars = Flight::get();
  37. $this->assertEquals(2, count($vars));
  38. $this->assertEquals(1, $vars['a']);
  39. $this->assertEquals(2, $vars['b']);
  40. }
  41. // Register a class
  42. function testRegister(){
  43. Flight::path(__DIR__.'/classes');
  44. Flight::register('user', 'User');
  45. $user = Flight::user();
  46. $loaders = spl_autoload_functions();
  47. $this->assertTrue(sizeof($loaders) > 0);
  48. $this->assertTrue(is_object($user));
  49. $this->assertEquals('User', get_class($user));
  50. }
  51. // Map a function
  52. function testMap(){
  53. Flight::map('map1', function(){
  54. return 'hello';
  55. });
  56. $result = Flight::map1();
  57. $this->assertEquals('hello', $result);
  58. }
  59. // Unmapped method
  60. function testUnmapped() {
  61. $this->setExpectedException('Exception', 'doesNotExist must be a mapped method.');
  62. Flight::doesNotExist();
  63. }
  64. }