private function mockProfileHandler($handleCallback)
 {
     Config::set('hyperframework.db.operation_profiler.profile_handler_class', 'Hyperframework\\Db\\Test\\DbOperationProfileHandler');
     $mock = $this->getMock('Hyperframework\\Db\\Test\\DbOperationProfileHandler');
     Test\DbOperationProfileHandler::setDelegate($mock);
     return $mock->expects($this->once())->method('handle')->will($this->returnCallback($handleCallback));
 }
 public function testRun()
 {
     $this->expectOutputRegex('/^<!DOCTYPE html>/');
     Config::set('hyperframework.app_root_path', dirname(__DIR__));
     $debugger = new Debugger();
     $debugger->execute(new Error(E_ERROR, '', __FILE__, __LINE__));
 }
 public function testCustomizeErrorViewRoot()
 {
     Config::set('hyperframework.web.error_view.root_path', 'views/_custom_error_view_root');
     $this->expectOutputString("custom error view root: error\n");
     $view = new ErrorView();
     $view->render(500, '', null);
 }
 protected function setUp()
 {
     Config::set('hyperframework.app_root_path', dirname(__DIR__));
     Config::set('hyperframework.app_root_namespace', __NAMESPACE__);
     Config::set('hyperframework.initialize_config', false);
     Config::set('hyperframework.initialize_error_handler', false);
     Config::set('hyperframework.web.csrf_protection.enable', false);
 }
 private function mockProfileHandler()
 {
     Config::set('hyperframework.db.operation_profiler.enable', true);
     Config::set('hyperframework.db.operation_profiler.enable_logger', false);
     $mock = $this->getMockBuilder(DbOperationProfiler::class)->setMethods(['onPreparedStatementExecuting', 'onPreparedStatementExecuted'])->getMock();
     $mock->expects($this->once())->method('onPreparedStatementExecuting');
     $mock->expects($this->once())->method('onPreparedStatementExecuted');
     $mock->run();
 }
 public function testBatchSizeOption()
 {
     Config::set('hyperframework.db.operation_profiler.enable', true);
     Config::set('hyperframework.db.operation_profiler.enable_logger', false);
     $mock = $this->getMockBuilder(DbOperationProfiler::class)->setMethods(['onPreparedStatementExecuting', 'onPreparedStatementExecuted'])->getMock();
     $mock->expects($this->exactly(2))->method('onPreparedStatementExecuting');
     $mock->expects($this->exactly(2))->method('onPreparedStatementExecuted');
     $mock->run();
     DbImportCommand::execute('Document', [[1, 'doc 1', 12.34], [2, 'doc 2', 0]], ['column_names' => ['id', 'name', 'decimal'], 'batch_size' => 1]);
 }
 public function setUp()
 {
     Config::set('hyperframework.app_root_path', '/root');
 }
 /**
  * @expectedException Hyperframework\Common\ClassNotFoundException
  */
 public function testCustomCommandConfigClassNotFound()
 {
     Config::set('hyperframework.cli.command_config_class', 'Unknown');
     $_SERVER['argv'] = ['run', 'arg'];
     $app = $this->createApp();
 }
 protected function setUp()
 {
     Config::set('hyperframework.app_root_path', dirname(__DIR__));
     Config::set('hyperframework.app_root_namespace', 'Hyperframework\\Cli\\Test');
 }
Example #10
0
 public function testGetCustomRouter()
 {
     Config::set('hyperframework.web.router_class', 'Hyperframework\\Web\\Test\\FakeRouter');
     $app = new App(dirname(__DIR__));
     $this->assertInstanceOf('Hyperframework\\Web\\Test\\FakeRouter', $app->getRouter());
 }
 /**
  * @expectedException Hyperframework\Common\ConfigException
  */
 public function testInvalidConfig()
 {
     Config::set('hyperframework.exit_function', true);
     ExitHelper::exitScript();
 }
 public function testThrowArgumentErrorException()
 {
     Config::set('hyperframework.error_handler.error_exception_bitmask', E_ALL);
     $this->registerErrorHandler();
     try {
         $function = function ($arg) {
         };
         $function();
     } catch (ErrorException $e) {
         $line = __LINE__ - 2;
         $file = __FILE__;
         $this->assertEquals($e->getLine(), $line);
         $this->assertEquals($e->getFile(), $file);
         return;
     }
     $this->fail();
 }
 public function testBuildWithEmptyFormat()
 {
     Config::set('hyperframework.web.view.format', '');
     $this->assertSame('index.html', ViewPathBuilder::build('index'));
 }
 protected function setUp()
 {
     parent::setUp();
     Config::set('hyperframework.app_root_path', dirname(__DIR__));
 }
 /**
  * @expectedException Hyperframework\Common\ClassNotFoundException
  */
 public function testInvalidEngineConfig()
 {
     Config::set('hyperframework.web.response_engine_class', 'Unknown');
     Response::getEngine();
 }
 /**
  * @expectedException RuntimeException
  */
 public function testFailedToMakeLogFolder()
 {
     Config::set('hyperframework.logging.log_path', 'log/tmp/app.log');
     $this->writeToReadOnlyFolder();
 }
 /**
  * @expectedException Hyperframework\Common\InvalidOperationException
  */
 public function testQuitTwice()
 {
     Config::set('hyperframework.exit_function', function () {
     });
     $app = new App(dirname(__DIR__));
     $router = $app->getRouter();
     $router->setAction('index');
     $controller = new IndexController($app);
     $controller->quit();
     $controller->quit();
 }
 public function testRepeatableArgument()
 {
     Config::set('hyperframework.cli.command_config_path', 'repeatable_argument_command.php');
     $result = (new CommandParser())->parse(new CommandConfig(), ['run', 'a', 'b']);
     $this->assertSame(['a', 'b'], $result['arguments']);
 }
 public function testCustomizeSubcommandConfigRootPath()
 {
     Config::set('hyperframework.cli.multiple_commands', true);
     Config::set('hyperframework.cli.subcommand_config_root_path', 'custom_subcommands_config_root');
     $commandConfig = new CommandConfig();
     $this->assertSame(['root-path-test-child'], $commandConfig->getSubcommandNames());
 }
 /**
  * @expectedException Hyperframework\Common\ClassNotFoundException
  */
 public function testInvalidEngineConfig()
 {
     Config::set('hyperframework.logging.logger_engine_class', 'Unknown');
     Logger::getEngine();
 }
 /**
  * @expectedException Hyperframework\Common\ClassNotFoundException
  */
 public function testInvalidEngineConfig()
 {
     Config::set('hyperframework.db.client_engine_class', 'Unknown');
     DbClient::getEngine();
 }
Example #22
0
 /**
  * @expectedException Hyperframework\Common\ClassNotFoundException
  */
 public function testInitializeErrorHandlerByInvalidConfig()
 {
     Config::set('hyperframework.error_handler.class', 'Unknown');
     new App(dirname(__DIR__));
 }
 public function testRenderDescriptionWhichStartsWithPhpEol()
 {
     Config::set('hyperframework.cli.command_config_path', 'description_starts_with_php_eol_option_command.php');
     $this->expectOutputString('Usage: ab [options] <arg>' . PHP_EOL . PHP_EOL . 'Options:' . PHP_EOL . ' --test' . PHP_EOL . 'description' . PHP_EOL);
     $app = $this->getMockBuilder('Hyperframework\\Cli\\App')->disableOriginalConstructor()->getMock();
     $app->method('getCommandConfig')->willReturn(new CommandConfig());
     $help = new Help($app);
     $help->render();
 }
 public function testIsEnabled()
 {
     Config::set('hyperframework.web.csrf_protection.enable', false);
     $this->assertFalse(CsrfProtection::isEnabled());
 }
 public function testChangeTokenNameByConfig()
 {
     $engine = new CsrfProtectionEngine();
     Config::set('hyperframework.web.csrf_protection.token_name', 'name');
     $this->assertSame('name', $engine->getTokenName());
 }
 protected function setUp()
 {
     parent::setUp();
     Config::set('hyperframework.cli.command_config_path', 'global_command.php');
 }
 public function testSet()
 {
     $this->mockEngineMethod('set')->with('name', 'value');
     Config::set('name', 'value');
 }
 /**
  * @expectedException Hyperframework\Common\ClassNotFoundException
  */
 public function testCreateViewByInvalidConfig()
 {
     Config::set('hyperframework.web.view.class', 'Unknown');
     ViewFactory::createView();
 }
 /**
  * @param string $appRootPath
  */
 public function __construct($appRootPath)
 {
     Config::set('hyperframework.cli.multiple_commands', true);
     parent::__construct($appRootPath);
 }
 public function testExecuteDebugger()
 {
     $this->expectOutputString('Hyperframework\\Web\\Test\\Debugger::execute');
     Config::set('hyperframework.web.debugger.enable', true);
     Config::set('hyperframework.web.debugger.class', 'Hyperframework\\Web\\Test\\Debugger');
     $handler = new ErrorHandler();
     $this->callProtectedMethod($handler, 'executeDebugger', [null, null]);
     ob_end_flush();
 }