Skip to content

Commit

Permalink
Merge pull request #13 from paycoreio/feature/PC-5696-multiple-sorting
Browse files Browse the repository at this point in the history
PC-5696: add multiple sorting
  • Loading branch information
Pashkalab authored Aug 13, 2020
2 parents 605d529 + ca8dd11 commit 6d79cc1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 21 deletions.
11 changes: 1 addition & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,11 @@ cache:
- vendor

php:
- '7.1'
- '7.2'
- '7.3'

before_script:
- composer install -o --ignore-platform-reqs

after_script:
- |
if [ $TRAVIS_PHP_VERSION = '7.1' ]; then
travis_retry wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
fi
install:
- export PATH="$HOME/.composer/vendor/bin:$PATH"
- travis_retry composer self-update && composer --version
Expand All @@ -28,4 +19,4 @@ script:
# check the code style
- if [ $TRAVIS_PHP_VERSION = '7.2' ]; then IFS=$'\n'; COMMIT_SCA_FILES=($(git diff --name-only --diff-filter=ACMRTUXB "${TRAVIS_COMMIT_RANGE}")); unset IFS; fi
- if [ $TRAVIS_PHP_VERSION = '7.2' ]; then ./vendor/bin/php-cs-fixer fix --config=.php_cs.php -v --dry-run --stop-on-violation --using-cache=no --path-mode=intersection -- "${COMMIT_SCA_FILES[@]}";fi
- phpunit --configuration phpunit.xml
- vendor/bin/phpunit --configuration phpunit.xml
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"license": "MIT",
"type": "project",
"require": {
"php": "^7.1",
"php": "^7.3",
"doctrine/orm": "^2.5",
"neomerx/json-api": "^1.0|^2.0",
"nesbot/carbon": "^1.21",
"ramsey/uuid": "^3.5",
"sylius/registry": "^0.19.0|^1.0"
},
"require-dev": {
"phpunit/phpunit": "^6",
"phpunit/phpunit": "^9",
"friendsofphp/php-cs-fixer": "^2.8",
"phpstan/phpstan": "^0.9"
},
Expand Down
5 changes: 4 additions & 1 deletion src/Paymaxi/Component/Query/Handler/CriteriaHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ final class CriteriaHandler extends AbstractHandler
/** @var Criteria */
private $criteria;

private $sortParams = [];

/**
* CriteriaHandler constructor.
*
Expand All @@ -45,7 +47,8 @@ public function supports($object): bool
*/
protected function handleSorting(SortInterface $sort, string $order):void
{
$sort->applyCriteria($this->criteria, $order);
$this->sortParams = \array_merge($this->sortParams, [$sort->getFieldName() => $order]);
$sort->applyCriteria($this->criteria, $this->sortParams);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Paymaxi/Component/Query/Sort/CriteriaSortInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface CriteriaSortInterface extends SortInterface
{
/**
* @param Criteria $criteria
* @param string $orderField
* @param array $sortParams
*/
public function applyCriteria(Criteria $criteria, string $orderField): void;
public function applyCriteria(Criteria $criteria, array $sortParams): void;
}
6 changes: 3 additions & 3 deletions src/Paymaxi/Component/Query/Sort/StaticSorting.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ final class StaticSorting extends AbstractSorting implements CriteriaSortInterfa
{
/**
* @param Criteria $criteria
* @param string $orderField
* @param array $sortParams
*
* @return void
*/
public function applyCriteria(Criteria $criteria, string $orderField): void
public function applyCriteria(Criteria $criteria, array $sortParams): void
{
$criteria->orderBy([$this->getFieldName() => $orderField]);
$criteria->orderBy($sortParams);
}
}
6 changes: 3 additions & 3 deletions tests/CriteriaQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CriteriaQueryBuilderTest extends TestCase
/** @var EntityManager */
private $em;

public function setUp()
public function setUp(): void
{
$connectionParams = ['url' => 'sqlite://:memory:'];
$config = Setup::createXMLMetadataConfiguration(array(__DIR__ . "/mapping"), true);
Expand All @@ -38,7 +38,7 @@ public function setUp()
$this->schemaTool->createSchema($this->em->getMetadataFactory()->getAllMetadata());
}

public function tearDown()
public function tearDown(): void
{
$this->schemaTool->dropDatabase();
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public function it_returns_criteria()
public function this_throw_exception_on_missing_default_order_field()
{
$this->expectException(QueryException::class);
$this->expectExceptionMessageRegExp('@has no field or association named created$@');
$this->expectExceptionMessageMatches('@has no field or association named created$@');
$qb = $this->getAuthorQb();
$qb->setDefaultOrder([]);

Expand Down

0 comments on commit 6d79cc1

Please sign in to comment.