diff --git a/src/Keboola/CsvTable/Table.php b/src/Keboola/CsvTable/Table.php index 78b7591..1c88baf 100755 --- a/src/Keboola/CsvTable/Table.php +++ b/src/Keboola/CsvTable/Table.php @@ -22,7 +22,7 @@ class Table extends CsvWriter { /** @var string */ protected $name; - /** @var bool */ + /** @var bool|null */ protected $incremental = null; /** @var array */ @@ -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; } diff --git a/tests/Keboola/CsvTable/TableTest.php b/tests/Keboola/CsvTable/TableTest.php index 8662e76..87f5876 100755 --- a/tests/Keboola/CsvTable/TableTest.php +++ b/tests/Keboola/CsvTable/TableTest.php @@ -4,7 +4,7 @@ use Keboola\CsvTable\Table; use PHPUnit\Framework\TestCase; -class TempTest extends TestCase +class TableTest extends TestCase { public function testCreate() { @@ -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()); + } }