Example #1
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']);
 }
Example #2
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']);
 }
Example #3
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']);
 }
Example #4
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']);
 }