/** * @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\QueryCollection::__construct() * @covers Cocur\NQM\QueryCollection::execute() * @covers Cocur\NQM\QueryCollection::getQueryParameters() */ public function executeExecutesMultipleStatementsWithDifferentParameters() { $pdo = $this->getMockPdo(); $pdo->mock('SELECT :foo1;', []); $pdo->mock('SELECT :foo2;', []); $this->nqm->shouldReceive('getPdo')->once()->andReturn($pdo); $this->nqm->shouldReceive('getQuery')->with('select2')->once()->andReturn("SELECT :foo1;\n#;\nSELECT :foo2;"); $statements = $this->collection->execute('select2', ['foo1' => 'bar1', 'foo2' => 'bar2']); $this->assertCount(2, $statements); $this->assertInstanceOf('\\PDOStatement', $statements[0]); $this->assertCount(1, $statements[0]->getBoundParams()); $this->assertArrayHasKey(':foo1', $statements[0]->getBoundParams()); $this->assertArrayNotHasKey('foo2', $statements[0]->getBoundParams()); $this->assertInstanceOf('\\PDOStatement', $statements[1]); $this->assertCount(1, $statements[1]->getBoundParams()); $this->assertArrayHasKey(':foo2', $statements[1]->getBoundParams()); $this->assertArrayNotHasKey('foo1', $statements[1]->getBoundParams()); }