Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Doctrine 3 compatibility #331

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
name: PHPStan
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: PHPStan
uses: docker://oskarstark/phpstan-ga
env:
Expand All @@ -29,7 +29,7 @@ jobs:
name: PHP-CS-Fixer
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Fix CS
uses: docker://oskarstark/php-cs-fixer-ga
tests:
Expand All @@ -45,15 +45,17 @@ jobs:
php: '8.1'
- description: '8.2'
php: '8.2'
- description: '8.3'
php: '8.3'
- description: 'Dev deps'
php: '8.2'
php: '8.3'
dev: true
name: PHP ${{ matrix.php }} tests (${{ matrix.description }})
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.composer/cache/files
key: ${{ matrix.php }}-${{ matrix.symfony }}-${{ matrix.composer_option }}
Expand All @@ -65,6 +67,9 @@ jobs:
- name: Configure for PHP 8.1
run: composer require --dev --no-update laminas/laminas-code 4.12.0
if: matrix.php == '8.1'
- name: Get jackalope dev
run: composer require jackalope/jackalope-doctrine-dbal ^2.0@dev doctrine/phpcr-odm ^2.0@dev jackalope/jackalope ^2.0@dev --no-update --dev
if: matrix.dev
- name: Go for dev dependencies
run: composer config minimum-stability dev && composer config prefer-stable true
if: matrix.dev
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
"require-dev": {
"ext-pdo_sqlite": "*",
"doctrine/mongodb-odm": "^2.4",
"doctrine/orm": "^2.12",
"doctrine/phpcr-odm": "^1.6",
"jackalope/jackalope-doctrine-dbal": "^1.8",
"phpunit/phpunit": "^9.5",
"doctrine/orm": "^2.12 || ^3.0",
"doctrine/phpcr-odm": "^2.0@dev",
"jackalope/jackalope": "^2.0@dev",
"jackalope/jackalope-doctrine-dbal": "^2.0@dev",
"phpunit/phpunit": "^9.6",
"propel/propel1": "^1.7",
"ruflin/elastica": "^7.0",
"solarium/solarium": "^6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
$qb = clone $target;

//reset count orderBy since it can break query and slow it down
$qb
->resetQueryPart('orderBy')
;

if (method_exists($qb, 'resetOrderBy')) {
$qb->resetOrderBy();
} else {
$qb->resetQueryParts();

Check failure on line 28 in src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/DBALQueryBuilderSubscriber.php

View workflow job for this annotation

GitHub Actions / PHPStan

Call to an undefined method Doctrine\DBAL\Query\QueryBuilder::resetQueryParts().
}

// get the query
$sql = $qb->getSQL();

$qb
->resetQueryParts()
->select('count(*) as cnt')
->from('(' . $sql . ')', 'dbal_count_tbl')
;
Expand Down
20 changes: 5 additions & 15 deletions tests/Test/Fixture/Document/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,19 @@

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
* @ODM\Document
*/
#[ODM\Document]
final class Article
{
/**
* @ODM\Id
*/
#[ODM\Id]
private $id;

/**
* @ODM\Field(type="string")
*/
#[ODM\Field(type: "string")]
private ?string $title = null;

/**
* @ODM\Field(type="bool", name="status")
*/
#[ODM\Field(type: "bool")]
private bool $status = false;

/**
* @ODM\Field(type="date", name="created_at")
*/
#[ODM\Field(type: "date", name: "created_at")]
private ?\DateTime $createdAt = null;

public function getId()
Expand Down
22 changes: 5 additions & 17 deletions tests/Test/Fixture/Document/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,30 @@

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
* @ODM\Document
*/
#[ODM\Document]
final class Image
{
/**
* @ODM\Id
*/
#[ODM\Id]
private $id;

/**
* @ODM\Field
*/
#[ODM\Field]
private ?string $title = null;

/**
* @ODM\File
* @var int|string
*/
#[ODM\File]
private $file;

/**
* Set file.
*
* @param int|string $file
*/
public function setFile($file): self
public function setFile($file): void
{
$this->file = $file;

return $this;
}

/**
* Get file.
*
* @return int|string
*/
public function getFile()
Expand Down
18 changes: 5 additions & 13 deletions tests/Test/Fixture/Document/PHPCR/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,18 @@

namespace Test\Fixture\Document\PHPCR;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR;

/**
* @PHPCR\Document
*/
#[PHPCR\Document]
final class Article
{
/**
* @PHPCR\Id
*/
#[PHPCR\Id]
private $id;

/**
* @PHPCR\ParentDocument
*/
#[PHPCR\ParentDocument]
private $parent;

/**
* @PHPCR\Field(type="string")
*/
#[PHPCR\Field(type: "string")]
private $title;

public function getId()
Expand Down
18 changes: 4 additions & 14 deletions tests/Test/Fixture/Entity/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,16 @@

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
#[ORM\Entity]
class Article
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
#[ORM\Id, ORM\GeneratedValue, ORM\Column(type: "integer")]
private $id;

/**
* @ORM\Column(length=64)
*/
#[ORM\Column(length: 64)]
private ?string $title = null;

/**
* @ORM\Column(type="boolean")
*/
#[ORM\Column(type: "boolean")]
private bool $enabled = true;

public function getId()
Expand Down
18 changes: 4 additions & 14 deletions tests/Test/Fixture/Entity/Composite.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,16 @@

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
#[ORM\Entity]
class Composite
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
*/
#[ORM\Id, ORM\Column(type: "integer")]
private $id;

/**
* @ORM\Column(length=64)
*/
#[ORM\Column(length: 64)]
private ?string $title = null;

/**
* @ORM\Id
* @ORM\Column(type="string")
*/
#[ORM\Id, ORM\Column(type: "string")]
private ?string $uid = null;

public function setUid(?string $uid): void
Expand Down
30 changes: 7 additions & 23 deletions tests/Test/Fixture/Entity/Shop/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,25 @@
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
#[ORM\Entity]
class Product
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
#[ORM\Id, ORM\GeneratedValue, ORM\Column(type: "integer")]
private $id;

/**
* @ORM\Column(length=64)
*/
#[ORM\Column(length: 64)]
private ?string $title = null;

/**
* @ORM\Column(length=255, nullable=true)
*/
#[ORM\Column(length: 255, nullable: true)]
private ?string $description = null;

/**
* @ORM\Column(type="float", nullable=false)
*/
#[ORM\Column(type: "float", nullable: true)]
private ?float $price = null;

/**
* @ORM\ManyToMany(targetEntity="Tag")
*/
#[ORM\ManyToMany(targetEntity: "Tag")]
private Collection $tags;

/**
* @ORM\Column(type="integer")
*/
#[ORM\Column(type: "integer")]
private int $numTags = 0;

public function __construct()
Expand Down
14 changes: 3 additions & 11 deletions tests/Test/Fixture/Entity/Shop/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*/
#[ORM\Entity]
class Tag
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
#[ORM\Id, ORM\GeneratedValue, ORM\Column(type: "integer")]
private $id;

/**
* @ORM\Column(length=64)
*/
#[ORM\Column(length: 64)]
private ?string $name = null;

public function getId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Test\Pager\Subscriber\Filtration\Doctrine\ORM;

use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManagerInterface;
use Knp\Component\Pager\ArgumentAccess\RequestArgumentAccess;
use Knp\Component\Pager\Event\Subscriber\Filtration\Doctrine\ORM\Query\WhereWalker;
Expand Down Expand Up @@ -39,8 +40,9 @@ public function shouldHandleApcQueryCache(): void
'memory' => true,
];

$em = \Doctrine\ORM\EntityManager::create($conn, $config);
$schema = \array_map(static function ($class) use ($em) {
$connection = DriverManager::getConnection($conn, $config);
$em = new \Doctrine\ORM\EntityManager($connection, $config);
$schema = \array_map(static function (string $class) use ($em) {
return $em->getClassMetadata($class);
}, $this->getUsedEntityFixtures());

Expand Down Expand Up @@ -756,7 +758,7 @@ public function shouldFilterCaseInsensitiveWhenAsked(): void
}

/**
* @return Article[]
* @return string[]
*/
protected function getUsedEntityFixtures(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Test\Pager\Subscriber\Sortable\Doctrine\ORM;

use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\SchemaTool;
use Knp\Component\Pager\ArgumentAccess\RequestArgumentAccess;
Expand Down Expand Up @@ -38,7 +39,8 @@ public function shouldHandleApcQueryCache(): void
'memory' => true,
];

$em = EntityManager::create($conn, $config);
$connection = DriverManager::getConnection($conn, $config);
$em = new EntityManager($connection, $config);
$schema = \array_map(static function ($class) use ($em) {
return $em->getClassMetadata($class);
}, $this->getUsedEntityFixtures());
Expand Down
Loading
Loading