Skip to content

Commit ef1bfbf

Browse files
TavoNiievezW0rmaVictor-Truhanovich
authored
Support doctrine/orm v3 + doctrine/dbal v4 (#26)
* Allow doctrine/orm v3 * Replace ramsey/uuid-doctrine with symfony/doctrine-bridge and symfony/uuid * Compatibility with doctrine/dbal v4 * Changed use of deprecated doctrine/orm connect method to use getNativeConnection method * Simplify DBAL connection parameters * Drop PHP 8.0 * Test against lowest dependency versions * Use attributes and annotations in tests * Skip phpstan if executed with lowest dependencies to avoid false-positives --------- Co-authored-by: W0rma <[email protected]> Co-authored-by: Viktor Truhanovich <[email protected]>
1 parent 3a5efca commit ef1bfbf

23 files changed

+154
-41
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ jobs:
88

99
strategy:
1010
matrix:
11-
php: [8.0, 8.1, 8.2, 8.3]
11+
php: [8.1, 8.2, 8.3]
12+
composer_flags: [ '', '--prefer-lowest' ]
1213

1314
steps:
1415
- name: Checkout code
@@ -25,10 +26,12 @@ jobs:
2526
run: composer validate
2627

2728
- name: Install dependencies
28-
run: composer install --prefer-dist --no-progress --no-interaction
29+
run: composer update --prefer-dist --no-progress --no-interaction ${{ matrix.composer_flags }}
2930

3031
- name: Run test suite
3132
run: php vendor/bin/codecept run
3233

3334
- name: Run source code analysis
35+
if: "${{ matrix.composer_flags == '' }}"
3436
run: php vendor/bin/phpstan
37+

composer.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,20 @@
1717
],
1818
"homepage": "https://codeception.com/",
1919
"require": {
20-
"php": "^8.0",
20+
"php": "^8.1",
2121
"ext-json": "*",
2222
"ext-pdo": "*",
23-
"codeception/codeception": "^5.0.0-alpha2"
23+
"codeception/codeception": "^5.1"
2424
},
2525
"require-dev": {
26-
"codeception/stub": "^4.0",
27-
"doctrine/annotations": "^1.13",
28-
"doctrine/data-fixtures": "^1.5",
29-
"doctrine/orm": "^2.10",
30-
"phpstan/phpstan": "^1.0",
31-
"ramsey/uuid-doctrine": "^1.6",
32-
"symfony/cache": "^4.4 || ^5.4 || ^6.0"
33-
},
34-
"conflict": {
35-
"codeception/codeception": "<5.0"
26+
"codeception/stub": "^4.1.3",
27+
"doctrine/annotations": "^2.0.1",
28+
"doctrine/data-fixtures": "^1.7",
29+
"doctrine/orm": "^2.14 || ^3.0",
30+
"phpstan/phpstan": "^1.10.58",
31+
"symfony/cache": "^5.4.35 || ^6.4.3 || ^7.0",
32+
"symfony/doctrine-bridge": "^5.4.35 || ^6.4.3 || ^7.0",
33+
"symfony/uid": "^5.4.35 || ^6.4.3 || ^7.0"
3634
},
3735
"minimum-stability": "dev",
3836
"autoload": {

src/Codeception/Module/Doctrine2.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ protected function retrieveEntityManager(): void
257257
);
258258
}
259259

260-
$this->em->getConnection()->connect();
260+
$this->em->getConnection()->getNativeConnection();
261261
}
262262

263263
/**
@@ -401,7 +401,12 @@ public function haveFakeRepository(string $className, array $methods = []): void
401401

402402
$reflectedRepositoryFactory = new ReflectionClass($repositoryFactory);
403403

404-
if ($reflectedRepositoryFactory->hasProperty('repositoryList')) {
404+
if ($repositoryFactoryProperty->isReadOnly()) {
405+
$this->debugSection(
406+
'Warning',
407+
'Repository can\'t be mocked, the EntityManager\'s repositoryFactory is readonly'
408+
);
409+
} elseif ($reflectedRepositoryFactory->hasProperty('repositoryList')) {
405410
$repositoryListProperty = $reflectedRepositoryFactory->getProperty('repositoryList');
406411
$repositoryListProperty->setAccessible(true);
407412

@@ -415,13 +420,13 @@ public function haveFakeRepository(string $className, array $methods = []): void
415420
} else {
416421
$this->debugSection(
417422
'Warning',
418-
'Repository can\'t be mocked, the EventManager\'s repositoryFactory doesn\'t have "repositoryList" property'
423+
'Repository can\'t be mocked, the EntityManager\'s repositoryFactory doesn\'t have "repositoryList" property'
419424
);
420425
}
421426
} else {
422427
$this->debugSection(
423428
'Warning',
424-
'Repository can\'t be mocked, the EventManager class doesn\'t have "repositoryFactory" or "repositories" property'
429+
'Repository can\'t be mocked, the EntityManager class doesn\'t have "repositoryFactory" or "repositories" property'
425430
);
426431
}
427432
}

tests/data/doctrine2_entities/CircularRelations/A.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,25 @@
1010
* @ORM\Entity
1111
* @ORM\Table(name="circular_a")
1212
*/
13+
#[ORM\Entity]
14+
#[ORM\Table(name: 'circular_a')]
1315
class A
1416
{
1517
/**
1618
* @ORM\Id
1719
* @ORM\Column(type="integer")
1820
* @ORM\GeneratedValue
1921
*/
22+
#[ORM\Id]
23+
#[ORM\Column(type: 'integer')]
24+
#[ORM\GeneratedValue]
2025
private ?int $id = null;
2126

2227
/**
2328
* @var ArrayCollection
2429
* @ORM\OneToMany(targetEntity="C", mappedBy="a")
2530
*/
31+
#[ORM\OneToMany(targetEntity: C::class, mappedBy: 'a')]
2632
private Collection $cs;
2733

2834
public function __construct()

tests/data/doctrine2_entities/CircularRelations/B.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,25 @@
1010
* @ORM\Entity
1111
* @ORM\Table(name="circular_b")
1212
*/
13+
#[ORM\Entity]
14+
#[ORM\Table(name: 'circular_b')]
1315
class B
1416
{
1517
/**
1618
* @ORM\Id
1719
* @ORM\Column(type="integer")
1820
* @ORM\GeneratedValue
1921
*/
22+
#[ORM\Id]
23+
#[ORM\Column(type: 'integer')]
24+
#[ORM\GeneratedValue]
2025
private ?int $id = null;
2126

2227
/**
2328
* @var ArrayCollection
2429
* @ORM\OneToMany(targetEntity="C", mappedBy="b")
2530
*/
31+
#[ORM\OneToMany(targetEntity: C::class, mappedBy: 'b')]
2632
private Collection $cs;
2733

2834
public function __construct()

tests/data/doctrine2_entities/CircularRelations/C.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@
88
* @ORM\Entity
99
* @ORM\Table(name="circular_c")
1010
*/
11+
#[ORM\Entity]
12+
#[ORM\Table(name: 'circular_c')]
1113
class C
1214
{
1315
/**
1416
* @ORM\Id
1517
* @ORM\ManyToOne(targetEntity="A", inversedBy="cs", cascade={"persist"})
1618
*/
19+
#[ORM\Id]
20+
#[ORM\ManyToOne(targetEntity: A::class, inversedBy: 'cs', cascade: ['persist'])]
1721
private ?A $a;
1822

1923
/**
2024
* @ORM\Id
2125
* @ORM\ManyToOne(targetEntity="B", inversedBy="cs", cascade={"persist"})
2226
*/
27+
#[ORM\Id]
28+
#[ORM\ManyToOne(targetEntity: B::class, inversedBy: 'cs', cascade: ['persist'])]
2329
private ?B $b;
2430

2531
public function __construct(A $a, B $b)

tests/data/doctrine2_entities/CompositePrimaryKeyEntity.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@
55
/**
66
* @ORM\Entity
77
*/
8+
#[ORM\Entity]
89
class CompositePrimaryKeyEntity
910
{
1011
/**
1112
* @ORM\Id
1213
* @ORM\Column(type="integer")
1314
*/
15+
#[ORM\Id]
16+
#[ORM\Column(type: 'integer')]
1417
private int $integerPart;
1518

1619
/**
1720
*
1821
* @ORM\Id
1922
* @ORM\Column(type="string")
2023
*/
24+
#[ORM\Id]
25+
#[ORM\Column(type: 'string')]
2126
private string $stringPart;
2227
}

tests/data/doctrine2_entities/EntityWithConstructorParameters.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,35 @@
55
/**
66
* @ORM\Entity
77
*/
8+
#[ORM\Entity]
89
class EntityWithConstructorParameters
910
{
1011
/**
1112
* @ORM\Id
1213
* @ORM\Column(type="integer")
1314
* @ORM\GeneratedValue
1415
*/
16+
#[ORM\Id]
17+
#[ORM\Column(type: 'integer')]
18+
#[ORM\GeneratedValue]
1519
private int $id;
1620

1721
/**
1822
* @ORM\Column(type="string", nullable=true)
1923
*/
24+
#[ORM\Column(type: 'string', nullable: true)]
2025
private ?string $name = null;
2126

2227
/**
2328
* @ORM\Column(type="string", nullable=true)
2429
*/
30+
#[ORM\Column(type: 'string', nullable: true)]
2531
private ?string $foo = null;
2632

2733
/**
2834
* @ORM\Column(type="string")
2935
*/
36+
#[ORM\Column(type: 'string')]
3037
private string $bar = '';
3138

3239
public function __construct($name, $foo = null, $bar = 'foobar')

tests/data/doctrine2_entities/EntityWithEmbeddable.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/**
66
* @ORM\Entity
77
*/
8+
#[ORM\Entity]
89
class EntityWithEmbeddable
910
{
1011
/**
@@ -13,11 +14,15 @@ class EntityWithEmbeddable
1314
* @ORM\Column(type="integer")
1415
* @ORM\GeneratedValue
1516
*/
17+
#[ORM\Id]
18+
#[ORM\Column(type: 'integer')]
19+
#[ORM\GeneratedValue]
1620
private int $id;
1721

1822
/**
1923
* @ORM\Embedded(class="SampleEmbeddable")
2024
*/
25+
#[ORM\Embedded(class: SampleEmbeddable::class)]
2126
private SampleEmbeddable $embed;
2227

2328
public function __construct()

tests/data/doctrine2_entities/EntityWithUuid.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
<?php
22

33
use Doctrine\ORM\Mapping as ORM;
4-
use Ramsey\Uuid\Uuid;
5-
use Ramsey\Uuid\UuidInterface;
4+
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
5+
use Symfony\Component\Uid\Uuid;
66

77
/**
88
* @ORM\Entity
99
*/
10+
#[ORM\Entity]
1011
class EntityWithUuid
1112
{
1213
/**
1314
* @ORM\Id
1415
* @ORM\Column(type="uuid", unique=true)
1516
* @ORM\GeneratedValue(strategy="CUSTOM")
16-
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
17+
* @ORM\CustomIdGenerator(class="Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator")
1718
*/
18-
private ?UuidInterface $id = null;
19+
#[ORM\Id]
20+
#[ORM\Column(type: 'uuid', unique: true)]
21+
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
22+
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
23+
private ?Uuid $id = null;
1924

2025
public function __construct()
2126
{
22-
$this->id = Uuid::uuid4();
27+
$this->id = Uuid::v4();
2328
}
2429

25-
public function getId(): UuidInterface
30+
public function getId(): Uuid
2631
{
2732
return $this->id;
2833
}

0 commit comments

Comments
 (0)