diff --git a/src/Bean.php b/src/Bean.php index 70422e7..5ae3c0a 100644 --- a/src/Bean.php +++ b/src/Bean.php @@ -186,8 +186,8 @@ protected function initiateProperties() : void $this->{$name} = \Infinityloop\Utils\Json::fromString($value); break; - case \Infinityloop\CoolBeans\PrimaryKey\IntPrimaryKey::class: - $this->{$name} = new \Infinityloop\CoolBeans\PrimaryKey\IntPrimaryKey($value); + case \CoolBeans\PrimaryKey\IntPrimaryKey::class: + $this->{$name} = new \CoolBeans\PrimaryKey\IntPrimaryKey($value); break; default: diff --git a/tests/Unit/BeanTest.php b/tests/Unit/BeanTest.php index 08dd3f7..f777a8d 100644 --- a/tests/Unit/BeanTest.php +++ b/tests/Unit/BeanTest.php @@ -160,16 +160,18 @@ public function testInitiateProperties() : void $activeRowMock->expects('offsetGet')->with('activated')->andReturn(1); $activeRowMock->expects('offsetGet')->with('inactive')->andReturn(0); $activeRowMock->expects('offsetGet')->with('json')->andReturn('{"id":"1"}'); + $activeRowMock->expects('offsetGet')->with('intPrimaryKey')->andReturn(10); $activeRowMock->expects('getPrimary')->with(false)->andReturn(['id' => $this->activeRowData['id']]); $beanInstance = new class($activeRowMock) extends \CoolBeans\Bean { public int $id; public bool $active = true; - public bool $ready; + public ?bool $ready; public bool $activated; public bool $inactive; public \Infinityloop\Utils\Json $json; + public \CoolBeans\PrimaryKey\IntPrimaryKey $intPrimaryKey; }; self::assertEquals($this->activeRowData['id'], $beanInstance->offsetGet('id')); @@ -180,6 +182,7 @@ public function testInitiateProperties() : void self::assertInstanceOf(\Infinityloop\Utils\Json::class, $beanInstance->offsetGet('json')); self::assertEquals(['id' => '1'], $beanInstance->offsetGet('json')->toArray()); self::assertEquals(true, (new \ReflectionMethod(\CoolBeans\Bean::class, 'initiateProperties'))->isProtected()); + self::assertEquals(10, $beanInstance->offsetGet('intPrimaryKey')->getValue()); } public function testInitiatePropertiesPropertyWithoutType() : void @@ -196,6 +199,20 @@ public function testInitiatePropertiesPropertyWithoutType() : void }; } + public function testInitiatePropertiesPropertyWithoutNullable() : void + { + $activeRowMock = \Mockery::mock(\Nette\Database\Table\ActiveRow::class); + $activeRowMock->expects('offsetGet')->with('nulled')->andReturn(null); + $activeRowMock->expects('getPrimary')->with(false)->andReturn(['id' => $this->activeRowData['id']]); + + $this->expectException(\CoolBeans\Exception\NonNullableType::class); + $this->expectExceptionMessage('Property [nulled] does not have nullable type.'); + + new class($activeRowMock) extends \CoolBeans\Bean { + public bool $nulled; + }; + } + public function testValidateMissingColumns() : void { $activeRowMock = \Mockery::mock(\Nette\Database\Table\ActiveRow::class);