Skip to content

Commit 690aa10

Browse files
Added test coverage for bigInteger handling within RegistryModifier
1 parent 63f31ac commit 690aa10

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

psalm-baseline.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="6.8.8@1361cd33008feb3ae2b4a93f1860e14e538ec8c2">
2+
<files psalm-version="6.12.1@e71404b0465be25cf7f8a631b298c01c5ddd864f">
33
<file src="src/CreatedAt.php">
44
<PropertyNotSetInConstructor>
55
<code><![CDATA[CreatedAt]]></code>
@@ -113,6 +113,9 @@
113113
<code><![CDATA[$columnName]]></code>
114114
<code><![CDATA[$columnName]]></code>
115115
<code><![CDATA[$columnName]]></code>
116+
<code><![CDATA[$columnName]]></code>
117+
<code><![CDATA[$columnName]]></code>
118+
<code><![CDATA[$columnName]]></code>
116119
<code><![CDATA[$rule]]></code>
117120
</ArgumentTypeCoercion>
118121
<ClassMustBeFinal>

tests/Behavior/Functional/Driver/Common/Schema/RegistryModifierTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Cycle\ORM\Entity\Behavior\Tests\Functional\Driver\Common\Schema;
66

77
use Cycle\Database\ColumnInterface;
8+
use Cycle\ORM\Entity\Behavior\Exception\BehaviorCompilationException;
89
use Cycle\ORM\Entity\Behavior\Schema\RegistryModifier;
910
use Cycle\ORM\Entity\Behavior\Tests\Fixtures\CustomTypecast;
1011
use Cycle\ORM\Entity\Behavior\Tests\Functional\Driver\Common\BaseTest;
@@ -57,6 +58,28 @@ public function testAddIntegerField(): void
5758
$this->assertSame('version_int', $fields->get('version')->getColumn());
5859
}
5960

61+
public function testAddBigIntegerField(): void
62+
{
63+
$this->modifier->addBigIntegerColumn('snowflake_column', 'snowflake');
64+
65+
$entity = $this->registry->getEntity(self::ROLE_TEST);
66+
$fields = $entity->getFields();
67+
68+
$this->assertTrue($fields->has('snowflake'));
69+
$this->assertSame('bigInteger', $fields->get('snowflake')->getType());
70+
$this->assertSame('snowflake_column', $fields->get('snowflake')->getColumn());
71+
}
72+
73+
public function testAddBigIntegerFieldThrowsException(): void
74+
{
75+
$this->modifier->addIntegerColumn('snowflake_column', 'snowflake');
76+
77+
$this->expectException(BehaviorCompilationException::class);
78+
$this->expectExceptionMessage('Field snowflake must be of type big integer.');
79+
80+
$this->modifier->addBigIntegerColumn('snowflake_column', 'snowflake');
81+
}
82+
6083
public function testAddUuidField(): void
6184
{
6285
$this->modifier->addUuidColumn('uuid_column', 'uuid');
@@ -73,15 +96,19 @@ public function testAddTypecast(): void
7396
{
7497
$this->modifier->addUuidColumn('uuid_column', 'uuid');
7598
$this->modifier->addIntegerColumn('counter_column', 'counter');
99+
$this->modifier->addBigIntegerColumn('snowflake_column', 'snowflake');
76100
$field1 = $this->registry->getEntity(self::ROLE_TEST)->getFields()->get('uuid');
77101
$field2 = $this->registry->getEntity(self::ROLE_TEST)->getFields()->get('counter');
102+
$field3 = $this->registry->getEntity(self::ROLE_TEST)->getFields()->get('snowflake');
78103

79104
$this->modifier->setTypecast($field1, [Uuid::class, 'fromString']);
80105
$this->modifier->setTypecast($field2, 'int', CustomTypecast::class);
106+
$this->modifier->setTypecast($field3, 'int', CustomTypecast::class);
81107

82108
// field has custom UUID typecast
83109
$this->assertSame([Uuid::class, 'fromString'], $field1->getTypecast());
84110
$this->assertSame('int', $field2->getTypecast());
111+
$this->assertSame('int', $field3->getTypecast());
85112

86113
// entity has default typecast
87114
$this->assertSame(

tests/Behavior/Unit/Schema/RegistryModifierTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public static function integerDataProvider(): \Traversable
2222
yield ['integer(4)'];
2323
}
2424

25+
public static function bigIntegerDataProvider(): \Traversable
26+
{
27+
yield ['bigint'];
28+
yield ['bigInteger'];
29+
}
30+
2531
public static function datetimeDataProvider(): \Traversable
2632
{
2733
yield ['datetime'];
@@ -61,6 +67,24 @@ public function testIsIntegerTypeFalse(mixed $type): void
6167
$this->assertFalse(RegistryModifier::isIntegerType($type));
6268
}
6369

70+
/**
71+
* @dataProvider bigIntegerDataProvider
72+
*/
73+
public function testIsBigIntegerTypeTrue(mixed $type): void
74+
{
75+
$this->assertTrue(RegistryModifier::isBigIntegerType($type));
76+
}
77+
78+
/**
79+
* @dataProvider datetimeDataProvider
80+
* @dataProvider stringDataProvider
81+
* @dataProvider invalidDataProvider
82+
*/
83+
public function testIsBigIntegerTypeFalse(mixed $type): void
84+
{
85+
$this->assertFalse(RegistryModifier::isBigIntegerType($type));
86+
}
87+
6488
/**
6589
* @dataProvider datetimeDataProvider
6690
*/

0 commit comments

Comments
 (0)