From 11b02baefb619e2dc13d340cf2338d283f7b3eb0 Mon Sep 17 00:00:00 2001 From: Ian Lindsay <6673081+ilindsay@users.noreply.github.com> Date: Tue, 9 Jul 2024 09:54:05 +0100 Subject: [PATCH] feat: VOL-4507 Upgrade to Doctrine 2.19.5 (#189) * feat!: VOL-4507 Upgrade to Doctrine 2.19.5 * Update composer.json Co-authored-by: JoshuaLicense * fix: Rewritten some of the query which was breaking after the doctrine upgrade. Added some missing unit tests for the Repository worked on. --------- Co-authored-by: JoshuaLicense Co-authored-by: Andy Newton --- composer.json | 2 +- composer.lock | 195 ++++++++++-------- .../src/Domain/Repository/Conversation.php | 56 ++--- .../Domain/Repository/ConversationTest.php | 88 ++++++++ 4 files changed, 223 insertions(+), 118 deletions(-) create mode 100644 test/module/Api/src/Domain/Repository/ConversationTest.php diff --git a/composer.json b/composer.json index 5d599e841d..29b40090f2 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "beberlei/doctrineextensions": "^1.0", "caseyamcl/guzzle_retry_middleware": "^2.7.1", "doctrine/doctrine-orm-module": "^5", - "doctrine/orm": "~2.11.0", + "doctrine/orm": "^2.19.5", "doctrine/persistence": "^2.1", "dvsa/authentication-cognito": "^2.0", "dvsa/laminas-config-cloud-parameters": "^0.1.0", diff --git a/composer.lock b/composer.lock index d12cbb9225..283e1d3d5a 100644 --- a/composer.lock +++ b/composer.lock @@ -157,27 +157,32 @@ }, { "name": "beberlei/doctrineextensions", - "version": "v1.3.0", + "version": "v1.5.0", "source": { "type": "git", "url": "https://github.com/beberlei/DoctrineExtensions.git", - "reference": "008f162f191584a6c37c03a803f718802ba9dd9a" + "reference": "281f1650641c2f438b0a54d8eaa7ba50ac7e3eb6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/beberlei/DoctrineExtensions/zipball/008f162f191584a6c37c03a803f718802ba9dd9a", - "reference": "008f162f191584a6c37c03a803f718802ba9dd9a", + "url": "https://api.github.com/repos/beberlei/DoctrineExtensions/zipball/281f1650641c2f438b0a54d8eaa7ba50ac7e3eb6", + "reference": "281f1650641c2f438b0a54d8eaa7ba50ac7e3eb6", "shasum": "" }, "require": { - "doctrine/orm": "^2.7", + "doctrine/orm": "^2.19 || ^3.0", "php": "^7.2 || ^8.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.14", - "nesbot/carbon": "*", - "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", - "symfony/yaml": "^4.2 || ^5.0", + "doctrine/annotations": "^1.14 || ^2", + "doctrine/coding-standard": "^9.0.2 || ^12.0", + "nesbot/carbon": "^2.72 || ^3", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^8.5 || ^9.6", + "squizlabs/php_codesniffer": "^3.8", + "symfony/cache": "^5.4 || ^6.4 || ^7.0", + "symfony/yaml": "^5.4 || ^6.4 || ^7.0", + "vimeo/psalm": "^3.18 || ^5.22", "zf1/zend-date": "^1.12", "zf1/zend-registry": "^1.12" }, @@ -208,9 +213,9 @@ "orm" ], "support": { - "source": "https://github.com/beberlei/DoctrineExtensions/tree/v1.3.0" + "source": "https://github.com/beberlei/DoctrineExtensions/tree/v1.5.0" }, - "time": "2020-11-29T07:37:23+00:00" + "time": "2024-03-03T17:55:15+00:00" }, { "name": "behat/transliterator", @@ -720,16 +725,16 @@ }, { "name": "doctrine/dbal", - "version": "3.8.4", + "version": "3.8.5", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "b05e48a745f722801f55408d0dbd8003b403dbbd" + "reference": "0e3536ba088a749985c8801105b6b3ac6c1280b6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/b05e48a745f722801f55408d0dbd8003b403dbbd", - "reference": "b05e48a745f722801f55408d0dbd8003b403dbbd", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/0e3536ba088a749985c8801105b6b3ac6c1280b6", + "reference": "0e3536ba088a749985c8801105b6b3ac6c1280b6", "shasum": "" }, "require": { @@ -745,12 +750,12 @@ "doctrine/coding-standard": "12.0.0", "fig/log-test": "^1", "jetbrains/phpstorm-stubs": "2023.1", - "phpstan/phpstan": "1.10.58", - "phpstan/phpstan-strict-rules": "^1.5", - "phpunit/phpunit": "9.6.16", + "phpstan/phpstan": "1.11.1", + "phpstan/phpstan-strict-rules": "^1.6", + "phpunit/phpunit": "9.6.19", "psalm/plugin-phpunit": "0.18.4", "slevomat/coding-standard": "8.13.1", - "squizlabs/php_codesniffer": "3.9.0", + "squizlabs/php_codesniffer": "3.9.2", "symfony/cache": "^5.4|^6.0|^7.0", "symfony/console": "^4.4|^5.4|^6.0|^7.0", "vimeo/psalm": "4.30.0" @@ -813,7 +818,7 @@ ], "support": { "issues": "https://github.com/doctrine/dbal/issues", - "source": "https://github.com/doctrine/dbal/tree/3.8.4" + "source": "https://github.com/doctrine/dbal/tree/3.8.5" }, "funding": [ { @@ -829,29 +834,33 @@ "type": "tidelift" } ], - "time": "2024-04-25T07:04:44+00:00" + "time": "2024-06-08T17:49:56+00:00" }, { "name": "doctrine/deprecations", - "version": "v0.5.3", + "version": "1.1.3", "source": { "type": "git", "url": "https://github.com/doctrine/deprecations.git", - "reference": "9504165960a1f83cc1480e2be1dd0a0478561314" + "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/deprecations/zipball/9504165960a1f83cc1480e2be1dd0a0478561314", - "reference": "9504165960a1f83cc1480e2be1dd0a0478561314", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", + "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", "shasum": "" }, "require": { - "php": "^7.1|^8.0" + "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^6.0|^7.0|^8.0", - "phpunit/phpunit": "^7.0|^8.0|^9.0", - "psr/log": "^1.0" + "doctrine/coding-standard": "^9", + "phpstan/phpstan": "1.4.10 || 1.10.15", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "psalm/plugin-phpunit": "0.18.4", + "psr/log": "^1 || ^2 || ^3", + "vimeo/psalm": "4.30.0 || 5.12.0" }, "suggest": { "psr/log": "Allows logging deprecations via PSR-3 logger implementation" @@ -870,9 +879,9 @@ "homepage": "https://www.doctrine-project.org/", "support": { "issues": "https://github.com/doctrine/deprecations/issues", - "source": "https://github.com/doctrine/deprecations/tree/v0.5.3" + "source": "https://github.com/doctrine/deprecations/tree/1.1.3" }, - "time": "2021-03-21T12:59:47+00:00" + "time": "2024-01-30T19:34:25+00:00" }, { "name": "doctrine/doctrine-laminas-hydrator", @@ -1384,30 +1393,30 @@ }, { "name": "doctrine/instantiator", - "version": "1.5.0", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b" + "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/0a0fa9780f5d4e507415a065172d26a98d02047b", - "reference": "0a0fa9780f5d4e507415a065172d26a98d02047b", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", + "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0" + "php": "^8.1" }, "require-dev": { - "doctrine/coding-standard": "^9 || ^11", + "doctrine/coding-standard": "^11", "ext-pdo": "*", "ext-phar": "*", - "phpbench/phpbench": "^0.16 || ^1", - "phpstan/phpstan": "^1.4", - "phpstan/phpstan-phpunit": "^1", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.30 || ^5.4" + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^1.9.4", + "phpstan/phpstan-phpunit": "^1.3", + "phpunit/phpunit": "^9.5.27", + "vimeo/psalm": "^5.4" }, "type": "library", "autoload": { @@ -1434,7 +1443,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.5.0" + "source": "https://github.com/doctrine/instantiator/tree/2.0.0" }, "funding": [ { @@ -1450,35 +1459,37 @@ "type": "tidelift" } ], - "time": "2022-12-30T00:15:36+00:00" + "time": "2022-12-30T00:23:10+00:00" }, { "name": "doctrine/lexer", - "version": "1.2.3", + "version": "2.1.1", "source": { "type": "git", "url": "https://github.com/doctrine/lexer.git", - "reference": "c268e882d4dbdd85e36e4ad69e02dc284f89d229" + "reference": "861c870e8b75f7c8f69c146c7f89cc1c0f1b49b6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/lexer/zipball/c268e882d4dbdd85e36e4ad69e02dc284f89d229", - "reference": "c268e882d4dbdd85e36e4ad69e02dc284f89d229", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/861c870e8b75f7c8f69c146c7f89cc1c0f1b49b6", + "reference": "861c870e8b75f7c8f69c146c7f89cc1c0f1b49b6", "shasum": "" }, "require": { + "doctrine/deprecations": "^1.0", "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^9.0", + "doctrine/coding-standard": "^9 || ^12", "phpstan/phpstan": "^1.3", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.11" + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.6", + "psalm/plugin-phpunit": "^0.18.3", + "vimeo/psalm": "^4.11 || ^5.21" }, "type": "library", "autoload": { "psr-4": { - "Doctrine\\Common\\Lexer\\": "lib/Doctrine/Common/Lexer" + "Doctrine\\Common\\Lexer\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -1510,7 +1521,7 @@ ], "support": { "issues": "https://github.com/doctrine/lexer/issues", - "source": "https://github.com/doctrine/lexer/tree/1.2.3" + "source": "https://github.com/doctrine/lexer/tree/2.1.1" }, "funding": [ { @@ -1526,56 +1537,59 @@ "type": "tidelift" } ], - "time": "2022-02-28T11:07:21+00:00" + "time": "2024-02-05T11:35:39+00:00" }, { "name": "doctrine/orm", - "version": "2.11.3", + "version": "2.19.5", "source": { "type": "git", "url": "https://github.com/doctrine/orm.git", - "reference": "4af1aa317713d5f3dbc57b22237d1acb8477079c" + "reference": "94986af28452da42a46a4489d1c958a2e5d710e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/orm/zipball/4af1aa317713d5f3dbc57b22237d1acb8477079c", - "reference": "4af1aa317713d5f3dbc57b22237d1acb8477079c", + "url": "https://api.github.com/repos/doctrine/orm/zipball/94986af28452da42a46a4489d1c958a2e5d710e5", + "reference": "94986af28452da42a46a4489d1c958a2e5d710e5", "shasum": "" }, "require": { "composer-runtime-api": "^2", "doctrine/cache": "^1.12.1 || ^2.1.1", - "doctrine/collections": "^1.5", + "doctrine/collections": "^1.5 || ^2.1", "doctrine/common": "^3.0.3", "doctrine/dbal": "^2.13.1 || ^3.2", - "doctrine/deprecations": "^0.5.3", - "doctrine/event-manager": "^1.1", + "doctrine/deprecations": "^0.5.3 || ^1", + "doctrine/event-manager": "^1.2 || ^2", "doctrine/inflector": "^1.4 || ^2.0", - "doctrine/instantiator": "^1.3", - "doctrine/lexer": "^1.0", - "doctrine/persistence": "^2.2", + "doctrine/instantiator": "^1.3 || ^2", + "doctrine/lexer": "^2 || ^3", + "doctrine/persistence": "^2.4 || ^3", "ext-ctype": "*", "php": "^7.1 || ^8.0", "psr/cache": "^1 || ^2 || ^3", - "symfony/console": "^3.0 || ^4.0 || ^5.0 || ^6.0", + "symfony/console": "^4.2 || ^5.0 || ^6.0 || ^7.0", "symfony/polyfill-php72": "^1.23", - "symfony/polyfill-php80": "^1.15" + "symfony/polyfill-php80": "^1.16" }, "conflict": { - "doctrine/annotations": "<1.13 || >= 2.0" + "doctrine/annotations": "<1.13 || >= 3.0" }, "require-dev": { - "doctrine/annotations": "^1.13", - "doctrine/coding-standard": "^9.0", + "doctrine/annotations": "^1.13 || ^2", + "doctrine/coding-standard": "^9.0.2 || ^12.0", "phpbench/phpbench": "^0.16.10 || ^1.0", - "phpstan/phpstan": "~1.4.10 || 1.5.0", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.4", - "squizlabs/php_codesniffer": "3.6.2", - "symfony/cache": "^4.4 || ^5.4 || ^6.0", - "symfony/yaml": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "vimeo/psalm": "4.22.0" + "phpstan/phpstan": "~1.4.10 || 1.10.59", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.6", + "psr/log": "^1 || ^2 || ^3", + "squizlabs/php_codesniffer": "3.7.2", + "symfony/cache": "^4.4 || ^5.4 || ^6.4 || ^7.0", + "symfony/var-exporter": "^4.4 || ^5.4 || ^6.2 || ^7.0", + "symfony/yaml": "^3.4 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "vimeo/psalm": "4.30.0 || 5.22.2" }, "suggest": { + "ext-dom": "Provides support for XSD validation for XML mapping files", "symfony/cache": "Provides cache support for Setup Tool with doctrine/cache 2.0", "symfony/yaml": "If you want to use YAML Metadata Mapping Driver" }, @@ -1585,7 +1599,7 @@ "type": "library", "autoload": { "psr-4": { - "Doctrine\\ORM\\": "lib/Doctrine/ORM" + "Doctrine\\ORM\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -1622,9 +1636,9 @@ ], "support": { "issues": "https://github.com/doctrine/orm/issues", - "source": "https://github.com/doctrine/orm/tree/2.11.3" + "source": "https://github.com/doctrine/orm/tree/2.19.5" }, - "time": "2022-04-19T09:01:33+00:00" + "time": "2024-04-30T06:49:54+00:00" }, { "name": "doctrine/persistence", @@ -8044,16 +8058,16 @@ }, { "name": "symfony/console", - "version": "v6.4.7", + "version": "v6.4.8", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "a170e64ae10d00ba89e2acbb590dc2e54da8ad8f" + "reference": "be5854cee0e8c7b110f00d695d11debdfa1a2a91" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/a170e64ae10d00ba89e2acbb590dc2e54da8ad8f", - "reference": "a170e64ae10d00ba89e2acbb590dc2e54da8ad8f", + "url": "https://api.github.com/repos/symfony/console/zipball/be5854cee0e8c7b110f00d695d11debdfa1a2a91", + "reference": "be5854cee0e8c7b110f00d695d11debdfa1a2a91", "shasum": "" }, "require": { @@ -8118,7 +8132,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v6.4.7" + "source": "https://github.com/symfony/console/tree/v6.4.8" }, "funding": [ { @@ -8134,7 +8148,7 @@ "type": "tidelift" } ], - "time": "2024-04-18T09:22:46+00:00" + "time": "2024-05-31T14:49:08+00:00" }, { "name": "symfony/dependency-injection", @@ -9508,16 +9522,16 @@ }, { "name": "symfony/string", - "version": "v7.0.7", + "version": "v7.1.1", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "e405b5424dc2528e02e31ba26b83a79fd4eb8f63" + "reference": "60bc311c74e0af215101235aa6f471bcbc032df2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/e405b5424dc2528e02e31ba26b83a79fd4eb8f63", - "reference": "e405b5424dc2528e02e31ba26b83a79fd4eb8f63", + "url": "https://api.github.com/repos/symfony/string/zipball/60bc311c74e0af215101235aa6f471bcbc032df2", + "reference": "60bc311c74e0af215101235aa6f471bcbc032df2", "shasum": "" }, "require": { @@ -9531,6 +9545,7 @@ "symfony/translation-contracts": "<2.5" }, "require-dev": { + "symfony/emoji": "^7.1", "symfony/error-handler": "^6.4|^7.0", "symfony/http-client": "^6.4|^7.0", "symfony/intl": "^6.4|^7.0", @@ -9574,7 +9589,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.0.7" + "source": "https://github.com/symfony/string/tree/v7.1.1" }, "funding": [ { @@ -9590,7 +9605,7 @@ "type": "tidelift" } ], - "time": "2024-04-18T09:29:19+00:00" + "time": "2024-06-04T06:40:14+00:00" }, { "name": "symfony/var-exporter", diff --git a/module/Api/src/Domain/Repository/Conversation.php b/module/Api/src/Domain/Repository/Conversation.php index ecf4f17a9d..67b32114ef 100644 --- a/module/Api/src/Domain/Repository/Conversation.php +++ b/module/Api/src/Domain/Repository/Conversation.php @@ -2,6 +2,7 @@ namespace Dvsa\Olcs\Api\Domain\Repository; +use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\QueryBuilder; use Dvsa\Olcs\Api\Entity\Messaging\MessagingConversation as Entity; use Dvsa\Olcs\Api\Entity\Messaging\MessagingMessage; @@ -56,35 +57,36 @@ public function applyOrderForListing(QueryBuilder $qb, array $roleNames): QueryB { $subQuery = $this->getEntityManager()->createQueryBuilder(); $subQuery->select('1') - ->from(MessagingUserMessageRead::class, 'inner_read') - ->leftJoin('inner_read.user', 'inner_user') - ->leftJoin('inner_user.roles', 'inner_role') - ->where('inner_read.messagingMessage = irmm.id') - ->andWhere($qb->expr()->in('inner_role.role', ':roleNames')); - - $unreadQueryBuilder = $this->getEntityManager()->createQueryBuilder(); - $unreadQueryBuilder->select('1') - ->from(MessagingMessage::class, 'irmm') + ->from(MessagingUserMessageRead::class, 'inner_read') + ->join('inner_read.user', 'inner_user') + ->join('inner_user.roles', 'inner_role') + ->where('inner_read.messagingMessage = irmm.id') + ->andWhere($qb->expr()->in('inner_role.role', ':roleNames')); + + $qb->leftJoin(MessagingMessage::class, 'irmm', Join::WITH, 'irmm.messagingConversation = ' . $this->alias . '.id') ->leftJoin('irmm.messagingConversation', 'inner_conversation') ->leftJoin('inner_conversation.task', 'inner_task') - ->groupBy('irmm.messagingConversation') - ->where('inner_conversation.isClosed = 0') - ->andWhere($unreadQueryBuilder->expr()->not($unreadQueryBuilder->expr()->exists($subQuery))) - ->andWhere($unreadQueryBuilder->expr()->eq($this->alias . '.id', 'irmm.messagingConversation')); - - $lastReadQuery = $this->getEntityManager()->createQueryBuilder(); - $lastReadQuery->select('MAX(lrmm.createdOn)') - ->from(MessagingMessage::class, 'lrmm') - ->where($lastReadQuery->expr()->eq('lrmm.messagingConversation', $this->alias . '.id')) - ->groupBy('lrmm.messagingConversation'); - - $qb->addSelect('(' . $lastReadQuery->getDQL() . ') AS last_read'); - $qb->addSelect('(' . $unreadQueryBuilder->getDQL() . ') AS has_unread'); - $qb->addOrderBy($this->alias . '.isClosed', 'ASC'); - $qb->addOrderBy('has_unread', 'DESC'); - $qb->addOrderBy('last_read', 'DESC'); - - $qb->setParameter('roleNames', $roleNames); + ->addSelect('MAX(irmm.createdOn) AS last_read') + ->addSelect('CASE WHEN ' . $this->alias . '.isClosed = 0 AND NOT EXISTS (' . $subQuery->getDQL() . ') THEN 1 ELSE 0 END AS has_unread') + ->groupBy($this->alias . '.id') + ->addOrderBy($this->alias . '.isClosed', 'ASC') + ->addOrderBy('has_unread', 'DESC') + ->addOrderBy('last_read', 'DESC') + ->andWhere($qb->expr()->orX( + $qb->expr()->eq($this->alias . '.isClosed', ':closed'), + $qb->expr()->exists( + $this->getEntityManager()->createQueryBuilder() + ->select('1') + ->from(MessagingUserMessageRead::class, 'filter_read') + ->join('filter_read.user', 'filter_user') + ->join('filter_user.roles', 'filter_role') + ->where('filter_read.messagingMessage = irmm.id') + ->andWhere($qb->expr()->in('filter_role.role', ':roleNames')) + ->getDQL() + ) + )) + ->setParameter('roleNames', $roleNames) + ->setParameter('closed', false); return $qb; } diff --git a/test/module/Api/src/Domain/Repository/ConversationTest.php b/test/module/Api/src/Domain/Repository/ConversationTest.php new file mode 100644 index 0000000000..ae7c8a1a96 --- /dev/null +++ b/test/module/Api/src/Domain/Repository/ConversationTest.php @@ -0,0 +1,88 @@ +setUpSut(Conversation::class); + } + + public function testApplyOrderForListing() + { + $qb = m::mock(QueryBuilder::class); + $roleNames = ['role1', 'role2']; + + $subQuery = m::mock(QueryBuilder::class); + $this->em->shouldReceive('createQueryBuilder') + ->twice() + ->andReturn($subQuery); + + $subQuery->shouldReceive('select') + ->twice() + ->andReturnSelf() + ->shouldReceive('from') + ->twice() + ->andReturnSelf() + ->shouldReceive('join') + ->times(4) + ->andReturnSelf() + ->shouldReceive('where') + ->twice() + ->andReturnSelf() + ->shouldReceive('andWhere') + ->twice() + ->andReturnSelf() + ->shouldReceive('getDQL') + ->twice() + ->andReturn('SUBQUERY'); + + $qb->shouldReceive('leftJoin') + ->times(3) + ->andReturnSelf() + ->shouldReceive('addSelect') + ->twice() + ->andReturnSelf() + ->shouldReceive('groupBy') + ->once() + ->andReturnSelf() + ->shouldReceive('addOrderBy') + ->times(3) + ->andReturnSelf() + ->shouldReceive('andWhere') + ->once() + ->andReturnSelf() + ->shouldReceive('setParameter') + ->twice() + ->andReturnSelf() + ->shouldReceive('expr') + ->times(5) + ->andReturn(m::mock()->shouldReceive('in', 'eq', 'orX', 'exists')->getMock()); + + $result = $this->sut->applyOrderForListing($qb, $roleNames); + + $this->assertSame($qb, $result); + } + + public function testFilterByStatuses() + { + $qb = m::mock(QueryBuilder::class); + $statuses = ['open', 'closed']; + + $qb->shouldReceive('andWhere') + ->once() + ->andReturnSelf() + ->shouldReceive('expr') + ->once() + ->andReturn(m::mock()->shouldReceive('orX')->andReturnSelf()->shouldReceive('addMultiple')->getMock()); + + $result = $this->sut->filterByStatuses($qb, $statuses); + + $this->assertSame($qb, $result); + } +}