Skip to content

Commit

Permalink
Merge pull request #10 from vossik/master
Browse files Browse the repository at this point in the history
fixed BeanTest, fixed CoolBeans namespace
  • Loading branch information
peldax authored May 11, 2020
2 parents 558c76c + 14d3c96 commit e150069
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Bean.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 18 additions & 1 deletion tests/Unit/BeanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit e150069

Please sign in to comment.