Elgg\Mocks\Database::addQuerySpec PHP Method

addQuerySpec() public method

Set the result of a query that may be called in the future
public addQuerySpec ( array $spec ) : integer
$spec array Query spec
return integer ID of spec
    public function addQuerySpec(array $spec)
    {
        static $id = 0;
        $default = ['params' => [], 'results' => null, 'row_count' => null, 'insert_id' => null];
        $spec = array_merge($default, $spec);
        $spec['sql'] = $this->normalizeSql($spec['sql']);
        if (!empty($spec['times'])) {
            $spec['remaining'] = $spec['times'];
        }
        unset($spec['times']);
        $id++;
        $this->query_specs[$id] = (object) $spec;
        return $id;
    }

Usage Example

Example #1
0
 public function testCanRemoveSubtype()
 {
     $dbprefix = elgg_get_config('dbprefix');
     $this->setupFetchAllQuery();
     $type = 'object';
     $subtype = 'foo';
     $this->db->addQuerySpec(['sql' => "\n\t\t\t\tDELETE FROM {$dbprefix}entity_subtypes\n\t\t\t\tWHERE type = :type AND subtype = :subtype\n\t\t\t", 'params' => [':type' => $type, ':subtype' => $subtype], 'row_count' => 1]);
     $this->assertTrue(_elgg_services()->subtypeTable->remove($type, $subtype));
     $this->db->addQuerySpec(['sql' => "\n\t\t\t\tDELETE FROM {$dbprefix}entity_subtypes\n\t\t\t\tWHERE type = :type AND subtype = :subtype\n\t\t\t", 'params' => [':type' => $type, ':subtype' => 'unregistered'], 'row_count' => 0]);
     $this->assertFalse(_elgg_services()->subtypeTable->remove($type, 'unregistered'));
 }