public function testUsageWithCallbackCollection() { $pdo = $this->manager->getPdo(); $stmt = $pdo->prepare("SELECT * FROM collection_test"); $stmt->execute(); $pdoCollection = new PdoCollection($stmt); $callbackCollection = new CallbackCollection($pdoCollection, function ($row) { $row['test'] = 'test'; return $row; }); foreach ($callbackCollection as $line) { $this->assertEquals('test', $line['test']); } }
public function testUsage() { $pdo = $this->manager->getPdo(); $stmt = $pdo->prepare("SELECT * FROM collection_test"); $stmt->execute(); $this->assertFileNotExists('vfs://output/data.csv'); $collection = new PdoCollection($stmt); $config = new ExporterConfig(); $exporter = new Exporter($config); $exporter->export('vfs://output/data.csv', $collection); $expectedContents = "1,name\r\n"; $expectedContents .= "2,name\r\n"; $expectedContents .= "3,name\r\n"; $this->assertSame($expectedContents, file_get_contents('vfs://output/data.csv')); }
public function testUsage() { $interpreter = new Interpreter(); $table = 'test'; $dsn = $this->manager->getDsn(); $options = array('user' => $this->manager->getUser(), 'password' => $this->manager->getPassword()); $sqlObserver = new PdoObserver($table, array('id', 'name', 'age', 'flag', 'flag2', 'status', 'contents'), $dsn, $options); $interpreter->addObserver(array($sqlObserver, 'notify')); $interpreter->interpret(array('123', 'test', '28', 'true', 'false', 'null', 'test"test')); $pdo = $this->manager->getPdo(); $stmt = $pdo->prepare("SELECT * FROM " . $table); $stmt->execute(); $result = $stmt->fetch(); $this->assertEquals(123, $result[0]); $this->assertEquals('test', $result[1]); $this->assertEquals(28, $result[2]); $this->assertEquals(1, $result[3]); $this->assertEquals(0, $result[4]); $this->assertEquals('NULL', $result[5]); $this->assertEquals('test"test', $result[6]); }