Skip to content

Commit

Permalink
try to update the query analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
garak committed Mar 24, 2024
1 parent 0affd01 commit 00a041d
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 309 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
"ext-pdo_sqlite": "*",
"doctrine/mongodb-odm": "^2.4",
"doctrine/orm": "^2.12 || ^3.0",
"doctrine/phpcr-odm": "^1.6",
"jackalope/jackalope-doctrine-dbal": "^1.8 || ^2.0@dev",
"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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ public function items(ItemsEvent $event): void
$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
7 changes: 3 additions & 4 deletions tests/Test/Tool/BaseTestCaseMongoODM.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private function getMockAnnotatedConfig()
->method('getHydratorNamespace')
->willReturn('Hydrator');

$config->expects($this->any())
$config
->method('getDefaultDB')
->willReturn('knp_pager_tests');

Expand All @@ -123,18 +123,17 @@ private function getMockAnnotatedConfig()
->method('getClassMetadataFactoryName')
->willReturn(ClassMetadataFactory::class);

$config->expects($this->any())
$config
->method('getMongoCmd')
->willReturn('$');

$config
->expects($this->any())
->method('getDefaultCommitOptions')
->willReturn(['safe' => true])
;
$mappingDriver = $this->getMetadataDriverImplementation();

$config->expects($this->any())
$config
->method('getMetadataDriverImpl')
->willReturn($mappingDriver);

Expand Down
Loading

0 comments on commit 00a041d

Please sign in to comment.