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.

87 lines
2.2 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/autoload.php';
  10. require_once __DIR__.'/classes/User.php';
  11. class RegisterTest extends PHPUnit_Framework_TestCase
  12. {
  13. /**
  14. * @var \flight\Engine
  15. */
  16. private $app;
  17. function setUp() {
  18. $this->app = new \flight\Engine();
  19. }
  20. // Register a class
  21. function testRegister(){
  22. $this->app->register('reg1', 'User');
  23. $user = $this->app->reg1();
  24. $this->assertTrue(is_object($user));
  25. $this->assertEquals('User', get_class($user));
  26. $this->assertEquals('', $user->name);
  27. }
  28. // Register a class with constructor parameters
  29. function testRegisterWithConstructor(){
  30. $this->app->register('reg2', 'User', array('Bob'));
  31. $user = $this->app->reg2();
  32. $this->assertTrue(is_object($user));
  33. $this->assertEquals('User', get_class($user));
  34. $this->assertEquals('Bob', $user->name);
  35. }
  36. // Register a class with initialization
  37. function testRegisterWithInitialization(){
  38. $this->app->register('reg3', 'User', array('Bob'), function($user){
  39. $user->name = 'Fred';
  40. });
  41. $user = $this->app->reg3();
  42. $this->assertTrue(is_object($user));
  43. $this->assertEquals('User', get_class($user));
  44. $this->assertEquals('Fred', $user->name);
  45. }
  46. // Get a non-shared instance of a class
  47. function testSharedInstance() {
  48. $this->app->register('reg4', 'User');
  49. $user1 = $this->app->reg4();
  50. $user2 = $this->app->reg4();
  51. $user3 = $this->app->reg4(false);
  52. $this->assertTrue($user1 === $user2);
  53. $this->assertTrue($user1 !== $user3);
  54. }
  55. // Map method takes precedence over register
  56. function testMapOverridesRegister(){
  57. $this->app->register('reg5', 'User');
  58. $user = $this->app->reg5();
  59. $this->assertTrue(is_object($user));
  60. $this->app->map('reg5', function(){
  61. return 123;
  62. });
  63. $user = $this->app->reg5();
  64. $this->assertEquals(123, $user);
  65. }
  66. }