Skip to content

Commit ddb97c1

Browse files
Added tests for Snowflake identifiers as well as updated tests for UUID and ULID
1 parent 09c697e commit ddb97c1

34 files changed

+1268
-61
lines changed

tests/Identifier/Fixtures/Combined/MultipleIdentifiers.php

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,27 @@
66

77
use Cycle\Annotated\Annotation\Column;
88
use Cycle\Annotated\Annotation\Entity;
9-
use Cycle\ORM\Entity\Behavior\Identifier\Ulid;
10-
use Cycle\ORM\Entity\Behavior\Identifier\Uuid4;
11-
use Ramsey\Identifier\Ulid as UlidInterface;
9+
use Cycle\ORM\Entity\Behavior\Identifier;
10+
use Ramsey\Identifier\Snowflake;
11+
use Ramsey\Identifier\Ulid;
1212
use Ramsey\Identifier\Uuid;
1313

1414
/**
1515
* @Entity
16-
* @Uuid4
17-
* @Uuid4(field="uuidNullable", column="uuid_nullable", nullable=true)
18-
* @Ulid(field="ulid")
19-
* @Ulid(field="ulidNullable", column="ulid_nullable", nullable=true)
16+
* @Identifier\Uuid4
17+
* @Identifier\Uuid4(field="uuidNullable", column="uuid_nullable", nullable=true)
18+
* @Identifier\Ulid(field="ulid")
19+
* @Identifier\Ulid(field="ulidNullable", column="ulid_nullable", nullable=true)
20+
* @Identifier\SnowflakeGeneric(field="snowflake")
21+
* @Identifier\SnowflakeGeneric(field="snowflakeNullable", column="snowflake_nullable", nullable=true)
2022
*/
2123
#[Entity]
22-
#[Uuid4]
23-
#[Uuid4(field: 'uuidNullable', column: 'uuid_nullable', nullable: true)]
24-
#[Ulid(field: 'ulid')]
25-
#[Uuid4(field: 'ulidNullable', column: 'ulid_nullable', nullable: true)]
24+
#[Identifier\Uuid4]
25+
#[Identifier\Uuid4(field: 'uuidNullable', column: 'uuid_nullable', nullable: true)]
26+
#[Identifier\Ulid(field: 'ulid')]
27+
#[Identifier\Uuid4(field: 'ulidNullable', column: 'ulid_nullable', nullable: true)]
28+
#[Identifier\SnowflakeGeneric(field: 'snowflake')]
29+
#[Identifier\SnowflakeGeneric(field: 'snowflakeNullable', column: 'snowflake_nullable', nullable: true)]
2630
class MultipleIdentifiers
2731
{
2832
/**
@@ -41,11 +45,23 @@ class MultipleIdentifiers
4145
* @Column(type="ulid")
4246
*/
4347
#[Column(type: 'ulid')]
44-
public UlidInterface $ulid;
48+
public Ulid $ulid;
4549

4650
/**
4751
* @Column(type="ulid", nullable=true)
4852
*/
4953
#[Column(type: 'ulid')]
50-
public ?UlidInterface $ulidNullable = null;
54+
public ?Ulid $ulidNullable = null;
55+
56+
/**
57+
* @Column(type="snowflake")
58+
*/
59+
#[Column(type: 'snowflake')]
60+
public Snowflake $snowflake;
61+
62+
/**
63+
* @Column(type="snowflake", nullable=true)
64+
*/
65+
#[Column(type: 'snowflake')]
66+
public ?Snowflake $snowflakeNullable = null;
5167
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\ORM\Entity\Behavior\Identifier\Tests\Fixtures\Snowflake;
6+
7+
use Cycle\Annotated\Annotation\Column;
8+
use Cycle\Annotated\Annotation\Entity;
9+
use Cycle\ORM\Entity\Behavior\Identifier;
10+
use Ramsey\Identifier\Snowflake;
11+
12+
/**
13+
* @Entity
14+
* @Identifier\SnowflakeGeneric
15+
* @Identifier\SnowflakeDiscord(field="discord")
16+
* @Identifier\SnowflakeInstagram(field="instagram")
17+
* @Identifier\SnowflakeMastodon(field="mastodon")
18+
* @Identifier\SnowflakeTwitter(field="twitter")
19+
*/
20+
#[Entity]
21+
#[Identifier\SnowflakeGeneric]
22+
#[Identifier\SnowflakeDiscord(field: 'discord')]
23+
#[Identifier\SnowflakeInstagram(field: 'instagram')]
24+
#[Identifier\SnowflakeMastodon(field: 'mastodon')]
25+
#[Identifier\SnowflakeTwitter(field: 'twitter')]
26+
class MultipleSnowflake
27+
{
28+
/**
29+
* @Column(type="snowflake", primary=true)
30+
*/
31+
#[Column(type: 'snowflake', primary: true)]
32+
public Snowflake $snowflake;
33+
34+
/**
35+
* @Column(type="snowflake")
36+
*/
37+
#[Column(type: 'snowflake')]
38+
public Snowflake $discord;
39+
40+
/**
41+
* @Column(type="snowflake")
42+
*/
43+
#[Column(type: 'snowflake')]
44+
public Snowflake $instagram;
45+
46+
/**
47+
* @Column(type="snowflake")
48+
*/
49+
#[Column(type: 'snowflake')]
50+
public Snowflake $mastodon;
51+
52+
/**
53+
* @Column(type="snowflake")
54+
*/
55+
#[Column(type: 'snowflake')]
56+
public Snowflake $twitter;
57+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\ORM\Entity\Behavior\Identifier\Tests\Fixtures\Snowflake;
6+
7+
use Cycle\Annotated\Annotation\Column;
8+
use Cycle\Annotated\Annotation\Entity;
9+
use Cycle\ORM\Entity\Behavior\Identifier;
10+
use Ramsey\Identifier\Snowflake;
11+
12+
/**
13+
* @Entity
14+
* @Identifier\SnowflakeGeneric
15+
* @Identifier\SnowflakeGeneric(field="notDefinedSnowflake", column="not_defined_snowflake", nullable=true)
16+
*/
17+
#[Entity]
18+
#[Identifier\SnowflakeGeneric]
19+
#[Identifier\SnowflakeGeneric(field: 'notDefinedSnowflake', column: 'not_defined_snowflake', nullable: true)]
20+
final class NullableSnowflake
21+
{
22+
/**
23+
* @Column(type="snowflake", primary=true)
24+
*/
25+
#[Column(type: 'snowflake', primary: true)]
26+
public Snowflake $snowflake;
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\ORM\Entity\Behavior\Identifier\Tests\Fixtures\Snowflake;
6+
7+
use Cycle\Annotated\Annotation\Column;
8+
use Cycle\Annotated\Annotation\Entity;
9+
use Cycle\ORM\Entity\Behavior\Identifier;
10+
11+
/**
12+
* @Entity
13+
* @Identifier\SnowflakeGeneric(field="customSnowflake", column="custom_snowflake")
14+
*/
15+
#[Entity]
16+
#[Identifier\SnowflakeGeneric(field: 'customSnowflake', column: 'custom_snowflake')]
17+
class Post
18+
{
19+
/**
20+
* @Column(type="primary")
21+
*/
22+
#[Column(type: 'primary')]
23+
public int $id;
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cycle\ORM\Entity\Behavior\Identifier\Tests\Fixtures\Snowflake;
6+
7+
use Cycle\Annotated\Annotation\Column;
8+
use Cycle\Annotated\Annotation\Entity;
9+
use Cycle\ORM\Entity\Behavior\Identifier;
10+
use Ramsey\Identifier\Snowflake;
11+
12+
/**
13+
* @Entity
14+
* @Identifier\SnowflakeGeneric
15+
*/
16+
#[Entity]
17+
#[Identifier\SnowflakeGeneric]
18+
class User
19+
{
20+
/**
21+
* @Column(type="snowflake", primary=true)
22+
*/
23+
#[Column(type: 'snowflake', primary: true)]
24+
public Snowflake $snowflake;
25+
}

tests/Identifier/Fixtures/Ulid/MultipleUlid.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@
66

77
use Cycle\Annotated\Annotation\Column;
88
use Cycle\Annotated\Annotation\Entity;
9-
use Cycle\ORM\Entity\Behavior\Identifier\Ulid;
10-
use Ramsey\Identifier\Ulid as UlidInterface;
9+
use Cycle\ORM\Entity\Behavior\Identifier;
10+
use Ramsey\Identifier\Ulid;
1111

1212
/**
1313
* @Entity
14-
* @Ulid
15-
* @Ulid(field="fooUlid", column="foo_ulid")
16-
* @Ulid(field="bar")
14+
* @Identifier\Ulid
15+
* @Identifier\Ulid(field="fooUlid", column="foo_ulid")
16+
* @Identifier\Ulid(field="bar")
1717
*/
1818
#[Entity]
19-
#[Ulid]
20-
#[Ulid(field: 'fooUlid', column: 'foo_ulid')]
21-
#[Ulid(field: 'bar')]
19+
#[Identifier\Ulid]
20+
#[Identifier\Ulid(field: 'fooUlid', column: 'foo_ulid')]
21+
#[Identifier\Ulid(field: 'bar')]
2222
final class MultipleUlid
2323
{
2424
/**
2525
* @Column(type="ulid", primary=true)
2626
*/
2727
#[Column(type: 'ulid', primary: true)]
28-
public UlidInterface $ulid;
28+
public Ulid $ulid;
2929

3030
/**
3131
* @Column(type="ulid", name="foo_ulid")
3232
*/
3333
#[Column(type: 'ulid', name: 'foo_ulid')]
34-
public UlidInterface $fooUlid;
34+
public Ulid $fooUlid;
3535

3636
/**
3737
* @Column(type="ulid")
3838
*/
3939
#[Column(type: 'ulid')]
40-
public UlidInterface $bar;
40+
public Ulid $bar;
4141
}

tests/Identifier/Fixtures/Ulid/NullableUlid.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66

77
use Cycle\Annotated\Annotation\Column;
88
use Cycle\Annotated\Annotation\Entity;
9-
use Cycle\ORM\Entity\Behavior\Identifier\Ulid;
10-
use Ramsey\Identifier\Ulid as UlidInterface;
9+
use Cycle\ORM\Entity\Behavior\Identifier;
10+
use Ramsey\Identifier\Ulid;
1111

1212
/**
1313
* @Entity
14-
* @Ulid
15-
* @Ulid(field="notDefinedUlid", column="not_defined_ulid", nullable=true)
14+
* @Identifier\Ulid
15+
* @Identifier\Ulid(field="notDefinedUlid", column="not_defined_ulid", nullable=true)
1616
*/
1717
#[Entity]
18-
#[Ulid]
19-
#[Ulid(field: 'notDefinedUlid', column: 'not_defined_ulid', nullable: true)]
18+
#[Identifier\Ulid]
19+
#[Identifier\Ulid(field: 'notDefinedUlid', column: 'not_defined_ulid', nullable: true)]
2020
final class NullableUlid
2121
{
2222
/**
2323
* @Column(type="ulid", primary=true)
2424
*/
2525
#[Column(type: 'ulid', primary: true)]
26-
public UlidInterface $ulid;
26+
public Ulid $ulid;
2727
}

tests/Identifier/Fixtures/Ulid/Post.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
use Cycle\Annotated\Annotation\Column;
88
use Cycle\Annotated\Annotation\Entity;
9-
use Cycle\ORM\Entity\Behavior\Identifier\Ulid;
9+
use Cycle\ORM\Entity\Behavior\Identifier;
1010

1111
/**
1212
* @Entity
13-
* @Ulid(field="customUlid", column="custom_ulid")
13+
* @Identifier\Ulid(field="customUlid", column="custom_ulid")
1414
*/
1515
#[Entity]
16-
#[Ulid(field: 'customUlid', column: 'custom_ulid')]
16+
#[Identifier\Ulid(field: 'customUlid', column: 'custom_ulid')]
1717
class Post
1818
{
1919
/**

tests/Identifier/Fixtures/Ulid/User.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66

77
use Cycle\Annotated\Annotation\Column;
88
use Cycle\Annotated\Annotation\Entity;
9-
use Cycle\ORM\Entity\Behavior\Identifier\Ulid;
10-
use Ramsey\Identifier\Ulid as UlidInterface;
9+
use Cycle\ORM\Entity\Behavior\Identifier;
10+
use Ramsey\Identifier\Ulid;
1111

1212
/**
1313
* @Entity
14-
* @Ulid
14+
* @Identifier\Ulid
1515
*/
1616
#[Entity]
17-
#[Ulid]
17+
#[Identifier\Ulid]
1818
class User
1919
{
2020
/**
2121
* @Column(type="ulid", primary=true)
2222
*/
2323
#[Column(type: 'ulid', primary: true)]
24-
public UlidInterface $ulid;
24+
public Ulid $ulid;
2525
}

tests/Identifier/Fixtures/Uuid/MultipleUuid.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@
66

77
use Cycle\Annotated\Annotation\Column;
88
use Cycle\Annotated\Annotation\Entity;
9-
use Cycle\ORM\Entity\Behavior\Identifier\Uuid1;
10-
use Cycle\ORM\Entity\Behavior\Identifier\Uuid7;
9+
use Cycle\ORM\Entity\Behavior\Identifier;
1110
use Ramsey\Identifier\Uuid;
1211

1312
/**
1413
* @Entity
15-
* @Uuid1
16-
* @Uuid1(field="otherUuid", column="other_uuid")
17-
* @Uuid7(field="uuid7")
18-
* @Uuid7(field="otherUuid7", column="other_uuid7")
14+
* @Identifier\Uuid1
15+
* @Identifier\Uuid1(field="otherUuid", column="other_uuid")
16+
* @Identifier\Uuid7(field="uuid7")
17+
* @Identifier\Uuid7(field="otherUuid7", column="other_uuid7")
1918
*/
2019
#[Entity]
21-
#[Uuid1]
22-
#[Uuid1(field: 'otherUuid', column: 'other_uuid')]
23-
#[Uuid7(field: 'uuid7')]
24-
#[Uuid7(field: 'otherUuid7', column: 'other_uuid7')]
20+
#[Identifier\Uuid1]
21+
#[Identifier\Uuid1(field: 'otherUuid', column: 'other_uuid')]
22+
#[Identifier\Uuid7(field: 'uuid7')]
23+
#[Identifier\Uuid7(field: 'otherUuid7', column: 'other_uuid7')]
2524
final class MultipleUuid
2625
{
2726
/**

0 commit comments

Comments
 (0)