$watch->start('csv_generation'); $header = array('lastname', 'firstname', 'phone number', 'email', 'birthday', 'address', 'zipcode', 'city', 'points'); $csvWriter1->writeRow($header); for ($i = 0; $i < $maxLines; $i++) { $lastname = $faker->lastName; $firstname = $faker->firstName; $row = array($lastname, $firstname, $faker->phoneNumber, strtolower($firstname . '.' . $lastname) . '@' . $faker->domainName, $faker->dateTimeThisCentury->format('Y-m-d'), $faker->streetAddress, $faker->postcode, $faker->city, $faker->randomNumber()); $csvWriter1->writeRow($row); } $csvWriter1->close(); $eventGeneration = $watch->stop('csv_generation'); echo 'Converting the CSV' . "\n\n"; $file2 = $dir . '/bench_result' . $maxLines . '.csv'; $watch->start('csv_convert'); $csvReader = new CsvReader(array('delimiter' => ';', 'enclosure' => '"', 'encoding' => 'CP1252', 'eol' => "\r\n", 'escape' => "\\")); $csvReader->open($file1); $csvWriter2 = new CsvWriter(array('delimiter' => ',', 'enclosure' => '"', 'encoding' => 'UTF-8', 'eol' => "\n", 'escape' => "\\")); $csvWriter2->open($file2); foreach ($csvReader as $row) { $csvWriter2->writeRow($row); } $csvWriter2->close(); $csvReader->close(); $eventConverting = $watch->stop('csv_convert'); echo 'Results' . "\n"; echo 'CSV Generation' . "\n\n"; echo 'duration = ' . $eventGeneration->getDuration() . ' ms' . "\n"; echo 'memory usage = ' . $eventGeneration->getMemory() / (1024 * 1024) . ' Mb (' . $eventConverting->getMemory() . ' b)' . "\n\n"; echo 'CSV Parsing/Converting' . "\n\n"; echo 'duration = ' . $eventConverting->getDuration() . ' ms' . "\n"; echo 'memory usage = ' . $eventConverting->getMemory() / (1024 * 1024) . ' Mb (' . $eventConverting->getMemory() . ' b)' . "\n";
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage The file handler mode "wb" is not valid. Allowed modes : "rb", "r+b", "w+b", "a+b", "x+b", "c+b". */ public function testReadingExistingFileHandlerWithInvalidMode() { $filename = __DIR__ . '/Fixtures/testReadStream1.csv'; if (file_exists($filename)) { unlink($filename); } $expected = array(array('nom', 'prénom', 'age'), array('Martin', 'Durand', '28'), array('Alain', 'Richard', '36')); $stream = fopen($filename, 'wb'); $reader = new CsvReader(array('delimiter' => ',', 'enclosure' => '"', 'encoding' => 'UTF-8', 'eol' => "\n", 'escape' => "\\", 'bom' => false, 'translit' => 'translit', 'force_encoding_detect' => false, 'skip_empty' => false, 'trim' => false)); $this->assertFalse($reader->isFileOpened()); $this->assertInstanceOf('CSanquer\\ColibriCsv\\CsvReader', $reader->open($stream)); }