/** * Tests a certain path through the process() method * * @return void */ public function testInitWithException() { // We should get a \AppserverIo\Server\Exceptions\ModuleException $this->setExpectedException('\\AppserverIo\\Server\\Exceptions\\ModuleException'); // Get the objects we need $rewriteModule = new RewriteModule(); $mockServerContext = new MockServerContext(); // Do the thing $rewriteModule->init($mockServerContext); }
/** * Initializes the rewrite module to test. * Will also build up needed mock objects and provide data for the actual rewrite tests. * * @return void */ public function setUp() { // Get an instance of the module we can test with $this->rewriteModule = new RewriteModule(); // We need a mock server context to init our module, otherwise we cannot use it $this->mockServerContext = new ServerContext(); $this->mockServerContext->init(new MockServerConfig(null)); // We need a MockRequestContext to work on $this->mockRequestContext = new MockRequestContext(); $this->mockRequestContext->setServerVar(ServerVars::DOCUMENT_ROOT, realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . RewriteModule::MODULE_NAME . DIRECTORY_SEPARATOR)); // The module has to be inited $this->rewriteModule->init($this->mockServerContext); // We will collect all data files $dataPath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . RewriteModule::MODULE_NAME . DIRECTORY_SEPARATOR; $dataFiles = scandir($dataPath); // Iterate over all data files and collect the sets of test data foreach ($dataFiles as $dataFile) { // Skip the files we do not want foreach ($this->excludedDataFiles as $excludedDataFile) { if (strpos($dataFile, $excludedDataFile) === 0) { continue 2; } } // Require the different files and collect the data $ruleSets = array(); require $dataPath . $dataFile; // Iterate over all rulesets and collect the rules and maps foreach ($ruleSets as $setName => $ruleSet) { // Per convention we got the variables $rules, and $map within a file $this->rewriteDataSets[$setName] = array('redirect' => @$ruleSet['redirect'], 'redirectAs' => @$ruleSet['redirectAs'], 'rules' => $ruleSet['rules'], 'map' => $ruleSet['map']); } } // Create a request and response object we can use for our processing $this->request = new HttpRequest(); $this->response = new HttpResponse(); $this->response->init(); }