Skip to content

Commit

Permalink
Merge pull request #6 from keboola/webrouse-COM-596-fix-incremental-def
Browse files Browse the repository at this point in the history
Fix default value of the incremental attribute
  • Loading branch information
michaljurecko authored Jan 20, 2021
2 parents f3abf0d + 48748d1 commit c5163f1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/Keboola/CsvTable/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Table extends CsvWriter {
/** @var string */
protected $name;

/** @var bool */
/** @var bool|null */
protected $incremental = null;

/** @var array */
Expand Down Expand Up @@ -75,11 +75,20 @@ public function getAttributes(): array

public function setIncremental(bool $incremental): void
{
$this->incremental = (bool) $incremental;
$this->incremental = $incremental;
}

public function isIncrementalSet(): bool
{
return $this->incremental !== null;
}

public function getIncremental(): bool
{
if ($this->incremental === null) {
throw new \UnexpectedValueException('Incremental is not set.');
}

return $this->incremental;
}

Expand Down
25 changes: 24 additions & 1 deletion tests/Keboola/CsvTable/TableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Keboola\CsvTable\Table;
use PHPUnit\Framework\TestCase;

class TempTest extends TestCase
class TableTest extends TestCase
{
public function testCreate()
{
Expand Down Expand Up @@ -60,4 +60,27 @@ public function testPrimaryKeyEmpty()
$table = new Table('pk', ['id', 'user', 'data']);
$this->assertNull($table->getPrimaryKey());
}

public function testIncrementalNoValue()
{
$table = new Table('pk', ['id', 'user', 'data']);
$this->assertFalse($table->isIncrementalSet());

$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Incremental is not set.');
$table->getIncremental();
}

public function testIncrementalSetValue()
{
$table = new Table('pk', ['id', 'user', 'data']);

$table->setIncremental(true);
$this->assertTrue($table->isIncrementalSet());
$this->assertTrue($table->getIncremental());

$table->setIncremental(false);
$this->assertTrue($table->isIncrementalSet());
$this->assertFalse($table->getIncremental());
}
}

0 comments on commit c5163f1

Please sign in to comment.