/** * @test * * @covers Cocur\NQM\NQM::execute() */ public function convertParametersShouldNotAddColonIfItIsThere() { $this->pdo->mock('SELECT * FROM table WHERE key = :key;', [[':key' => 'foo']]); $this->queryLoader->shouldReceive('getQuery')->with('foo')->once()->andReturn('SELECT * FROM table WHERE key = :key;'); $stmt = $this->nqm->execute('foo', [':key' => 'foo']); $this->assertInstanceOf('\\PDOStatement', $stmt); $this->assertEquals([':key' => 'foo'], $stmt->fetch(\PDO::FETCH_ASSOC)); }
/** * @test * @covers Cocur\NQM\QueryLoader\CacheQueryLoader::getQuery() * @expectedException \Cocur\NQM\Exception\QueryNotExistsException */ public function getQueryThrowsExceptionIfQueryDoesNotExist() { $this->loader->shouldReceive('getQuery')->once()->andThrow('Cocur\\NQM\\Exception\\QueryNotExistsException'); $this->cache->getQuery('foo'); }
/** * Returns the query with the given name. * * $nqm->getQuery('find-all-users'); * * @param string $name Name of a query. * * @return string SQL code of the query with the given name. * * @throws QueryNotExistsException if no query with the given name exists. */ public function getQuery($name) { return $this->queryLoader->getQuery($name); }