Inheritance: extends PHPUnit_Framework_TestCas\PHPUnit_Framework_TestCase
コード例 #1
0
 public function setUp()
 {
     if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
         $this->markTestSkipped('Can only test in *nix envs.');
     }
     $this->scriptsDir = dirname(dirname(dirname(dirname(__DIR__)))) . '/.scripts/';
     $this->filesDir = dirname(__DIR__) . '/test_files/commit_messages/';
     $this->validateScript = "php {$this->scriptsDir}validate_commit_msg.php";
     parent::setUp();
 }
コード例 #2
0
ファイル: Database.php プロジェクト: elgg/elgg
 /**
  * Execute database query
  *
  * @param string $sql    Query
  * @param array  $params Query params
  * @return PHPUnit_Framework_MockObject_MockObject (statement)
  */
 public function executeDatabaseQuery($sql, $params = [])
 {
     $sql = $this->normalizeSql($sql);
     $results = [];
     $row_count = 0;
     $this->last_insert_id = null;
     $match = false;
     foreach ($this->query_specs as $i => $spec) {
         if ($spec->sql == $sql && $params == $spec->params) {
             $match = true;
             if (isset($spec->results)) {
                 if (is_callable($spec->results)) {
                     $results = call_user_func($spec->results, $spec);
                 } else {
                     if (is_array($spec->results)) {
                         $results = $spec->results;
                     }
                 }
             }
             $row_count = isset($spec->row_count) ? $spec->row_count : count($results);
             if (isset($spec->insert_id)) {
                 $this->last_insert_id = $spec->insert_id;
             }
             if (isset($spec->remaining)) {
                 $spec->remaining--;
                 if (!$spec->remaining) {
                     // don't allow more matches
                     unset($this->query_specs[$i]);
                 }
             }
             break;
         }
     }
     if (!$match && strpos($sql, 'select') !== 0) {
         // We need to make sure all UPDATE, INSERT and DELETE queries are
         // mocked, otherwise we will be getting incorrect test results
         throw new \DatabaseException("No testing query spec was found");
     }
     $statement = $this->test->getMockBuilder(\Doctrine\DBAL\PDOStatement::class)->setMethods(['fetch', 'rowCount'])->disableOriginalConstructor()->getMock();
     $statement->expects($this->test->any())->method('fetch')->will($this->test->returnCallback(function () use(&$results) {
         return array_shift($results);
     }));
     $statement->expects($this->test->any())->method('rowCount')->will($this->test->returnValue($row_count));
     return $statement;
 }
コード例 #3
0
ファイル: bootstrap.php プロジェクト: elgg/elgg
/**
 * Create an HTTP request
 *
 * @param string $uri             URI of the request
 * @param string $method          HTTP method
 * @param array  $parameters      Query/Post parameters
 * @param int    $ajax            AJAX api version (0 for non-ajax)
 * @param bool   $add_csrf_tokens Add CSRF tokens
 * @return \Elgg\Http\Request
 * @deprecated 2.3
 */
function _elgg_testing_request($uri = '', $method = 'GET', $parameters = [], $ajax = 0, $add_csrf_tokens = false)
{
    return \Elgg\TestCase::prepareHttpRequest($uri, $method, $parameters, $ajax, $add_csrf_tokens);
}
コード例 #4
0
 public function setUp()
 {
     parent::setUp();
     $this->mock = $this->getMockForAbstractClass('\\Elgg\\HooksRegistrationService');
 }