Exemplo n.º 1
0
 /**
  * @dataProvider \g105b\phpcsv\TestHelper::data_randomFilePath
  */
 public function testDeleteByReferenceRemovesExpectedRow($filePath)
 {
     TestHelper::createCsv($filePath, 10);
     $csv = new Csv($filePath);
     $rowThree = $csv->get(3);
     $allRows = $csv->getAll();
     $this->assertContains($rowThree, $allRows);
     $csv->delete($rowThree);
     $allRowsAfterDelete = $csv->getAll();
     $this->assertNotContains($rowThree, $allRowsAfterDelete);
     $searchResult = $csv->getAllBy("firstName", $rowThree["firstName"]);
     $this->assertNotContains($rowThree, $searchResult);
 }
Exemplo n.º 2
0
 /**
  * @dataProvider \g105b\phpcsv\TestHelper::data_randomFilePath
  */
 public function testGetAllDoesNotGiveHeaderRow($filePath)
 {
     TestHelper::createCsv($filePath, 10);
     $csv = new Csv($filePath);
     $headers = $csv->getHeaders();
     $allRows = $csv->getAll();
     $this->assertNotEquals($headers, array_values($allRows[0]));
 }
Exemplo n.º 3
0
 /**
  * @dataProvider \g105b\phpcsv\TestHelper::data_randomFilePath
  */
 public function testNewLine($filePath)
 {
     TestHelper::createCsv($filePath, 10);
     $csv = new Csv($filePath);
     $all = $csv->getAll();
     $numberOfRows = count($all);
     $csv->setIdField("rowNum");
     $headers = $csv->getHeaders();
     $rowThatHasNewLine = rand(0, 9);
     $fieldThatHasQuotes = rand(0, count($headers) - 2);
     $headerName = $headers[$fieldThatHasQuotes];
     $row = $csv->get($rowThatHasNewLine);
     $fieldValue = "New...\n...Line!";
     $row[$headerName] = $fieldValue;
     $csv->updateRow($rowThatHasNewLine, $row);
     $all = $csv->getAll(true);
     $this->assertEquals($numberOfRows, count($all), 'Should have same number of rows after update');
     $rowAfterUpdate = $csv->get($rowThatHasNewLine);
     $this->assertEquals($fieldValue, $rowAfterUpdate[$headerName]);
 }
Exemplo n.º 4
0
 /**
  * @dataProvider \g105b\phpcsv\TestHelper::data_randomFilePath
  */
 public function testFileNotDeletedWhenExists($filePath)
 {
     TestHelper::createCsv($filePath, 10);
     $csv = new Csv($filePath);
     $csv->getAll();
     $csv = null;
     $this->assertFileExists($filePath);
 }