Skip to content

Commit

Permalink
style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
OriHoch committed Nov 30, 2017
1 parent a426214 commit 414d60d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
12 changes: 9 additions & 3 deletions src/DataSources/CsvDataSource.php
Expand Up @@ -88,10 +88,16 @@ public function getNextLine()
{
$row = $this->nextRow;
if ($row === null) {
if (!$this->resource) $this->open();
if ($this->isEof()) throw new \Exception("EOF");
if (!$this->resource) {
$this->open();
}
if ($this->isEof()) {
throw new \Exception('EOF');
}
$row = $this->nextRow;
if ($row === null) throw new \Exception("cannot get valid row, but isEof returns false");
if ($row === null) {
throw new \Exception('cannot get valid row, but isEof returns false');
}
}
$this->nextRow = null;
$colNum = 0;
Expand Down
29 changes: 14 additions & 15 deletions tests/TableTest.php
Expand Up @@ -345,18 +345,16 @@ public function testReadOptions()

public function testInvalidTabularData()
{

$schema = new Schema((object) [
"fields" => [
(object) ["name" => "id", "type" => "integer"],
(object) ["name" => "email", "type" => "string", "format" => "email"]
]
'fields' => [
(object) ['name' => 'id', 'type' => 'integer'],
(object) ['name' => 'email', 'type' => 'string', 'format' => 'email'],
],
]);
$dataSource = new CsvDataSource($this->fixture('invalid_tabular_data.csv'));
$table = new Table($dataSource, $schema);
try {
foreach ($table as $row) {

}
$this->assertTrue(false);
} catch (\Exception $e) {
Expand All @@ -378,35 +376,36 @@ public function testInvalidTabularData()
}
$this->assertEquals(
['id' => '1', 'email' => 'good@email.and.nice'],
$table->read(["cast" => false])[0]
$table->read(['cast' => false])[0]
);
}

public function testEmailsTabularData()
{
$schema = new Schema((object) [
"fields" => [
(object) ["name" => "id", "type" => "integer"],
(object) ["name" => "email", "type" => "string", "format" => "email"]
]
'fields' => [
(object) ['name' => 'id', 'type' => 'integer'],
(object) ['name' => 'email', 'type' => 'string', 'format' => 'email'],
],
]);
$dataSource = new CsvDataSource($this->fixture('valid_emails_tabular_data.csv'));
$table = new Table($dataSource, $schema);
foreach ($table as $row) {}
foreach ($table as $row) {
}
$dataSource = new CsvDataSource($this->fixture('valid_emails_tabular_data.csv'));
$table = new Table($dataSource, $schema);
$this->assertEquals(
['id' => '1', 'email' => 'good@email.and.nice'],
$table->read(["cast" => false])[0]
$table->read(['cast' => false])[0]
);
}

public function testIterateWithoutEof()
{
$dataSource = new CsvDataSource($this->fixture('valid_emails_tabular_data.csv'));
$row = $dataSource->getNextLine();
$this->assertTrue($row["id"] === '1');
$this->assertTrue($row["email"] === 'good@email.and.nice');
$this->assertTrue($row['id'] === '1');
$this->assertTrue($row['email'] === 'good@email.and.nice');
}

protected $fixturesPath;
Expand Down

0 comments on commit 414d60d

Please sign in to comment.