Ejemplo n.º 1
0
 public function testParser()
 {
     $schema = CSVSchema::create();
     $parser = $schema->parser();
     $this->assertInstanceOf(CSVParser::class, $parser);
     $this->assertAttributeEquals($schema, "schema", $parser);
 }
Ejemplo n.º 2
0
 public function testArrayAccessUnset()
 {
     $schema = CSVSchema::create()->withHeader("header1", "intval");
     $record = CSVRecord::create($schema);
     $record->setValue(0, "666");
     $this->assertEquals(666, $record->getValue("header1"));
     unset($record["header1"]);
     $this->assertEquals(0, $record->getValue("header1"));
 }
Ejemplo n.º 3
0
 public function testExcelSchema()
 {
     $schema = CSVSchema::create()->withDelimiter(',')->withEnclosure('"')->withEscape("\\")->withSeparator("\r\n");
     $excel = CSV::excelSchema();
     $this->assertEquals($schema, $excel);
 }
Ejemplo n.º 4
0
 public function testParseLines()
 {
     $schema = CSVSchema::create()->withHeaderLine()->withHeader("name")->withHeader("email")->withHeader("gender")->withHeader("salary", function ($salary) {
         return round(floatval(substr($salary, 1)), 2);
     });
     $parser = CSVParser::create($schema);
     $lines = "";
     $lines .= "name,email,gender,salary";
     $lines .= "\r\n" . '"Helen ""Rivera""",hrivera0@nifty.com,Female,$1263.92';
     $lines .= "\r\n" . '"Helen ""Rivera""",hrivera0@nifty.com,Female,$1263.92';
     $lines .= "\r\n" . '"Helen ""Rivera""",hrivera0@nifty.com,Female,$1263.92';
     foreach ($parser->parseLines($lines) as $index => $record) {
         $this->assertInstanceOf(CSVRecord::class, $record);
         $this->assertEquals($index, $record->getIndex());
         $this->assertTrue($record->hasValue("name"));
         $this->assertTrue($record->hasValue("email"));
         $this->assertTrue($record->hasValue("gender"));
         $this->assertTrue($record->hasValue("salary"));
         $this->assertEquals('Helen "Rivera"', $record->getValue("name"));
         $this->assertEquals('*****@*****.**', $record->getValue("email"));
         $this->assertEquals('Female', $record->getValue("gender"));
         $this->assertEquals(1263.92, $record->getValue("salary"));
     }
 }