當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。