Esempio n. 1
0
    /**
     * @param YoPdo $yo_pdo
     * @param string $table_name
     * @param array $expected_results
     * @return array
     */
    public function assertResults(YoPdo $yo_pdo, $table_name, array $expected_results)
    {
        $column_sql = '';
        if ($expected_results && reset($expected_results)) {
            $column_sql = ', ' . implode(', ', array_keys(reset($expected_results)));
        }
        $sql = <<<SQL
SELECT id {$column_sql}
FROM {$table_name}
ORDER BY id
SQL;
        $result = $yo_pdo->query($sql);
        while ($row = $result->fetch()) {
            if (!array_key_exists('id', $row)) {
                $this->test_case->assertTrue(false, "Field 'id' not found in row.");
            } elseif (!array_key_exists($row['id'], $expected_results)) {
                $this->test_case->assertTrue(false, "Row with key '{$row['id']}' not found in expected results.");
            } else {
                $expected_result = $expected_results[$row['id']];
                $expected_result['id'] = $row['id'];
                if (array_diff_assoc($expected_result, $row) || array_diff_assoc($row, $expected_result)) {
                    $this->test_case->assertEquals($expected_result, $row);
                }
                unset($expected_results[$row['id']]);
            }
        }
        $this->test_case->assertEmpty($expected_results);
    }
Esempio n. 2
0
 public function rollbackAll()
 {
     if (null === $this->current_name) {
         return;
     }
     $this->names = [];
     $this->current_name = null;
     $this->yo_pdo->query('ROLLBACK');
 }
    /**
     * @param YoPdo $yo_pdo
     * @return void
     */
    protected function transactionalDown(YoPdo $yo_pdo)
    {
        $sql = <<<SQL
ALTER TABLE buffered_jobs
    DROP COLUMN mutex_id;
ALTER TABLE queued_jobs
    DROP COLUMN mutex_id;
ALTER TABLE successful_jobs
    DROP COLUMN mutex_id;
ALTER TABLE failed_jobs
    DROP COLUMN mutex_id;
SQL;
        $yo_pdo->queryMultiple($sql);
    }
Esempio n. 4
0
    /**
     * @param array $additional_records
     */
    public function insertRecords(array $additional_records = [])
    {
        $this->bufferRecords($additional_records);
        if (!count($this->records)) {
            return;
        }
        $table_name = $this->table_name;
        $columns = implode(', ', $this->columns);
        $placeholders = $this->getRecordLines(count($this->records));
        $flattened_records = $this->flattenRecords($this->records);
        $sql = <<<SQL
INSERT INTO {$table_name}
({$columns})
VALUES
{$placeholders}
SQL;
        $this->yo_pdo->query($sql, $flattened_records);
        $this->records = [];
    }
Esempio n. 5
0
    /**
     * @return fluent
     */
    public function createSchema()
    {
        $sql = <<<SQL
CREATE SCHEMA migrations;

CREATE TABLE migrations.migrations
(
    version VARCHAR PRIMARY KEY,
    migrated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
    migration_hash VARCHAR NOT NULL
);

CREATE TABLE migrations.rollbacks
(
    version VARCHAR NOT NULL,
    migrated_at TIMESTAMP WITH TIME ZONE NOT NULL,
    migration_hash VARCHAR NOT NULL,
    rolled_back_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
    rollback_hash VARCHAR NOT NULL
);
SQL;
        $this->yo_pdo->queryMultiple($sql);
        return $this;
    }
Esempio n. 6
0
 /**
  * @param YoPdo $yo_pdo
  * @param $table_name
  * @param array $rows
  */
 private function populateTable(YoPdo $yo_pdo, $table_name, array $rows)
 {
     foreach ($rows as $row) {
         $yo_pdo->insert($table_name, $row);
     }
 }
    /**
     * @param YoPdo $yo_pdo
     * @return void
     */
    protected function transactionalDown(YoPdo $yo_pdo)
    {
        $sql = <<<SQL
DROP TABLE buffered_jobs;
DROP TABLE queued_jobs;
DROP TABLE successful_jobs;
DROP TABLE failed_jobs;
SQL;
        $yo_pdo->queryMultiple($sql);
    }
Esempio n. 8
0
    /**
     * @covers ::getSelectRowGenerator
     * @dataProvider dbProvider
     * @param YoPdo $yo_pdo
     */
    public function testARowGeneratorCanBeUsed(YoPdo $yo_pdo)
    {
        $sql = <<<SQL
SELECT :param_a AS col UNION
SELECT :param_b AS col UNION
SELECT :last_param AS col
ORDER BY col
SQL;
        $result = $yo_pdo->getSelectRowGenerator($sql, array('param_a' => 1, 'param_b' => 2, 'last_param' => 3));
        $count = 1;
        foreach ($result as $row) {
            $this->assertEquals($count, $row['col']);
            ++$count;
        }
    }
Esempio n. 9
0
 /**
  * @param YoPdo $yo_pdo
  * @param string $name
  * @throws Exception\TransactionAcceptanceOrderException
  */
 private function assertUnknownTransactionNameException(YoPdo $yo_pdo, $name)
 {
     try {
         $yo_pdo->transaction()->accept($name);
         $this->fail("'{$name}' transaction should not be defined");
     } catch (UnknownTransactionNameException $exception) {
         $this->assertTrue(true);
     }
 }