/** * @param string $tableName * @param array $rows */ protected function insertTableRows($tableName, array $rows) { foreach ($rows as $rowKey => $values) { $this->connection->insert($tableName, $this->parser->parse($values)); $this->parser->addReference($rowKey, $this->connection->lastInsertId()); } }
/** @test */ public function it_replaces_several_keys() { $parser = new ForeignKeyParser(); $parser->addReference('station_1', 1); $parser->addReference('station_2', 2); $firstComment = $parser->parse(['comment' => 'El servicio es excelente', 'stars' => 5, 'station_id' => '@station_1']); $secondComment = $parser->parse(['comment' => 'El servicio es pésimo', 'stars' => 0, 'station_id' => '@station_2']); $thirdComment = $parser->parse(['comment' => 'El servicio es regular', 'stars' => 2, 'station_id' => '@station_1']); $this->assertEquals(1, $firstComment['station_id']); $this->assertEquals(2, $secondComment['station_id']); $this->assertEquals(1, $thirdComment['station_id']); }