elmika

Test Booking Object with PHPUnit

Apr 10th, 2014
134
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  namespace BookingNamespace;
  3.    
  4.      // Override DateTime in current namespace for testing
  5.     require_once "DateTime.class.php";
  6.     require_once "../MyBookingObject.class.php";
  7.    
  8.     class MyBookingObjectTest extends \PHPUnit_Framework_TestCase
  9.     {
  10.    
  11.         private $booking_object;
  12.    
  13.         /**
  14.          * Create test subject before test
  15.          */
  16.         protected function setUp()
  17.         {
  18.             parent::setUp();
  19.             DateTime::set_now("2014-04-02 16:15");
  20.             $this->booking_object = new MyBookingObject();
  21.         }
  22.    
  23.         /**
  24.          * Reset custom time after test
  25.          */
  26.         protected function tearDown()
  27.         {
  28.             DateTime::reset();
  29.         }
  30.      
  31.         /*
  32.          * Test cases
  33.          */
  34.         public function testBookAndConfirm()
  35.         {
  36.             $token = $this->booking_object->book();
  37.             $this->assertTrue($this->booking_object->confirm($token));
  38.         }
  39.         public function testBookAndConfirmThreeMinutesLater()
  40.         {
  41.             $token = $this->booking_object->book();
  42.             DateTime::modify_now("+3 minutes");
  43.             $this->assertTrue($this->booking_object->confirm($token));
  44.         }
  45.         public function testBookAndConfirmSixMinutesLater()
  46.         {
  47.             $token = $this->booking_object->book();
  48.             DateTime::modify_now("+6 minutes");
  49.             $this->assertFalse($this->booking_object->confirm($token));
  50.         }
  51.     }
  52.  
  53. ?>
RAW Paste Data