Google\Cloud\Tests\System\BigQuery\LoadDataAndQueryTest::testRunQueryWithNamedParameters PHP Method

testRunQueryWithNamedParameters() public method

    public function testRunQueryWithNamedParameters()
    {
        $date = '2000-01-01';
        $query = 'WITH data AS' . '(SELECT "Dave" as name, DATE("1999-01-01") as date, 1.1 as floatNum, 1 as intNum, false as boolVal ' . 'UNION ALL ' . 'SELECT "John" as name, DATE("2000-01-01") as date, 1.2 as floatNum, 2 as intNum, true as boolVal) ' . 'SELECT * FROM data ' . 'WHERE name = @name AND date >= @date AND floatNum = @numbers.floatNum AND intNum = @numbers.intNum AND boolVal = @boolVal';
        $results = self::$client->runQuery($query, ['parameters' => ['name' => 'John', 'date' => self::$client->date(new \DateTime($date)), 'numbers' => ['floatNum' => 1.2, 'intNum' => 2], 'boolVal' => true]]);
        $backoff = new ExponentialBackoff(8);
        $backoff->execute(function () use($results) {
            $results->reload();
            if (!$results->isComplete()) {
                throw new \Exception();
            }
        });
        if (!$results->isComplete()) {
            $this->fail('Query did not complete within the allotted time.');
        }
        $actualRows = iterator_to_array($results->rows());
        $expectedRows = [['name' => 'John', 'floatNum' => 1.2, 'intNum' => 2, 'boolVal' => true, 'date' => new Date(new \DateTime($date))]];
        $this->assertEquals($expectedRows, $actualRows);
    }