Exemplo n.º 1
0
 /**
  * @param Request       $request
  * @param Response      $response
  * @param callable|NULL $next
  *
  * @return Response
  */
 public function __invoke(Request $request, Response $response, callable $next = NULL)
 {
     $elapsed_time = elapsed_time_since_request();
     $response->getBody()->write("<div>Elapsed time : {$elapsed_time}</div>" . PHP_EOL);
     // delegate to parent
     return parent::__invoke($request, $response, $next);
 }
Exemplo n.º 2
0
 public function test_DI()
 {
     $di = $this->forge;
     $this->assertTrue($di->container() instanceof IlluminateContainer);
     $this->assertTrue(forge('ioc') instanceof IlluminateContainer);
     $this->assertTrue(forge('forge') instanceof Forge);
     $this->assertTrue(forge('Og\\Forge') instanceof Forge);
     # tests singleton with closure
     $di->singleton('speck', function () {
         return 'speck';
     });
     $this->assertEquals('speck', $di['speck']);
     $di->shared('elapsed_time_since_request', function () {
         return elapsed_time_since_request();
     });
     $this->assertStringEndsWith('ms', $di->offsetGet('elapsed_time_since_request'));
     # note that the first argument to the function is always the DI
     # although we are not using it in this example
     $di->add('add_values', function ($di, array $params) {
         if ($di instanceof IlluminateContainer) {
             return $params[0] + $params[1];
         } else {
             return NULL;
         }
     });
     $this->assertTrue($di->offsetExists('add_values'));
     $this->assertEquals(15, $di->get('add_values', [5, 10]));
 }
Exemplo n.º 3
0
 public function test_ContextEvents()
 {
     $context = $this->context;
     forge('events')->on('context.test.event', function (Context $context) {
         $context->thaw();
         $context['test.event'] = elapsed_time_since_request(TRUE);
     });
     forge('events')->notify('context.test.event', $context);
 }
Exemplo n.º 4
0
 /**
  * Middleware listener/
  *
  * @param          $class
  * @param Request  $request
  * @param Response $response
  *
  * @internal param Context $context
  */
 function middlewareSnooper($class, $request, $response)
 {
     static $count = 0;
     $this->kernel->context()->set('application.spy_middleware.fired', ++$count);
     $this->kernel->context()->set('application.spy_middleware.request_query', $request->getUri());
     $et = elapsed_time_since_request();
     $class = (new \ReflectionClass($class))->getShortName();
     $response->getBody()->write("<div><b>{$class}</b> middleware event fired @<b>{$et}</b></div>" . PHP_EOL);
 }
Exemplo n.º 5
0
 public function test01()
 {
     ### elapsed_time_since_request()
     $now = elapsed_time_since_request(TRUE);
     $this->assertGreaterThan($now, elapsed_time_since_request(TRUE));
     $this->assertStringEndsWith('ms', elapsed_time_since_request());
     $this->assertStringEndsNotWith('ms', (string) elapsed_time_since_request(TRUE));
     ### location_from_backtrace($index = 2)
     # The current location should be the call to ReflectionMethod.
     # Be aware that this may change if PHPUnit alters its execution pipeline.
     $this->assertStringEndsWith('ReflectionMethod::invokeArgs', location_from_backtrace());
     ### expose($value = NULL, $depth = 8)
     # these functions would otherwise halt the tests, so output is restricted
     # by use of the PHPUNIT_TESTS constant. The best we can do (until I find
     # another solution) is to call them for code coverage.
     //expose("expose test");
     //die_dump('die_dump test');
     ### readable_error_type($error_type)
     #@formatter:off
     $this->assertEquals('E_COMPILE_ERROR', readable_error_type(E_COMPILE_ERROR));
     $this->assertEquals('E_COMPILE_WARNING', readable_error_type(E_COMPILE_WARNING));
     $this->assertEquals('E_CORE_ERROR', readable_error_type(E_CORE_ERROR));
     $this->assertEquals('E_CORE_WARNING', readable_error_type(E_CORE_WARNING));
     $this->assertEquals('E_DEPRECATED', readable_error_type(E_DEPRECATED));
     $this->assertEquals('E_ERROR', readable_error_type(E_ERROR));
     $this->assertEquals('E_NOTICE', readable_error_type(E_NOTICE));
     $this->assertEquals('E_PARSE', readable_error_type(E_PARSE));
     $this->assertEquals('E_RECOVERABLE_ERROR', readable_error_type(E_RECOVERABLE_ERROR));
     $this->assertEquals('E_STRICT', readable_error_type(E_STRICT));
     $this->assertEquals('E_USER_DEPRECATED', readable_error_type(E_USER_DEPRECATED));
     $this->assertEquals('E_USER_ERROR', readable_error_type(E_USER_ERROR));
     $this->assertEquals('E_USER_NOTICE', readable_error_type(E_USER_NOTICE));
     $this->assertEquals('E_USER_WARNING', readable_error_type(E_USER_WARNING));
     $this->assertEquals('E_WARNING', readable_error_type(E_WARNING));
     $this->assertEquals('UNKNOWN_ERROR', readable_error_type('NON_EXISTENT_ERROR'));
 }
Exemplo n.º 6
0
 /**
  * **Get current elapsed time in readable format.**
  *
  * @return int
  */
 public function elapsed_time() : int
 {
     return (int) elapsed_time_since_request(TRUE);
 }