Skip to content

Commit

Permalink
Support doctrine/orm v3 + doctrine/dbal v4 (#26)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Feb 17, 2024
1 parent 3a5efca commit ef1bfbf
Show file tree
Hide file tree
Showing 23 changed files with 154 additions and 41 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ jobs:

strategy:
matrix:
php: [8.0, 8.1, 8.2, 8.3]
php: [8.1, 8.2, 8.3]
composer_flags: [ '', '--prefer-lowest' ]

steps:
- name: Checkout code
Expand All @@ -25,10 +26,12 @@ jobs:
run: composer validate

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

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

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

22 changes: 10 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@
],
"homepage": "https://codeception.com/",
"require": {
"php": "^8.0",
"php": "^8.1",
"ext-json": "*",
"ext-pdo": "*",
"codeception/codeception": "^5.0.0-alpha2"
"codeception/codeception": "^5.1"
},
"require-dev": {
"codeception/stub": "^4.0",
"doctrine/annotations": "^1.13",
"doctrine/data-fixtures": "^1.5",
"doctrine/orm": "^2.10",
"phpstan/phpstan": "^1.0",
"ramsey/uuid-doctrine": "^1.6",
"symfony/cache": "^4.4 || ^5.4 || ^6.0"
},
"conflict": {
"codeception/codeception": "<5.0"
"codeception/stub": "^4.1.3",
"doctrine/annotations": "^2.0.1",
"doctrine/data-fixtures": "^1.7",
"doctrine/orm": "^2.14 || ^3.0",
"phpstan/phpstan": "^1.10.58",
"symfony/cache": "^5.4.35 || ^6.4.3 || ^7.0",
"symfony/doctrine-bridge": "^5.4.35 || ^6.4.3 || ^7.0",
"symfony/uid": "^5.4.35 || ^6.4.3 || ^7.0"
},
"minimum-stability": "dev",
"autoload": {
Expand Down
13 changes: 9 additions & 4 deletions src/Codeception/Module/Doctrine2.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ protected function retrieveEntityManager(): void
);
}

$this->em->getConnection()->connect();
$this->em->getConnection()->getNativeConnection();
}

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

$reflectedRepositoryFactory = new ReflectionClass($repositoryFactory);

if ($reflectedRepositoryFactory->hasProperty('repositoryList')) {
if ($repositoryFactoryProperty->isReadOnly()) {
$this->debugSection(
'Warning',
'Repository can\'t be mocked, the EntityManager\'s repositoryFactory is readonly'
);
} elseif ($reflectedRepositoryFactory->hasProperty('repositoryList')) {
$repositoryListProperty = $reflectedRepositoryFactory->getProperty('repositoryList');
$repositoryListProperty->setAccessible(true);

Expand All @@ -415,13 +420,13 @@ public function haveFakeRepository(string $className, array $methods = []): void
} else {
$this->debugSection(
'Warning',
'Repository can\'t be mocked, the EventManager\'s repositoryFactory doesn\'t have "repositoryList" property'
'Repository can\'t be mocked, the EntityManager\'s repositoryFactory doesn\'t have "repositoryList" property'
);
}
} else {
$this->debugSection(
'Warning',
'Repository can\'t be mocked, the EventManager class doesn\'t have "repositoryFactory" or "repositories" property'
'Repository can\'t be mocked, the EntityManager class doesn\'t have "repositoryFactory" or "repositories" property'
);
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/data/doctrine2_entities/CircularRelations/A.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@
* @ORM\Entity
* @ORM\Table(name="circular_a")
*/
#[ORM\Entity]
#[ORM\Table(name: 'circular_a')]
class A
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue]
private ?int $id = null;

/**
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="C", mappedBy="a")
*/
#[ORM\OneToMany(targetEntity: C::class, mappedBy: 'a')]
private Collection $cs;

public function __construct()
Expand Down
6 changes: 6 additions & 0 deletions tests/data/doctrine2_entities/CircularRelations/B.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@
* @ORM\Entity
* @ORM\Table(name="circular_b")
*/
#[ORM\Entity]
#[ORM\Table(name: 'circular_b')]
class B
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue]
private ?int $id = null;

/**
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="C", mappedBy="b")
*/
#[ORM\OneToMany(targetEntity: C::class, mappedBy: 'b')]
private Collection $cs;

public function __construct()
Expand Down
6 changes: 6 additions & 0 deletions tests/data/doctrine2_entities/CircularRelations/C.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@
* @ORM\Entity
* @ORM\Table(name="circular_c")
*/
#[ORM\Entity]
#[ORM\Table(name: 'circular_c')]
class C
{
/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="A", inversedBy="cs", cascade={"persist"})
*/
#[ORM\Id]
#[ORM\ManyToOne(targetEntity: A::class, inversedBy: 'cs', cascade: ['persist'])]
private ?A $a;

/**
* @ORM\Id
* @ORM\ManyToOne(targetEntity="B", inversedBy="cs", cascade={"persist"})
*/
#[ORM\Id]
#[ORM\ManyToOne(targetEntity: B::class, inversedBy: 'cs', cascade: ['persist'])]
private ?B $b;

public function __construct(A $a, B $b)
Expand Down
5 changes: 5 additions & 0 deletions tests/data/doctrine2_entities/CompositePrimaryKeyEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@
/**
* @ORM\Entity
*/
#[ORM\Entity]
class CompositePrimaryKeyEntity
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
*/
#[ORM\Id]
#[ORM\Column(type: 'integer')]
private int $integerPart;

/**
*
* @ORM\Id
* @ORM\Column(type="string")
*/
#[ORM\Id]
#[ORM\Column(type: 'string')]
private string $stringPart;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,35 @@
/**
* @ORM\Entity
*/
#[ORM\Entity]
class EntityWithConstructorParameters
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue]
private int $id;

/**
* @ORM\Column(type="string", nullable=true)
*/
#[ORM\Column(type: 'string', nullable: true)]
private ?string $name = null;

/**
* @ORM\Column(type="string", nullable=true)
*/
#[ORM\Column(type: 'string', nullable: true)]
private ?string $foo = null;

/**
* @ORM\Column(type="string")
*/
#[ORM\Column(type: 'string')]
private string $bar = '';

public function __construct($name, $foo = null, $bar = 'foobar')
Expand Down
5 changes: 5 additions & 0 deletions tests/data/doctrine2_entities/EntityWithEmbeddable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* @ORM\Entity
*/
#[ORM\Entity]
class EntityWithEmbeddable
{
/**
Expand All @@ -13,11 +14,15 @@ class EntityWithEmbeddable
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue]
private int $id;

/**
* @ORM\Embedded(class="SampleEmbeddable")
*/
#[ORM\Embedded(class: SampleEmbeddable::class)]
private SampleEmbeddable $embed;

public function __construct()
Expand Down
17 changes: 11 additions & 6 deletions tests/data/doctrine2_entities/EntityWithUuid.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
<?php

use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Component\Uid\Uuid;

/**
* @ORM\Entity
*/
#[ORM\Entity]
class EntityWithUuid
{
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
* @ORM\CustomIdGenerator(class="Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator")
*/
private ?UuidInterface $id = null;
#[ORM\Id]
#[ORM\Column(type: 'uuid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?Uuid $id = null;

public function __construct()
{
$this->id = Uuid::uuid4();
$this->id = Uuid::v4();
}

public function getId(): UuidInterface
public function getId(): Uuid
{
return $this->id;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/data/doctrine2_entities/JoinedEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
/**
* @ORM\Entity
*/
#[ORM\Entity]
class JoinedEntity extends JoinedEntityBase
{
/**
* @ORM\Column(type="string", nullable=true)
*/
#[ORM\Column(type: 'string', nullable: true)]
private ?string $own = null;
}
6 changes: 6 additions & 0 deletions tests/data/doctrine2_entities/JoinedEntityBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
*/
#[ORM\Entity]
#[ORM\InheritanceType('JOINED')]
class JoinedEntityBase
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue]
private int $id;

/**
* @ORM\Column(type="string", nullable=true)
*/
#[ORM\Column(type: 'string', nullable: true)]
private ?string $inherited = null;
}
6 changes: 6 additions & 0 deletions tests/data/doctrine2_entities/MultilevelRelations/A.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,30 @@
/**
* @ORM\Entity
*/
#[ORM\Entity]
class A
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue]
private int $id;

/**
* @ORM\Column(type="string", nullable=true)
*/
#[ORM\Column(type: 'string', nullable: true)]
private ?string $name = null;

/**
* @var Collection|B[]
* @ORM\OneToMany(targetEntity="B", mappedBy="a")
*/
#[ORM\OneToMany(targetEntity: B::class, mappedBy: 'a')]
private Collection $b;

public function __construct()
Expand Down
Loading

0 comments on commit ef1bfbf

Please sign in to comment.