Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adding test for Shield class

  • Loading branch information...
commit 151baf8d340f0613a73da46b7518e1aed1ca9b7c 1 parent 03c4924
Chris Cornutt authored

Showing 1 changed file with 64 additions and 0 deletions. Show diff stats Hide diff stats

  1. +64 0 Shield/tests/Shield/ShieldTest.php
64 Shield/tests/Shield/ShieldTest.php
... ... @@ -0,0 +1,64 @@
  1 +<?php
  2 +
  3 +namespace Shield;
  4 +
  5 +class ShieldTest extends \PHPUnit_Framework_TestCase
  6 +{
  7 + public function setUp()
  8 + {
  9 + // just in case there's already a session going
  10 + $sid = session_id();
  11 + if ($sid) {
  12 + session_destroy();
  13 + session_write_close();
  14 + }
  15 + }
  16 + public function tearDown()
  17 + {
  18 + $this->_shield = null;
  19 + }
  20 +
  21 + /**
  22 + * Test that an exact match route is correctly handled
  23 + *
  24 + * @return null
  25 + */
  26 + public function testRouteMatch()
  27 + {
  28 + $_SERVER['REQUEST_URI'] = '/';
  29 + $_SERVER['REQUEST_METHOD'] = 'GET';
  30 +
  31 + $app = new Shield();
  32 + $app->get('/', function(){
  33 + echo 'match /';
  34 + });
  35 +
  36 + ob_start();
  37 + $app->run();
  38 +
  39 + $output = ob_get_clean();
  40 + $this->assertEquals('match /', $output);
  41 + }
  42 +
  43 + /**
  44 + * Test that a regex route is matched correctly
  45 + *
  46 + * @return null
  47 + */
  48 + public function testRegexRouteMatch()
  49 + {
  50 + $_SERVER['REQUEST_URI'] = '/testing123';
  51 + $_SERVER['REQUEST_METHOD'] = 'GET';
  52 +
  53 + $app = new Shield();
  54 + $app->get('/testing[0-9]+', function(){
  55 + echo 'match /';
  56 + });
  57 +
  58 + ob_start();
  59 + $app->run();
  60 +
  61 + $output = ob_get_clean();
  62 + $this->assertEquals('match /', $output);
  63 + }
  64 +}

0 comments on commit 151baf8

Please sign in to comment.
Something went wrong with that request. Please try again.