本文整理汇总了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);
}
示例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"]);
}
示例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]);
}
示例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");
}
示例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);
}
示例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);
}