当前位置: 首页>>代码示例>>PHP>>正文


PHP TestHelper::createCsv方法代码示例

本文整理汇总了PHP中TestHelper::createCsv方法的典型用法代码示例。如果您正苦于以下问题:PHP TestHelper::createCsv方法的具体用法?PHP TestHelper::createCsv怎么用?PHP TestHelper::createCsv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestHelper的用法示例。


在下文中一共展示了TestHelper::createCsv方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testDeleteByReferenceRemovesExpectedRow

 /**
  * @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);
 }
开发者ID:g105b,项目名称:phpcsv,代码行数:16,代码来源:DeleteRecord.test.php

示例2: testUpdateRowWithMissingFields

 /**
  * @dataProvider \g105b\phpcsv\TestHelper::data_randomFilePath
  */
 public function testUpdateRowWithMissingFields($filePath)
 {
     TestHelper::createCsv($filePath);
     $csv = new Csv($filePath);
     $csv->setIdField("rowNum");
     $row = $csv->get(3);
     $newFirstName = "Updated-" . $row["firstName"];
     $row["firstName"] = $newFirstName;
     $existingLastName = $row["lastName"];
     unset($row["lastName"]);
     $updated = $csv->update($row);
     $this->assertTrue($updated);
     $row = $csv->get(3);
     $this->assertEquals($newFirstName, $row["firstName"]);
     $this->assertEquals($existingLastName, $row["lastName"]);
 }
开发者ID:g105b,项目名称:phpcsv,代码行数:19,代码来源:UpdateRecord.test.php

示例3: testNewLine

 /**
  * @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]);
 }
开发者ID:g105b,项目名称:phpcsv,代码行数:23,代码来源:Data.test.php

示例4: testEmptyLine

 /**
  * @dataProvider \g105b\phpcsv\TestHelper::data_randomFilePath
  */
 public function testEmptyLine($filePath)
 {
     TestHelper::createCsv($filePath);
     // Force a few empty lines into the file by reading it as an array,
     // clearing 10 random lines, then writing the file again.
     $lines = file($filePath);
     $totalLinesIncludingEmptyAndHeaders = count($lines);
     // Generate 10 random keys:
     $emptyRowArray = array_rand($lines, 10);
     // Make sure none of them are the header row:
     foreach ($emptyRowArray as $i => $emptyRow) {
         if ($emptyRow == 0) {
             do {
                 $emptyRow = array_rand($lines);
             } while (in_array($emptyRow, $emptyRowArray));
             $emptyRowArray[$i] = $emptyRow;
         }
     }
     foreach ($emptyRowArray as $emptyRow) {
         $lines[$emptyRow] = "\n";
     }
     // Write back the file.
     file_put_contents($filePath, implode("", $lines));
     $csv = new Csv($filePath);
     $this->assertInstanceOf("\\g105b\\phpcsv\\Csv", $csv);
     $rowCount = 1;
     try {
         foreach ($csv as $rowNumber => $columns) {
             $rowCount++;
             $this->assertNotEmpty($columns);
             $this->assertNotEmpty($columns["firstName"]);
         }
     } catch (Exception $e) {
         die("WHAT>???????????????");
     }
     $this->assertEquals($totalLinesIncludingEmptyAndHeaders - 10, $rowCount, "Should be 10 rows missing");
 }
开发者ID:g105b,项目名称:phpcsv,代码行数:40,代码来源:RetrieveRecord.test.php

示例5: testConstructsWithDirectory

 /**
  * @dataProvider \g105b\phpcsv\TestHelper::data_randomFilePath
  * @expectedException \g105b\phpcsv\InvalidPathException
  */
 public function testConstructsWithDirectory($filePath)
 {
     TestHelper::createCsv($filePath, 1);
     $filePath = dirname($filePath);
     $csv = new Csv($filePath);
 }
开发者ID:g105b,项目名称:phpcsv,代码行数:10,代码来源:CreateRecord.test.php

示例6: testFileNotDeletedWhenExists

 /**
  * @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);
 }
开发者ID:g105b,项目名称:phpcsv,代码行数:11,代码来源:LoadFile.test.php


注:本文中的TestHelper::createCsv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。