-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test interactions with readonly ids (#38)
In newer PHP versions (which this expands the test matrix to cover), using `readonly` id properties is an option and, generally, a good one. This adds tests to ensure it mimics the expected behavior.
- Loading branch information
Showing
8 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,9 @@ jobs: | |
php: | ||
- '7.4' | ||
- '8.0' | ||
- '8.1' | ||
- '8.2' | ||
- '8.3' | ||
|
||
steps: | ||
- name: Check out code | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Firehed\Mocktrine\Entities; | ||
|
||
use Doctrine\ORM\Mapping; | ||
|
||
/** | ||
* @Entity | ||
* @Table(name="readonly_constructor_ids") | ||
*/ | ||
#[Mapping\Entity] | ||
#[Mapping\Table(name: 'readonly_constructor_ids')] | ||
class ReadonlyConstructorId | ||
{ | ||
/** | ||
* @Id | ||
* @Column | ||
*/ | ||
#[Mapping\Id] | ||
#[Mapping\Column] | ||
public readonly string $id; | ||
|
||
public function __construct() | ||
{ | ||
// Normally this would be a UUID, ULID, etc. | ||
$this->id = bin2hex(random_bytes(10)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Firehed\Mocktrine\Entities; | ||
|
||
use Doctrine\ORM\Mapping; | ||
|
||
/** | ||
* @Entity | ||
* @Table(name="readonly_generated_ids") | ||
*/ | ||
#[Mapping\Entity] | ||
#[Mapping\Table(name: 'readonly_generated_ids')] | ||
class ReadonlyGeneratedId | ||
{ | ||
/** | ||
* @Id | ||
* @Column | ||
* @GeneratedValue | ||
*/ | ||
#[Mapping\Id] | ||
#[Mapping\Column] | ||
#[Mapping\GeneratedValue] | ||
public readonly int $id; | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/Entities/XmlMappings/Firehed.Mocktrine.Entities.ReadonlyConstructorId.dcm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctrine-mapping xmlns="https://doctrine-project.org/schemas/orm/doctrine-mapping" | ||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="https://doctrine-project.org/schemas/orm/doctrine-mapping | ||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> | ||
|
||
<entity name="Firehed\Mocktrine\Entities\ReadonlyConstructorId" table="readonly_constructor_ids"> | ||
|
||
<id name="id" type="string" column="id" /> | ||
|
||
</entity> | ||
|
||
</doctrine-mapping> |
15 changes: 15 additions & 0 deletions
15
tests/Entities/XmlMappings/Firehed.Mocktrine.Entities.ReadonlyGeneratedId.dcm.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<doctrine-mapping xmlns="https://doctrine-project.org/schemas/orm/doctrine-mapping" | ||
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="https://doctrine-project.org/schemas/orm/doctrine-mapping | ||
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> | ||
|
||
<entity name="Firehed\Mocktrine\Entities\ReadonlyGeneratedId" table="readonly_generated_ids"> | ||
|
||
<id name="id" type="int" column="id"> | ||
<generator strategy="AUTO"/> | ||
</id> | ||
|
||
</entity> | ||
|
||
</doctrine-mapping> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters