Beispiel #1
0
 protected function setUp()
 {
     $this->application = new Application();
     $this->application->unitTesting = true;
     $this->application->context()->simulateNonCli = false;
     $this->application->registerModule(new UnitTestingModule());
     $this->application->initialiseModules();
     ExceptionHandler::disableExceptionTrapping();
 }
 public function testLayoutFilterThrowsException()
 {
     LayoutModule::setLayoutClassName("Rhubarb\\Crown\\Tests\\Layout\\NonExistant");
     $request = new WebRequest();
     $request->UrlPath = "/simple/";
     $request->IsWebRequest = true;
     $this->setExpectedException("Rhubarb\\Crown\\Layout\\Exceptions\\LayoutNotFoundException");
     ExceptionHandler::disableExceptionTrapping();
     Module::generateResponseForRequest($request);
 }
<?php

namespace Your\WebApp;

use Rhubarb\Crown\Context;
use Rhubarb\Crown\Exceptions\Handlers\ExceptionHandler;
use Rhubarb\Crown\Logging\Log;
use Rhubarb\Crown\Logging\PhpLog;
use Rhubarb\Stem\StemSettings;
$dbSettings = new StemSettings();
$dbSettings->Host = "localhost";
$dbSettings->Username = "******";
$dbSettings->Password = "";
$dbSettings->Database = "ogredb";
// Add a PHP logger
Log::attachLog(new PhpLog(Log::ALL));
$con = new Context();
$con->DeveloperMode = true;
// Switch off exception trapping. You should have this on in the production environment.
ExceptionHandler::disableExceptionTrapping();
 public function testDisablingTrapping()
 {
     ExceptionHandler::disableExceptionTrapping();
     try {
         // Enable layouts for this test as proof the URL handler has intercepted the response.
         LayoutModule::enableLayout();
         $request = new WebRequest();
         $request->UrlPath = "/test-exception/";
         $response = Module::generateResponseForRequest($request);
         $this->fail("Without exception trapping this line should not be reached.");
     } catch (RhubarbException $er) {
     }
     ExceptionHandler::setExceptionHandlerClassName('\\Rhubarb\\Crown\\Tests\\Exceptions\\Handlers\\UnitTestDisobedientExceptionHandler');
     try {
         // Enable layouts for this test as proof the URL handler has intercepted the response.
         LayoutModule::enableLayout();
         $request = new WebRequest();
         $request->UrlPath = "/test-exception/";
         $response = Module::generateResponseForRequest($request);
     } catch (RhubarbException $er) {
         $this->fail("The extended exception handler should force handling of exceptions even if trapping is disabled.");
     }
     ExceptionHandler::enableExceptionTrapping();
     LayoutModule::disableLayout();
 }
Beispiel #5
0
<?php

/**
 * Copyright (c) 2016 RhubarbPHP.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * A bootstrapper to setup the Rhubarb platform when running scripts from a terminal
 */
// Initiate our bootstrap script to boot all libraries required.
require_once __DIR__ . "/boot-application.php";
// Disable exception trapping as there will be no valid URL handler able to return a sensible
// interpretation of the exception details. CLI scripts are never seen publicly so it is more
// useful to have the real exception text and isn't a security risk.
\Rhubarb\Crown\Exceptions\Handlers\ExceptionHandler::disableExceptionTrapping();
if (isset($argv[1])) {
    $script = $argv[1];
    /** @noinspection PhpIncludeInspection */
    include $script;
}
 public function testLayoutFilterThrowsException()
 {
     LayoutModule::setLayoutClassName('\\Rhubarb\\Crown\\Tests\\unit\\Layout\\NonExistant');
     $request = new WebRequest();
     $request->urlPath = "/simple/";
     $this->setExpectedException(LayoutNotFoundException::class);
     ExceptionHandler::disableExceptionTrapping();
     Application::current()->generateResponseForRequest($request);
 }
 public function testDisablingTrapping()
 {
     ExceptionHandler::disableExceptionTrapping();
     try {
         // Enable layouts for this test as proof the URL handler has intercepted the response.
         LayoutModule::enableLayout();
         $request = new WebRequest();
         $request->urlPath = "/test-exception/";
         $response = $this->application->generateResponseForRequest($request);
         $this->fail("Without exception trapping this line should not be reached.");
     } catch (RhubarbException $er) {
     }
     $this->application->container()->registerClass(ExceptionHandler::class, UnitTestDisobedientExceptionHandler::class);
     try {
         // Enable layouts for this test as proof the URL handler has intercepted the response.
         LayoutModule::enableLayout();
         $request = new WebRequest();
         $request->urlPath = "/test-exception/";
         $response = $this->application->generateResponseForRequest($request);
     } catch (RhubarbException $er) {
         $this->fail("The extended exception handler should force handling of exceptions even if trapping is disabled.");
     }
     ExceptionHandler::enableExceptionTrapping();
     LayoutModule::disableLayout();
 }