Exemple #1
0
 /**
  * Unit test bootstrapper, called by PHPUnit_Framework_TestCase
  *
  * Your custom unit test inside the framework should look like
  * the following (pay attention how and were we get {@link phpRack_Assertion} object,
  * and {@link phpRack_Result} object):
  *
  * <code>
  * class MyTest extends AbstractTest {
  *   public function testMySpecificPackageWorksFine() {
  *     $isValid = $this->_test->assert->php->atLeast('5.2');
  *     $this->assertTrue(is_bool($isValid));
  *     $this->assertTrue($this->_test->assert->getResult());
  *   }
  * }
  * </code>
  *
  * You should NOT instantiate tests, assertions or test results explicitly
  * in your unit tests. Only if you're testing the mechanism of their
  * instantiation. If you're testing packages, use the approach explained
  * above in PHP snippet.
  *
  * @see PHPUnit_Framework_TestCase::run()
  * @see tearDown()
  */
 protected function setUp()
 {
     global $phpRackConfig;
     /**
      * @see phpRack_Runner
      */
     require_once PHPRACK_PATH . '/Runner.php';
     $this->_runner = new phpRack_Runner($phpRackConfig);
     /**
      * This test is used as a template for all other packages/assertions
      * testing. No matter what particular test we use here.
      * @see phpRack_Test
      */
     require_once PHPRACK_PATH . '/Test.php';
     $this->_test = phpRack_Test::factory('CustomTest.php', $this->_runner);
 }
Exemple #2
0
 /**
  * Run one test and return JSON result.
  *
  * @param $label string Test label
  * @param $token string Unique token to return back, if required
  * @param $options array Associative array of options to be used for setAjaxOptions()
  * @return string JSON
  * @throws phpRack_Exception
  * @see bootstrap.php
  */
 public function run($label, $token = 'token', $options = array())
 {
     if (!$this->getAuth()->isAuthenticated()) {
         throw new phpRack_Exception("Authentication failed, please login first");
     }
     // if this is one of our built-in tests
     if (!empty($options['suiteTest'])) {
         /**
          * @see phpRack_Suite
          */
         require_once PHPRACK_PATH . '/Suite/Test.php';
         $test = phpRack_Suite_Test::factory($label, $this);
         if (isset($options['config'])) {
             $test->setConfig($options['config']);
         }
     } else {
         $test = phpRack_Test::factory($label, $this);
     }
     unset($options['config']);
     unset($options['suiteTest']);
     $test->setAjaxOptions($options);
     $result = $test->run();
     $options = $test->getAjaxOptions();
     /**
      * @see phpRack_Runner_Logger
      */
     require_once PHPRACK_PATH . '/Runner/Logger.php';
     return json_encode(array('success' => $result->wasSuccessful(), 'options' => $options, 'log' => phpRack_Runner_Logger::utf8Encode(phpRack_Runner_Logger::cutLog($result->getLog(), intval($options['logSizeLimit']))), PHPRACK_AJAX_TOKEN => $token));
 }
Exemple #3
0
 /**
  * Run one test and return JSON result
  *
  * @param string Test file name (absolute name of PHP file)
  * @param string Unique token to return back, if required
  * @param array Associative array of options to be used for setAjaxOptions()
  * @return string JSON
  * @throws Exception
  * @see bootstrap.php
  */
 public function run($fileName, $token = 'token', $options = array())
 {
     if (!$this->getAuth()->isAuthenticated()) {
         //TODO: handle situation when login screen should appear
         throw new Exception("Authentication failed, please login first");
     }
     $test = phpRack_Test::factory($fileName, $this);
     $test->setAjaxOptions($options);
     $result = $test->run();
     $options = $test->getAjaxOptions();
     /**
      * @see phpRack_Runner_Logger
      */
     require_once PHPRACK_PATH . '/Runner/Logger.php';
     return json_encode(array('success' => $result->wasSuccessful(), 'options' => $options, 'log' => phpRack_Runner_Logger::utf8Encode(phpRack_Runner_Logger::cutLog($result->getLog(), intval($options['logSizeLimit']))), PHPRACK_AJAX_TOKEN => $token));
 }