Ejemplo n.º 1
0
 /**
  * @test
  */
 public function itShouldParseColumnAsInt()
 {
     $intFormatter = new Int('nl_NL');
     $csv = new File($this->getCSVFile(), 0);
     $csv->setMappingMode(File::COLUMN_TITLES);
     $csv->setFormatter('Stock', $intFormatter);
     $row = $csv->fetch();
     $this->assertInternalType('int', $row['Stock']);
     $this->assertEquals(12, $row['Stock']);
     $row = $csv->fetch();
     $this->assertEquals(15000, $row['Stock']);
     $row = $csv->fetch();
     $this->assertEquals(14, $row['Stock']);
 }
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function itShouldParseColumnAsDecimal()
 {
     $decimalFormatter = new Decimal('nl_NL');
     $csv = new File($this->getCSVFile(), 0);
     $csv->setMappingMode(File::COLUMN_TITLES);
     $csv->setFormatter('Rating', $decimalFormatter);
     $csv->setFormatter('Views', $decimalFormatter);
     $row = $csv->fetch();
     $this->assertInternalType('float', $row['Rating']);
     $this->assertEquals(5.6, $row['Rating']);
     $this->assertEquals(3230, $row['Views']);
     $row = $csv->fetch();
     $this->assertEquals(2093230, $row['Views']);
 }
Ejemplo n.º 3
0
 /**
  * @test
  */
 public function itShouldParseColumnAsFloat()
 {
     $priceFormatter = new Currency('nl_NL');
     $csv = new File($this->getCSVFile(), 0);
     $csv->setMappingMode(File::COLUMN_TITLES);
     $csv->setFormatter('Price', $priceFormatter);
     $row = $csv->fetch();
     $this->assertInternalType('float', $row['Price']);
     $this->assertEquals(15.95, $row['Price']);
     $row = $csv->fetch();
     $this->assertEquals(17, $row['Price']);
     $row = $csv->fetch();
     $this->assertEquals(19.91, $row['Price']);
     $row = $csv->fetch();
     $this->assertEquals(1, $row['Price']);
 }
Ejemplo n.º 4
0
 /**
  * Test the fetch method with the File::CUSTOM mode
  * @test
  */
 public function fetchCustom()
 {
     $file = new File($this->getCSVFile(), 0);
     $file->setMappingMode(File::CUSTOM);
     $file->setMapping(array('ID', 'First Name', 'Age'));
     $row = $file->fetch();
     $this->assertEquals('John', $row['First Name']);
 }
Ejemplo n.º 5
0
 /**
  * @test
  */
 public function itShouldParseColumnAsFloat()
 {
     /** @var FormatterInterface $fooFormatter */
     $fooFormatter = $this->getMock('RSKuipers\\CSV\\Formatter\\FormatterInterface', array('parse'));
     $fooFormatter->expects($this->atLeastOnce())->method('parse')->will($this->returnValue('Foo'));
     $csv = new File($this->getCSVFile(), 0);
     $csv->setMappingMode(File::COLUMN_TITLES);
     $csv->setFormatter('Name', $fooFormatter);
     $row = $csv->fetch();
     $this->assertEquals('Foo', $row['Name']);
 }