diff --git a/.github/workflows/continous-integration.yml b/.github/workflows/continous-integration.yml
new file mode 100644
index 000000000..2a007343b
--- /dev/null
+++ b/.github/workflows/continous-integration.yml
@@ -0,0 +1,47 @@
+name: 'Continuous integration'
+on: ['push', 'pull_request']
+jobs:
+ phpunit:
+ runs-on: 'ubuntu-20.04'
+ name: 'PHPUnit (PHP ${{ matrix.php }}, ES ${{ matrix.elasticsearch }})'
+ timeout-minutes: 10
+ env:
+ SYMFONY_REQUIRE: "${{ matrix.symfony_require }}"
+ strategy:
+ matrix:
+ include:
+ - php: '8.1'
+ elasticsearch: '6.8.23'
+ dependencies: 'highest'
+ symfony_require: '4.4.*'
+ fail-fast: false
+ steps:
+ - name: 'Checkout'
+ uses: 'actions/checkout@v2'
+
+ - name: 'Setup PHP'
+ uses: 'shivammathur/setup-php@v2'
+ with:
+ php-version: '${{ matrix.php }}'
+ coverage: 'none'
+ tools: 'pecl, composer:v2, flex'
+ extensions: 'curl, json, mbstring, mongodb, openssl'
+
+ - name: "Install Composer dependencies (${{ matrix.dependencies }})"
+ uses: "ramsey/composer-install@v1"
+ with:
+ dependency-versions: "${{ matrix.dependencies }}"
+ composer-options: "--prefer-dist --prefer-stable"
+
+ - name: 'Setup Elasticsearch'
+ run: |
+ sudo swapoff -a
+ sudo sysctl -w vm.swappiness=1
+ sudo sysctl -w fs.file-max=262144
+ sudo sysctl -w vm.max_map_count=262144
+ docker network create elastic
+ docker run -d --name=elasticsearch --network=elastic -p 9200:9200 -e discovery.type=single-node -e node.name=es docker.elastic.co/elasticsearch/elasticsearch:${{ matrix.elasticsearch }} sh -c "./bin/elasticsearch-plugin install --batch ingest-attachment && /usr/local/bin/docker-entrypoint.sh"
+ docker run --rm --network=elastic curlimages/curl --max-time 120 --retry-max-time 120 --retry 120 --retry-delay 5 --retry-all-errors --show-error --silent http://elasticsearch:9200
+ - name: 'Run unit tests'
+ run: |
+ vendor/bin/phpunit
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 4c30289c9..000000000
--- a/.travis.yml
+++ /dev/null
@@ -1,60 +0,0 @@
-language: php
-
-sudo: false
-
-cache:
- directories:
- - $HOME/.composer/cache
-
-env:
- global:
- - PHPUNIT_FLAGS="-v"
- - ES_VERSION="5.2.1"
-
-matrix:
- fast_finish: true
- include:
- # Minimum supported dependencies with min and max PHP version
- - php: 7.1
- env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
-
- # Latest supported dependencies with each PHP version
- - php: 7.1
- - php: 7.2
- - php: 7.3
- env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-clover=coverage.clover"
-
- # Install all SF components in the same major version, see https://github.com/dunglas/symfony-lock
- - php: 7.4
- env: DEPENDENCIES="symfony/flex" SYMFONY_VERSION="^3.4"
- - php: 7.4
- env: DEPENDENCIES="symfony/flex" SYMFONY_VERSION="^4.4"
- - php: 7.4
- env: DEPENDENCIES="symfony/flex" SYMFONY_VERSION="^5.0"
-
-before_install:
- - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
-
-install:
- # To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
- - if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
- - if [ "$DEPENDENCIES" != "" ]; then composer require --no-update ${DEPENDENCIES}; fi;
- - if [ "$SYMFONY_VERSION" != "" ]; then composer config extra.symfony.require ${SYMFONY_VERSION}; fi;
- - composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
- - mkdir /tmp/elasticsearch
- - wget -O - https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz | tar xz --directory=/tmp/elasticsearch --strip-components=1
- - /tmp/elasticsearch/bin/elasticsearch-plugin install -b mapper-attachments
- - /tmp/elasticsearch/bin/elasticsearch --daemonize -Epath.data=/tmp
- - .travis/wait-for-elasticsearch.sh
-
-before_script:
- - phpenv config-add .travis/php.ini
- - echo "extension = mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
-
-script:
- - vendor/bin/phpunit ${PHPUNIT_FLAGS}
-
-after_script:
- - if [[ $COVERAGE = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- - if [[ $COVERAGE = true ]]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
-
diff --git a/.travis/php.ini b/.travis/php.ini
deleted file mode 100644
index 2a30f4186..000000000
--- a/.travis/php.ini
+++ /dev/null
@@ -1 +0,0 @@
-memory_limit = 2G
diff --git a/.travis/wait-for-elasticsearch.sh b/.travis/wait-for-elasticsearch.sh
deleted file mode 100755
index f42f3bab3..000000000
--- a/.travis/wait-for-elasticsearch.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/usr/bin/env bash
-
-# the script was taken form https://github.com/php-enqueue/enqueue-dev/blob/4cdaf222e8613ba7b16c1b5d4820afd4ccb73a5a/bin/test#L1
-# wait for service
-# $1 host
-# $2 port
-# $3 attempts
-
-FORCE_EXIT=false
-
-function waitForService()
-{
- ATTEMPTS=0
- until nc -z $1 $2; do
- printf "wait for service %s:%s\n" $1 $2
- ((ATTEMPTS++))
- if [ $ATTEMPTS -ge $3 ]; then
- printf "service is not running %s:%s\n" $1 $2
- exit 1
- fi
- if [ "$FORCE_EXIT" = true ]; then
- exit;
- fi
-
- sleep 1
- done
-
- printf "service is online %s:%s\n" $1 $2
-}
-
-trap "FORCE_EXIT=true" SIGTERM SIGINT
-
-waitForService localhost 9200 30
diff --git a/composer.json b/composer.json
index 9da271455..48a098c65 100644
--- a/composer.json
+++ b/composer.json
@@ -12,31 +12,36 @@
{ "name": "Jeremy Mikola", "email": "jmikola@gmail.com" }
],
"require": {
- "php": "^7.1",
- "symfony/framework-bundle": "^3.4|^4.3|^5",
- "symfony/console": "^3.4|^4.3|^5",
- "symfony/dependency-injection": "^3.4|^4.3|^5",
- "symfony/property-access": "^3.4|^4.3|^5",
- "pagerfanta/pagerfanta": "^1.0.5|^2.0",
+ "php": "^8.0",
+ "symfony/framework-bundle": "^4.4",
+ "symfony/console": "^4.4",
+ "symfony/dependency-injection": "^4.4",
+ "symfony/property-access": "^4.4",
+ "pagerfanta/pagerfanta": "^3.6",
"psr/log": "^1.0",
- "ruflin/elastica": "^5.3.5|^6.1.1"
+ "ruflin/elastica": "^6.2"
},
"require-dev": {
- "doctrine/orm": "^2.5",
- "doctrine/doctrine-bundle": "^1.6|^2",
- "doctrine/persistence": "^1.3.4",
+ "doctrine/orm": "^2.8",
+ "doctrine/doctrine-bundle": "^2.1.1",
+ "doctrine/persistence": "^2.0",
"doctrine/phpcr-bundle": "^1.3|^2.0",
"doctrine/phpcr-odm": "^1.4",
"jackalope/jackalope-doctrine-dbal": "^1.2",
- "jms/serializer-bundle": "^2.4|^3.5",
- "phpunit/phpunit": "^6.5.14",
+ "jms/serializer-bundle": "^3.5",
+ "phpunit/phpunit": "^9.5",
"knplabs/knp-components": "^1.2|^2.3",
"symfony/expression-language" : "^3.4|^4.3|^5",
- "symfony/twig-bundle": "^3.4|^4.3|^5",
- "symfony/serializer": "^3.4|^4.3|^5",
- "symfony/yaml": "^3.4|^4.3|^5",
+ "symfony/twig-bundle": "^4.4",
+ "symfony/serializer": "^4.4",
+ "symfony/yaml": "^4.4",
"friendsofphp/php-cs-fixer": "^2.2",
- "symfony/web-profiler-bundle": "^3.4|^4.3|^5"
+ "symfony/web-profiler-bundle": "^4.4",
+ "doctrine/mongodb-odm-bundle": "^4.5",
+ "phpspec/prophecy-phpunit": "^2.0",
+ "pagerfanta/doctrine-mongodb-odm-adapter": "^3.6",
+ "pagerfanta/doctrine-orm-adapter": "^3.6",
+ "pagerfanta/doctrine-phpcr-odm-adapter": "^3.6"
},
"suggest": {
"enqueue/elastica-bundle": "The bundle adds extra features to FOSElasticaBundle bundle. Aimed to improve performance."
diff --git a/src/Doctrine/AbstractElasticaToModelTransformer.php b/src/Doctrine/AbstractElasticaToModelTransformer.php
index 167e70a10..f1e63085d 100644
--- a/src/Doctrine/AbstractElasticaToModelTransformer.php
+++ b/src/Doctrine/AbstractElasticaToModelTransformer.php
@@ -118,13 +118,14 @@ public function transform(array $elasticaObjects)
$objects,
function ($a, $b) use ($idPos, $identifier, $propertyAccessor) {
if ($this->options['hydrate']) {
- return $idPos[(string) $propertyAccessor->getValue(
- $a,
- $identifier
- )] > $idPos[(string) $propertyAccessor->getValue($b, $identifier)];
+ return (
+ $idPos[(string) $propertyAccessor->getValue($a, $identifier)]
+ >
+ $idPos[(string) $propertyAccessor->getValue($b, $identifier)]
+ ) ? 1 : -1;
}
- return $idPos[$a[$identifier]] > $idPos[$b[$identifier]];
+ return ($idPos[$a[$identifier]] > $idPos[$b[$identifier]]) ? 1 : -1;
}
);
diff --git a/src/Doctrine/MongoDBPagerProvider.php b/src/Doctrine/MongoDBPagerProvider.php
index 22284fe06..735ba86fb 100644
--- a/src/Doctrine/MongoDBPagerProvider.php
+++ b/src/Doctrine/MongoDBPagerProvider.php
@@ -3,7 +3,7 @@
/*
* This file is part of the FOSElasticaBundle package.
*
- * (c) FriendsOfSymfony
+ * (c) FriendsOfSymfony
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -13,8 +13,9 @@
use Doctrine\Persistence\ManagerRegistry;
use FOS\ElasticaBundle\Provider\PagerfantaPager;
+use FOS\ElasticaBundle\Provider\PagerInterface;
use FOS\ElasticaBundle\Provider\PagerProviderInterface;
-use Pagerfanta\Adapter\DoctrineODMMongoDBAdapter;
+use Pagerfanta\Doctrine\MongoDBODM\QueryAdapter;
use Pagerfanta\Pagerfanta;
final class MongoDBPagerProvider implements PagerProviderInterface
@@ -40,10 +41,7 @@ final class MongoDBPagerProvider implements PagerProviderInterface
private $registerListenersService;
/**
- * @param ManagerRegistry $doctrine
- * @param RegisterListenersService $registerListenersService
* @param string $objectClass
- * @param array $baseOptions
*/
public function __construct(ManagerRegistry $doctrine, RegisterListenersService $registerListenersService, $objectClass, array $baseOptions)
{
@@ -56,15 +54,15 @@ public function __construct(ManagerRegistry $doctrine, RegisterListenersService
/**
* {@inheritdoc}
*/
- public function provide(array $options = array())
+ public function provide(array $options = []): PagerInterface
{
- $options = array_replace($this->baseOptions, $options);
+ $options = \array_replace($this->baseOptions, $options);
$manager = $this->doctrine->getManagerForClass($this->objectClass);
$repository = $manager->getRepository($this->objectClass);
$pager = new PagerfantaPager(new Pagerfanta(
- new DoctrineODMMongoDBAdapter(call_user_func([$repository, $options['query_builder_method']]))
+ new QueryAdapter(\call_user_func([$repository, $options['query_builder_method']]))
));
$this->registerListenersService->register($manager, $pager, $options);
diff --git a/src/Doctrine/ORMPagerProvider.php b/src/Doctrine/ORMPagerProvider.php
index 3c43a648b..21771fc28 100644
--- a/src/Doctrine/ORMPagerProvider.php
+++ b/src/Doctrine/ORMPagerProvider.php
@@ -3,7 +3,7 @@
/*
* This file is part of the FOSElasticaBundle package.
*
- * (c) FriendsOfSymfony
+ * (c) FriendsOfSymfony
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -15,13 +15,14 @@
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ManagerRegistry;
use FOS\ElasticaBundle\Provider\PagerfantaPager;
+use FOS\ElasticaBundle\Provider\PagerInterface;
use FOS\ElasticaBundle\Provider\PagerProviderInterface;
-use Pagerfanta\Adapter\DoctrineORMAdapter;
+use Pagerfanta\Doctrine\ORM\QueryAdapter;
use Pagerfanta\Pagerfanta;
final class ORMPagerProvider implements PagerProviderInterface
{
- const ENTITY_ALIAS = 'a';
+ public const ENTITY_ALIAS = 'a';
/**
* @var string
@@ -44,10 +45,7 @@ final class ORMPagerProvider implements PagerProviderInterface
private $registerListenersService;
/**
- * @param ManagerRegistry $doctrine
- * @param RegisterListenersService $registerListenersService
* @param string $objectClass
- * @param array $baseOptions
*/
public function __construct(ManagerRegistry $doctrine, RegisterListenersService $registerListenersService, $objectClass, array $baseOptions)
{
@@ -60,9 +58,9 @@ public function __construct(ManagerRegistry $doctrine, RegisterListenersService
/**
* {@inheritdoc}
*/
- public function provide(array $options = array())
+ public function provide(array $options = []): PagerInterface
{
- $options = array_replace($this->baseOptions, $options);
+ $options = \array_replace($this->baseOptions, $options);
$manager = $this->doctrine->getManagerForClass($this->objectClass);
$repository = $manager->getRepository($this->objectClass);
@@ -92,7 +90,7 @@ public function provide(array $options = array())
}
}
- $pager = new PagerfantaPager(new Pagerfanta(new DoctrineORMAdapter($qb)));
+ $pager = new PagerfantaPager(new Pagerfanta(new QueryAdapter($qb)));
$this->registerListenersService->register($manager, $pager, $options);
diff --git a/src/Doctrine/PHPCRPagerProvider.php b/src/Doctrine/PHPCRPagerProvider.php
index a80d824bc..7d8ff6a47 100644
--- a/src/Doctrine/PHPCRPagerProvider.php
+++ b/src/Doctrine/PHPCRPagerProvider.php
@@ -3,7 +3,7 @@
/*
* This file is part of the FOSElasticaBundle package.
*
- * (c) FriendsOfSymfony
+ * (c) FriendsOfSymfony
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -11,15 +11,17 @@
namespace FOS\ElasticaBundle\Doctrine;
+use Doctrine\ODM\PHPCR\Translation\LocaleChooser\LocaleChooser;
use Doctrine\Persistence\ManagerRegistry;
use FOS\ElasticaBundle\Provider\PagerfantaPager;
+use FOS\ElasticaBundle\Provider\PagerInterface;
use FOS\ElasticaBundle\Provider\PagerProviderInterface;
-use Pagerfanta\Adapter\DoctrineODMPhpcrAdapter;
+use Pagerfanta\Doctrine\PHPCRODM\QueryAdapter;
use Pagerfanta\Pagerfanta;
final class PHPCRPagerProvider implements PagerProviderInterface
{
- const ENTITY_ALIAS = 'a';
+ public const ENTITY_ALIAS = 'a';
/**
* @var string
@@ -42,10 +44,7 @@ final class PHPCRPagerProvider implements PagerProviderInterface
private $registerListenersService;
/**
- * @param ManagerRegistry $doctrine
- * @param RegisterListenersService $registerListenersService
* @param string $objectClass
- * @param array $baseOptions
*/
public function __construct(ManagerRegistry $doctrine, RegisterListenersService $registerListenersService, $objectClass, array $baseOptions)
{
@@ -58,15 +57,21 @@ public function __construct(ManagerRegistry $doctrine, RegisterListenersService
/**
* {@inheritdoc}
*/
- public function provide(array $options = array())
+ public function provide(array $options = []): PagerInterface
{
- $options = array_replace($this->baseOptions, $options);
+ $options = \array_replace($this->baseOptions, $options);
$manager = $this->doctrine->getManagerForClass($this->objectClass);
+ if (isset($options['locale'])) {
+ /** @var LocaleChooser $localeChooser */
+ $localeChooser = $manager->getLocaleChooserStrategy();
+ $localeChooser->setLocale($options['locale']);
+ $manager->setLocaleChooserStrategy($localeChooser);
+ }
$repository = $manager->getRepository($this->objectClass);
- $adapter = new DoctrineODMPhpcrAdapter(
- call_user_func([$repository, $options['query_builder_method']], static::ENTITY_ALIAS)
+ $adapter = new QueryAdapter(
+ \call_user_func([$repository, $options['query_builder_method']], static::ENTITY_ALIAS)
);
$pager = new PagerfantaPager(new Pagerfanta($adapter));
diff --git a/src/Index/MappingBuilder.php b/src/Index/MappingBuilder.php
index 359439e10..d5fe63867 100644
--- a/src/Index/MappingBuilder.php
+++ b/src/Index/MappingBuilder.php
@@ -104,7 +104,9 @@ public function buildTypeMapping(TypeConfig $typeConfig)
$mapping['_meta']['model'] = $typeConfig->getModel();
}
- unset($mapping['_parent']['identifier'], $mapping['_parent']['property']);
+ if (isset($mapping['_parent'])) {
+ unset($mapping['_parent']);
+ }
if (empty($mapping)) {
// Empty mapping, we want it encoded as a {} instead of a []
diff --git a/src/Paginator/FantaPaginatorAdapter.php b/src/Paginator/FantaPaginatorAdapter.php
index c9b1bee4e..d5c69889e 100644
--- a/src/Paginator/FantaPaginatorAdapter.php
+++ b/src/Paginator/FantaPaginatorAdapter.php
@@ -30,9 +30,9 @@ public function __construct(PaginatorAdapterInterface $adapter)
*
* @return int The number of results
*/
- public function getNbResults()
+ public function getNbResults(): int
{
- return $this->adapter->getTotalHits();
+ return (int) $this->adapter->getTotalHits();
}
/**
@@ -67,7 +67,7 @@ public function getSuggests()
*
* @return array|\Traversable The slice
*/
- public function getSlice($offset, $length)
+ public function getSlice($offset, $length): iterable
{
return $this->adapter->getResults($offset, $length)->toArray();
}
diff --git a/src/Subscriber/PaginateElasticaQuerySubscriber.php b/src/Subscriber/PaginateElasticaQuerySubscriber.php
index c45cf5b0f..def92d1db 100644
--- a/src/Subscriber/PaginateElasticaQuerySubscriber.php
+++ b/src/Subscriber/PaginateElasticaQuerySubscriber.php
@@ -3,7 +3,7 @@
/*
* This file is part of the FOSElasticaBundle package.
*
- * (c) FriendsOfSymfony
+ * (c) FriendsOfSymfony
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -25,27 +25,21 @@ class PaginateElasticaQuerySubscriber implements EventSubscriberInterface
*/
private $requestStack;
- /**
- * @param RequestStack $requestStack
- */
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
- /**
- * @param ItemsEvent $event
- */
public function items(ItemsEvent $event)
{
if ($event->target instanceof PaginatorAdapterInterface) {
// Add sort to query
$this->setSorting($event);
- /** @var $results PartialResultsInterface */
+ /** @var PartialResultsInterface $results */
$results = $event->target->getResults($event->getOffset(), $event->getLimit());
- $event->count = $results->getTotalHits();
+ $event->count = (int) $results->getTotalHits();
$event->items = $results->toArray();
$aggregations = $results->getAggregations();
if (null != $aggregations) {
@@ -68,12 +62,11 @@ public static function getSubscribedEvents()
/**
* Adds knp paging sort to query.
- *
- * @param ItemsEvent $event
*/
protected function setSorting(ItemsEvent $event)
{
- $options = $event->options;
+ // Bugfix for PHP 7.4 as options can be null and generate a "Trying to access array offset on value of type null" error
+ $options = $event->options ?? [];
$sortField = $this->getFromRequest($options['sortFieldParameterName'] ?? null);
if (!$sortField && isset($options['defaultSortFieldName'])) {
@@ -94,7 +87,7 @@ protected function getSort($sortField, array $options = [])
];
if (isset($options['sortNestedPath'])) {
- $path = is_callable($options['sortNestedPath']) ?
+ $path = \is_callable($options['sortNestedPath']) ?
$options['sortNestedPath']($sortField) : $options['sortNestedPath'];
if (!empty($path)) {
@@ -103,7 +96,7 @@ protected function getSort($sortField, array $options = [])
}
if (isset($options['sortNestedFilter'])) {
- $filter = is_callable($options['sortNestedFilter']) ?
+ $filter = \is_callable($options['sortNestedFilter']) ?
$options['sortNestedFilter']($sortField) : $options['sortNestedFilter'];
if (!empty($filter)) {
@@ -123,28 +116,24 @@ protected function getSortDirection($sortField, array $options = [])
$sortDirection = $options['defaultSortDirection'];
}
- if ('desc' === strtolower($sortDirection)) {
+ if ('desc' === \strtolower($sortDirection ?? '')) {
$dir = 'desc';
}
// check if the requested sort field is in the sort whitelist
- if (isset($options['sortFieldWhitelist']) && !in_array($sortField, $options['sortFieldWhitelist'])) {
- throw new \UnexpectedValueException(sprintf('Cannot sort by: [%s] this field is not in whitelist', $sortField));
+ if (isset($options['sortFieldAllowList']) && !\in_array($sortField, $options['sortFieldAllowList'], true)) {
+ throw new \UnexpectedValueException(\sprintf('Cannot sort by: [%s] this field is not in whitelist', $sortField));
}
return $dir;
}
- /**
- * @return Request|null
- */
- private function getRequest()
+ private function getRequest(): ?Request
{
return $this->requestStack->getCurrentRequest();
}
/**
- * @param string|null $key
* @return mixed|null
*/
private function getFromRequest(?string $key)
diff --git a/tests/Functional/ConfigurationManagerTest.php b/tests/Functional/ConfigurationManagerTest.php
index 61fbe8a84..48ab15c06 100644
--- a/tests/Functional/ConfigurationManagerTest.php
+++ b/tests/Functional/ConfigurationManagerTest.php
@@ -35,9 +35,8 @@ public function testContainerSource()
$index = $manager->getIndexConfiguration('index');
$this->assertSame('index', $index->getName());
- $this->assertGreaterThanOrEqual(2, count($index->getTypes()));
+ $this->assertSame(1, count($index->getTypes()));
$this->assertInstanceOf(TypeConfig::class, $index->getType('type'));
- $this->assertInstanceOf(TypeConfig::class, $index->getType('parent'));
}
/**
diff --git a/tests/Functional/IndexableCallbackTest.php b/tests/Functional/IndexableCallbackTest.php
index 93c4603dd..32a68f80e 100644
--- a/tests/Functional/IndexableCallbackTest.php
+++ b/tests/Functional/IndexableCallbackTest.php
@@ -39,9 +39,9 @@ public function testIndexableCallback()
/** @var \FOS\ElasticaBundle\Provider\Indexable $in */
$in = static::$kernel->getContainer()->get('test_alias.fos_elastica.indexable');
- $this->assertTrue($in->isObjectIndexable('index', 'type', new TypeObj()));
- $this->assertTrue($in->isObjectIndexable('index', 'type2', new TypeObj()));
- $this->assertFalse($in->isObjectIndexable('index', 'type3', new TypeObj()));
- $this->assertFalse($in->isObjectIndexable('index', 'type4', new TypeObj()));
+ $this->assertTrue($in->isObjectIndexable('first_index', 'type', new TypeObj()));
+ $this->assertTrue($in->isObjectIndexable('second_index', 'type2', new TypeObj()));
+ $this->assertFalse($in->isObjectIndexable('third_index', 'type3', new TypeObj()));
+ $this->assertFalse($in->isObjectIndexable('fourth_index', 'type4', new TypeObj()));
}
}
diff --git a/tests/Functional/MappingToElasticaTest.php b/tests/Functional/MappingToElasticaTest.php
index 9781a9430..b65433436 100644
--- a/tests/Functional/MappingToElasticaTest.php
+++ b/tests/Functional/MappingToElasticaTest.php
@@ -38,7 +38,6 @@ public function testResetIndexAddsMappings()
$type = $this->getType();
$mapping = $type->getMapping();
- $this->assertSame('parent', $mapping['type']['_parent']['type']);
$this->assertSame('strict', $mapping['type']['dynamic']);
$this->assertArrayHasKey('dynamic', $mapping['type']['properties']['dynamic_allowed']);
@@ -64,9 +63,9 @@ public function testORMResetIndexAddsMappings()
{
static::bootKernel(['test_case' => 'ORM']);
$resetter = $this->getResetter();
- $resetter->resetIndex('index');
+ $resetter->resetIndex('first_index');
- $type = $this->getType();
+ $type = $this->getType('first_index', 'type');
$mapping = $type->getMapping();
$this->assertNotEmpty($mapping, 'Mapping was populated');
@@ -76,9 +75,9 @@ public function testORMResetType()
{
static::bootKernel(['test_case' => 'ORM']);
$resetter = $this->getResetter();
- $resetter->resetIndexType('index', 'type');
+ $resetter->resetIndexType('first_index', 'type');
- $type = $this->getType();
+ $type = $this->getType('first_index', 'type');
$mapping = $type->getMapping();
$this->assertNotEmpty($mapping, 'Mapping was populated');
@@ -87,7 +86,7 @@ public function testORMResetType()
public function testMappingIteratorToArrayField()
{
static::bootKernel(['test_case' => 'ORM']);
- $persister = static::$kernel->getContainer()->get('fos_elastica.object_persister.index.type');
+ $persister = static::$kernel->getContainer()->get('fos_elastica.object_persister.first_index.type');
$object = new TypeObj();
$object->id = 1;
@@ -113,8 +112,8 @@ private function getResetter()
*
* @return \Elastica\Type
*/
- private function getType($type = 'type')
+ private function getType($index = 'index', $type = 'type')
{
- return static::$kernel->getContainer()->get('fos_elastica.index.index.'.$type);
+ return static::$kernel->getContainer()->get("fos_elastica.index.$index.$type");
}
}
diff --git a/tests/Functional/ProfilerTest.php b/tests/Functional/ProfilerTest.php
index 6386ce14a..e7f2bb6ca 100644
--- a/tests/Functional/ProfilerTest.php
+++ b/tests/Functional/ProfilerTest.php
@@ -40,7 +40,7 @@ class ProfilerTest extends WebTestCase
/** @var ElasticaDataCollector */
private $collector;
- public function setUp()
+ public function setUp(): void
{
$this->logger = new ElasticaLogger($this->createMock(LoggerInterface::class), true);
$this->collector = new ElasticaDataCollector($this->logger);
@@ -85,9 +85,9 @@ public function testRender($query)
$output = str_replace(""", '"', $output);
- $this->assertContains('{"query":{"match_all":', $output);
- $this->assertContains('index/_search', $output);
- $this->assertContains('localhost:9200', $output);
+ $this->assertStringContainsString('{"query":{"match_all":', $output);
+ $this->assertStringContainsString('index/_search', $output);
+ $this->assertStringContainsString('localhost:9200', $output);
}
public function queryProvider()
diff --git a/tests/Functional/PropertyPathTest.php b/tests/Functional/PropertyPathTest.php
index 4364f9803..6bdc26059 100644
--- a/tests/Functional/PropertyPathTest.php
+++ b/tests/Functional/PropertyPathTest.php
@@ -20,7 +20,7 @@
namespace FOS\ElasticaBundle\Tests\Functional;
-use Elastica\Query\Match;
+use Elastica\Query\MatchQuery;
/**
* @group functional
@@ -31,16 +31,16 @@ public function testContainerSource()
{
static::bootKernel(['test_case' => 'ORM']);
/** @var \FOS\ElasticaBundle\Persister\ObjectPersister $persister */
- $persister = static::$kernel->getContainer()->get('fos_elastica.object_persister.index.property_paths_type');
+ $persister = static::$kernel->getContainer()->get('fos_elastica.object_persister.seventh_index.property_paths_type');
$obj = new TypeObj();
$obj->coll = 'Hello';
$persister->insertOne($obj);
/** @var \Elastica\Index $index */
- $index = static::$kernel->getContainer()->get('fos_elastica.index.index');
+ $index = static::$kernel->getContainer()->get('fos_elastica.index.seventh_index');
$index->refresh();
- $query = new Match();
+ $query = new MatchQuery();
$query->setField('something', 'Hello');
$search = $index->createSearch($query);
diff --git a/tests/Functional/ResetTemplatesCommandTest.php b/tests/Functional/ResetTemplatesCommandTest.php
index ce2ddba6c..de6aeb80d 100644
--- a/tests/Functional/ResetTemplatesCommandTest.php
+++ b/tests/Functional/ResetTemplatesCommandTest.php
@@ -26,7 +26,7 @@ class ResetTemplatesCommandTest extends WebTestCase
*/
private $application;
- protected function setUp()
+ protected function setUp(): void
{
static::bootKernel(['test_case' => 'Basic']);
$this->application = $application = new Application(static::$kernel);
@@ -47,7 +47,7 @@ public function testResetAllTemplates()
));
$output = $commandTester->getDisplay();
- $this->assertContains('Resetting all templates', $output);
+ $this->assertStringContainsString('Resetting all templates', $output);
$templates = $this->fetchAllTemplates();
$this->assertArrayHasKey('index_template_2_name', $templates);
@@ -69,8 +69,8 @@ public function testResetAllTemplatesAndForceDelete()
);
$output = $commandTester->getDisplay();
- $this->assertContains('You are going to remove all template indexes. Are you sure?', $output);
- $this->assertContains('Resetting all templates', $output);
+ $this->assertStringContainsString('You are going to remove all template indexes. Are you sure?', $output);
+ $this->assertStringContainsString('Resetting all templates', $output);
$templates = $this->fetchAllTemplates();
$this->assertArrayHasKey('index_template_2_name', $templates);
@@ -89,8 +89,8 @@ public function testResetExactTemplate()
));
$output = $commandTester->getDisplay();
- $this->assertContains('Resetting template', $output);
- $this->assertContains('index_template_example_1', $output);
+ $this->assertStringContainsString('Resetting template', $output);
+ $this->assertStringContainsString('index_template_example_1', $output);
$templates = $this->fetchAllTemplates();
$this->assertArrayHasKey('index_template_1_name', $templates);
@@ -110,9 +110,9 @@ public function testResetExactTemplateAndForceDelete()
));
$output = $commandTester->getDisplay();
- $this->assertContains('You are going to remove all template indexes. Are you sure?', $output);
- $this->assertContains('Resetting template', $output);
- $this->assertContains('index_template_example_1', $output);
+ $this->assertStringContainsString('You are going to remove all template indexes. Are you sure?', $output);
+ $this->assertStringContainsString('Resetting template', $output);
+ $this->assertStringContainsString('index_template_example_1', $output);
$templates = $this->fetchAllTemplates();
$this->assertArrayHasKey('index_template_1_name', $templates);
diff --git a/tests/Functional/SerializerTest.php b/tests/Functional/SerializerTest.php
index d682d761d..debd2649f 100644
--- a/tests/Functional/SerializerTest.php
+++ b/tests/Functional/SerializerTest.php
@@ -27,6 +27,7 @@ class SerializerTest extends WebTestCase
{
public function testMappingIteratorToArrayField()
{
+ error_reporting(E_ALL ^ E_DEPRECATED);
static::bootKernel(['test_case' => 'Serializer']);
$persister = static::$kernel->getContainer()->get('fos_elastica.object_persister.index.type');
@@ -49,8 +50,8 @@ public function testWithNullValues()
static::bootKernel(['test_case' => 'Serializer']);
$container = static::$kernel->getContainer();
- $disabledNullPersister = $container->get('fos_elastica.object_persister.index.type_serialize_null_disabled');
- $enabledNullPersister = $container->get('fos_elastica.object_persister.index.type_serialize_null_enabled');
+ $disabledNullPersister = $container->get('fos_elastica.object_persister.index_serialize_null_disabled.type_serialize_null_disabled');
+ $enabledNullPersister = $container->get('fos_elastica.object_persister.index_serialize_null_enabled.type_serialize_null_enabled');
$object = new TypeObj();
$object->id = 1;
@@ -59,12 +60,12 @@ public function testWithNullValues()
$enabledNullPersister->insertOne($object);
// Tests that attributes with null values are not persisted into an Elasticsearch type without the serialize_null option
- $disabledNullType = $container->get('fos_elastica.index.index.type_serialize_null_disabled');
+ $disabledNullType = $container->get('fos_elastica.index.index_serialize_null_disabled.type_serialize_null_disabled');
$documentData = $disabledNullType->getDocument(1)->getData();
$this->assertArrayNotHasKey('field1', $documentData);
// Tests that attributes with null values are persisted into an Elasticsearch type with the serialize_null option
- $enabledNullType = $container->get('fos_elastica.index.index.type_serialize_null_enabled');
+ $enabledNullType = $container->get('fos_elastica.index.index_serialize_null_enabled.type_serialize_null_enabled');
$documentData = $enabledNullType->getDocument(1)->getData();
$this->assertArrayHasKey('field1', $documentData);
$this->assertNull($documentData['field1']);
@@ -74,6 +75,6 @@ public function testUnmappedType()
{
static::bootKernel(['test_case' => 'Serializer']);
$resetter = static::$kernel->getContainer()->get('fos_elastica.resetter');
- $resetter->resetIndex('index');
+ $resetter->resetIndex('index_unmapped');
}
}
diff --git a/tests/Functional/WebTestCase.php b/tests/Functional/WebTestCase.php
index 1ba12dde5..22ef82227 100644
--- a/tests/Functional/WebTestCase.php
+++ b/tests/Functional/WebTestCase.php
@@ -36,12 +36,12 @@ protected static function getKernelClass()
return AppKernel::class;
}
- public static function setUpBeforeClass()
+ public static function setUpBeforeClass(): void
{
static::deleteTmpDir();
}
- public static function tearDownAfterClass()
+ public static function tearDownAfterClass(): void
{
static::deleteTmpDir();
}
diff --git a/tests/Functional/app/AppKernel.php b/tests/Functional/app/AppKernel.php
index ca1173ce8..0571e9961 100644
--- a/tests/Functional/app/AppKernel.php
+++ b/tests/Functional/app/AppKernel.php
@@ -44,7 +44,7 @@ public function __construct($varDir, $testCase, $rootConfig, $environment, $debu
parent::__construct($environment, $debug);
}
- public function registerBundles()
+ public function registerBundles(): iterable
{
if (!file_exists($filename = $this->getRootDir().'/'.$this->testCase.'/bundles.php')) {
throw new \RuntimeException(sprintf('The bundles file "%s" does not exist.', $filename));
@@ -58,12 +58,12 @@ public function getRootDir()
return __DIR__;
}
- public function getCacheDir()
+ public function getCacheDir(): string
{
return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/cache/'.$this->environment;
}
- public function getLogDir()
+ public function getLogDir(): string
{
return sys_get_temp_dir().'/'.$this->varDir.'/'.$this->testCase.'/logs';
}
@@ -87,7 +87,7 @@ public function unserialize($str)
call_user_func_array([$this, '__construct'], unserialize($str));
}
- protected function getKernelParameters()
+ protected function getKernelParameters(): array
{
$parameters = parent::getKernelParameters();
$parameters['kernel.test_case'] = $this->testCase;
diff --git a/tests/Functional/app/Basic/config.yml b/tests/Functional/app/Basic/config.yml
index 48071a1ce..122bcdb9c 100644
--- a/tests/Functional/app/Basic/config.yml
+++ b/tests/Functional/app/Basic/config.yml
@@ -27,37 +27,27 @@ fos_elastica:
my_analyzer:
type: custom
tokenizer: lowercase
- filter: [my_ngram]
+ filter: [ my_ngram ]
filter:
my_ngram:
type: "nGram"
min_gram: 3
- max_gram: 5
+ max_gram: 4
types:
- parent:
- dynamic: false
- dynamic_templates:
- dates:
- match: "date_*"
- mapping:
- type: date
- properties:
- field1: ~
- field2: ~
type:
dynamic: strict
date_detection: false
dynamic_date_formats: [ 'yyyy-MM-dd' ]
dynamic_templates:
- dates:
- match: "date_*"
- mapping:
- type: date
+ match: "date_*"
+ mapping:
+ type: date
- strings:
- match: "*"
- mapping:
- analyzer: english
- type: text
+ match: "*"
+ mapping:
+ analyzer: english
+ type: text
numeric_detection: true
properties:
field1: ~
@@ -87,11 +77,10 @@ fos_elastica:
lastlogin: { type: date, format: basic_date_time }
birthday: { type: date, format: "yyyy-MM-dd" }
dynamic_allowed: { type: object, dynamic: true }
- _parent:
- type: "parent"
- property: "parent"
- identifier: "id"
- null_mappings:
+ null_mappings_index:
+ index_name: 'foselastica_basic_test_%kernel.environment%'
+ types:
+ type:
properties: ~
empty_index: ~
@@ -107,7 +96,7 @@ fos_elastica:
types:
some_type:
properties:
- document_name_field_1: { type: string, index: not_analyzed }
+ document_name_field_1: { type: keyword }
index_template_example_2:
client: 'default'
template_name: 'index_template_2_name'
@@ -119,4 +108,4 @@ fos_elastica:
types:
some_type:
properties:
- document_name_field_2: { type: string, index: not_analyzed }
+ document_name_field_2: { type: keyword }
diff --git a/tests/Functional/app/ORM/config.yml b/tests/Functional/app/ORM/config.yml
index 311821ed9..bc6814bb6 100644
--- a/tests/Functional/app/ORM/config.yml
+++ b/tests/Functional/app/ORM/config.yml
@@ -20,14 +20,14 @@ services:
fos_elastica:
clients:
default:
- url: "http://localhost:9200"
+ url: "http://%fos_elastica.host%:%fos_elastica.port%"
indexes:
fos_elastica_orm_test:
types:
type:
properties:
field1: ~
- index:
+ first_index:
index_name: "foselastica_orm_test_%kernel.environment%"
types:
type:
@@ -41,6 +41,9 @@ fos_elastica:
provider:
debug_logging: true
indexable_callback: 'object.isIndexable() && !object.isntIndexable()'
+ second_index:
+ index_name: "foselastica_orm_test_second_%kernel.environment%"
+ types:
type2:
properties:
field1: ~
@@ -49,6 +52,9 @@ fos_elastica:
model: FOS\ElasticaBundle\Tests\Functional\TypeObj
listener: ~
indexable_callback: [ "@indexable_service", 'isIndexable' ]
+ third_index:
+ index_name: "foselastica_orm_test_third_%kernel.environment%"
+ types:
type3:
properties:
field1: ~
@@ -59,6 +65,9 @@ fos_elastica:
provider: ~
listener: ~
indexable_callback: 'isntIndexable'
+ fourth_index:
+ index_name: "foselastica_orm_test_fourth_%kernel.environment%"
+ types:
type4:
properties:
field1: ~
@@ -69,6 +78,9 @@ fos_elastica:
provider: ~
listener: ~
indexable_callback: [ 'FOS\ElasticaBundle\Tests\Functional\app\ORM\IndexableService', 'isntIndexable' ]
+ seventh_index:
+ index_name: "foselastica_orm_test_seventh_%kernel.environment%"
+ types:
property_paths_type:
persistence:
driver: orm
@@ -81,6 +93,9 @@ fos_elastica:
property_path: coll
dynamic:
property_path: false
+ fifth_index:
+ index_name: "foselastica_orm_test_fifth_%kernel.environment%"
+ types:
type_with_repository:
properties:
field1: ~
@@ -91,8 +106,8 @@ fos_elastica:
repository: FOS\ElasticaBundle\Tests\Functional\TypeObjectRepository
finder: ~
provider: ~
- second_index:
- index_name: "foselastica_orm_test_second_%kernel.environment%"
+ sixth_index:
+ index_name: "foselastica_orm_test_sixth_%kernel.environment%"
types:
type:
properties:
diff --git a/tests/Functional/app/Serializer/config.yml b/tests/Functional/app/Serializer/config.yml
index 45cc96772..4599cff24 100644
--- a/tests/Functional/app/Serializer/config.yml
+++ b/tests/Functional/app/Serializer/config.yml
@@ -24,7 +24,7 @@ jms_serializer:
fos_elastica:
clients:
default:
- url: "http://localhost:9200"
+ url: "http://%fos_elastica.host%:%fos_elastica.port%"
serializer:
serializer: jms_serializer
indexes:
@@ -41,6 +41,9 @@ fos_elastica:
serializer:
groups: ['search', 'Default']
version: 1.1
+ index_serialize_null_disabled:
+ index_name: "foselastica_ser_nonull_test_%kernel.environment%"
+ types:
type_serialize_null_disabled:
properties:
field1: ~
@@ -49,6 +52,9 @@ fos_elastica:
model: FOS\ElasticaBundle\Tests\Functional\TypeObj
serializer:
serialize_null: false
+ index_serialize_null_enabled:
+ index_name: "foselastica_ser_null_test_%kernel.environment%"
+ types:
type_serialize_null_enabled:
properties:
field1: ~
@@ -57,6 +63,9 @@ fos_elastica:
model: FOS\ElasticaBundle\Tests\Functional\TypeObj
serializer:
serialize_null: true
+ index_unmapped:
+ index_name: "foselastica_ser_unmapped_test_%kernel.environment%"
+ types:
unmapped:
persistence:
driver: orm
diff --git a/tests/Unit/Command/CreateCommandTest.php b/tests/Unit/Command/CreateCommandTest.php
index c6281e640..4edc81194 100644
--- a/tests/Unit/Command/CreateCommandTest.php
+++ b/tests/Unit/Command/CreateCommandTest.php
@@ -62,7 +62,7 @@ class CreateCommandTest extends TestCase
*/
private $index;
- protected function setUp()
+ protected function setUp(): void
{
$this->indexManager = $this->createMock(IndexManager::class);
$this->mappingBuilder = $this->createMock(MappingBuilder::class);
diff --git a/tests/Unit/Command/ResetCommandTest.php b/tests/Unit/Command/ResetCommandTest.php
index 02a451934..c4931ae7c 100644
--- a/tests/Unit/Command/ResetCommandTest.php
+++ b/tests/Unit/Command/ResetCommandTest.php
@@ -35,7 +35,7 @@ class ResetCommandTest extends TestCase
*/
private $indexManager;
- protected function setUp()
+ protected function setUp(): void
{
$this->resetter = $this->createMock(Resetter::class);
$this->indexManager = $this->createMock(IndexManager::class);
@@ -49,13 +49,13 @@ public function testResetAllIndexes()
->method('getAllIndexes')
->will($this->returnValue(['index1' => true, 'index2' => true]));
- $this->resetter->expects($this->at(0))
+ $this->resetter->expects($this->exactly(2))
->method('resetIndex')
- ->with($this->equalTo('index1'));
-
- $this->resetter->expects($this->at(1))
- ->method('resetIndex')
- ->with($this->equalTo('index2'));
+ ->withConsecutive(
+ [$this->equalTo('index1')],
+ [$this->equalTo('index2')]
+ )
+ ;
$this->command->run(
new ArrayInput([]),
@@ -68,7 +68,7 @@ public function testResetIndex()
$this->indexManager->expects($this->never())
->method('getAllIndexes');
- $this->resetter->expects($this->at(0))
+ $this->resetter->expects($this->once())
->method('resetIndex')
->with($this->equalTo('index1'));
@@ -86,7 +86,7 @@ public function testResetIndexType()
$this->resetter->expects($this->never())
->method('resetIndex');
- $this->resetter->expects($this->at(0))
+ $this->resetter->expects($this->once())
->method('resetIndexType')
->with($this->equalTo('index1'), $this->equalTo('type1'));
diff --git a/tests/Unit/Configuration/IndexTemplateConfigTest.php b/tests/Unit/Configuration/IndexTemplateConfigTest.php
index 983ee5ad2..f64e5f1b2 100644
--- a/tests/Unit/Configuration/IndexTemplateConfigTest.php
+++ b/tests/Unit/Configuration/IndexTemplateConfigTest.php
@@ -27,11 +27,9 @@ public function testInstantiate()
);
}
- /**
- * @expectedException \InvalidArgumentException
- */
public function testIncorrectInstantiate()
{
+ $this->expectException(\InvalidArgumentException::class);
$name = 'index_template1';
new IndexTemplateConfig($name, array(), array());
}
diff --git a/tests/Unit/DependencyInjection/ConfigSourcePassTest.php b/tests/Unit/DependencyInjection/ConfigSourcePassTest.php
index 57463295d..f5811eeb8 100644
--- a/tests/Unit/DependencyInjection/ConfigSourcePassTest.php
+++ b/tests/Unit/DependencyInjection/ConfigSourcePassTest.php
@@ -4,15 +4,18 @@
use FOS\ElasticaBundle\DependencyInjection\Compiler\ConfigSourcePass;
use PHPUnit\Framework\TestCase;
+use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
class ConfigSourcePassTest extends TestCase
{
+ use ProphecyTrait;
+
/** @var ContainerBuilder */
private $container;
- protected function setUp()
+ protected function setUp(): void
{
$this->container = $this->prophesize(ContainerBuilder::class);
}
diff --git a/tests/Unit/DependencyInjection/ConfigurationTest.php b/tests/Unit/DependencyInjection/ConfigurationTest.php
index c034055f3..44e288130 100644
--- a/tests/Unit/DependencyInjection/ConfigurationTest.php
+++ b/tests/Unit/DependencyInjection/ConfigurationTest.php
@@ -22,7 +22,7 @@ class ConfigurationTest extends TestCase
*/
private $processor;
- protected function setUp()
+ protected function setUp(): void
{
$this->processor = new Processor();
}
diff --git a/tests/Unit/Doctrine/AbstractElasticaToModelTransformerTest.php b/tests/Unit/Doctrine/AbstractElasticaToModelTransformerTest.php
index 49ea7a491..943da7d43 100644
--- a/tests/Unit/Doctrine/AbstractElasticaToModelTransformerTest.php
+++ b/tests/Unit/Doctrine/AbstractElasticaToModelTransformerTest.php
@@ -33,7 +33,7 @@ class AbstractElasticaToModelTransformerTest extends TestCase
*/
protected $objectClass = 'stdClass';
- protected function setUp()
+ protected function setUp(): void
{
$this->registry = $this->createMock(ManagerRegistry::class);
}
@@ -66,10 +66,10 @@ public function testIgnoreMissingOptionDuringTransformHybrid()
$hybridResults = $transformer->hybridTransform([$firstElasticaResult, $secondElasticaResult, $thirdElasticaResult]);
$this->assertCount(2, $hybridResults);
- $this->assertSame($firstOrmResult, $hybridResults[0]->getTransformed());
- $this->assertSame($firstElasticaResult, $hybridResults[0]->getResult());
- $this->assertSame($secondOrmResult, $hybridResults[1]->getTransformed());
- $this->assertSame($thirdElasticaResult, $hybridResults[1]->getResult());
+ $this->assertEquals($firstOrmResult, $hybridResults[0]->getTransformed());
+ $this->assertEquals($firstElasticaResult, $hybridResults[0]->getResult());
+ $this->assertEquals($secondOrmResult, $hybridResults[1]->getTransformed());
+ $this->assertEquals($thirdElasticaResult, $hybridResults[1]->getResult());
}
public function testObjectClassCanBeSet()
@@ -106,7 +106,7 @@ public function testObjectsAreTransformedByFindingThemByTheirIdentifiers($elasti
$transformedObjects = $transformer->transform($elasticaResults);
- $this->assertSame($doctrineObjects, $transformedObjects);
+ $this->assertEquals($doctrineObjects, $transformedObjects);
}
/**
@@ -147,7 +147,7 @@ public function testAnExceptionIsNotThrownWhenTheNumberOfFoundObjectsIsLessThanT
$results = $transformer->transform($elasticaResults);
- $this->assertSame([], $results);
+ $this->assertEquals([], $results);
}
/**
@@ -166,7 +166,7 @@ public function testHighlightsAreSetOnTransformedObjects($elasticaResults, $doct
$results = $transformer->transform($elasticaResults);
foreach ($results as $result) {
- $this->assertInternalType('array', $result->highlights);
+ $this->assertisArray($result->highlights);
$this->assertNotEmpty($result->highlights);
}
}
@@ -188,9 +188,9 @@ public function testResultsAreSortedByIdentifier($elasticaResults, $doctrineObje
$results = $transformer->transform($elasticaResults);
- $this->assertSame($doctrineObjects[2], $results[0]);
- $this->assertSame($doctrineObjects[1], $results[1]);
- $this->assertSame($doctrineObjects[0], $results[2]);
+ $this->assertEquals($doctrineObjects[2], $results[0]);
+ $this->assertEquals($doctrineObjects[1], $results[1]);
+ $this->assertEquals($doctrineObjects[0], $results[2]);
}
/**
@@ -212,8 +212,8 @@ public function testHybridTransformReturnsDecoratedResults($elasticaResults, $do
foreach ($results as $key => $result) {
$this->assertInstanceOf(HybridResult::class, $result);
- $this->assertSame($elasticaResults[$key], $result->getResult());
- $this->assertSame($doctrineObjects[$key], $result->getTransformed());
+ $this->assertEquals($elasticaResults[$key], $result->getResult());
+ $this->assertEquals($doctrineObjects[$key], $result->getTransformed());
}
}
diff --git a/tests/Unit/Doctrine/MongoDB/ListenerTest.php b/tests/Unit/Doctrine/MongoDB/ListenerTest.php
index 3a1b3527d..18fda96c4 100644
--- a/tests/Unit/Doctrine/MongoDB/ListenerTest.php
+++ b/tests/Unit/Doctrine/MongoDB/ListenerTest.php
@@ -15,7 +15,7 @@
class ListenerTest extends BaseListenerTest
{
- protected function setUp()
+ protected function setUp(): void
{
if (!class_exists(\Doctrine\ODM\MongoDB\DocumentManager::class)) {
$this->markTestSkipped('Doctrine MongoDB ODM is not available.');
diff --git a/tests/Unit/Doctrine/MongoDBPagerProviderTest.php b/tests/Unit/Doctrine/MongoDBPagerProviderTest.php
index d21744195..52236bb49 100644
--- a/tests/Unit/Doctrine/MongoDBPagerProviderTest.php
+++ b/tests/Unit/Doctrine/MongoDBPagerProviderTest.php
@@ -1,25 +1,37 @@
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
namespace FOS\ElasticaBundle\Tests\Unit\Doctrine;
use Doctrine\ODM\MongoDB\DocumentManager;
-use Doctrine\ODM\MongoDB\DocumentRepository;
use Doctrine\ODM\MongoDB\Query\Builder;
+use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
use FOS\ElasticaBundle\Doctrine\MongoDBPagerProvider;
use FOS\ElasticaBundle\Doctrine\RegisterListenersService;
use FOS\ElasticaBundle\Provider\PagerfantaPager;
use FOS\ElasticaBundle\Provider\PagerInterface;
use FOS\ElasticaBundle\Provider\PagerProviderInterface;
use FOS\ElasticaBundle\Tests\Unit\Mocks\DoctrineMongoDBCustomRepositoryMock;
-use Pagerfanta\Adapter\DoctrineODMMongoDBAdapter;
+use Pagerfanta\Doctrine\MongoDBODM\QueryAdapter;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\ManagerRegistry;
+/**
+ * @internal
+ */
class MongoDBPagerProviderTest extends TestCase
{
- protected function setUp()
+ protected function setUp(): void
{
- if (!class_exists(DocumentManager::class)) {
+ if (!\class_exists(DocumentManager::class)) {
$this->markTestSkipped('Doctrine MongoDB ODM is not available.');
}
}
@@ -51,22 +63,24 @@ public function testShouldReturnPagerfanataPagerWithDoctrineODMMongoDBAdapter()
$repository
->expects($this->once())
->method('createQueryBuilder')
- ->willReturn($expectedBuilder);
+ ->willReturn($expectedBuilder)
+ ;
$manager = $this->createMock(DocumentManager::class);
$manager
->expects($this->once())
->method('getRepository')
->with($objectClass)
- ->willReturn($repository);
-
+ ->willReturn($repository)
+ ;
$doctrine = $this->createDoctrineMock();
$doctrine
->expects($this->once())
->method('getManagerForClass')
->with($objectClass)
- ->willReturn($manager);
+ ->willReturn($manager)
+ ;
$provider = new MongoDBPagerProvider($doctrine, $this->createRegisterListenersServiceMock(), $objectClass, $baseConfig);
@@ -75,9 +89,8 @@ public function testShouldReturnPagerfanataPagerWithDoctrineODMMongoDBAdapter()
$this->assertInstanceOf(PagerfantaPager::class, $pager);
$adapter = $pager->getPagerfanta()->getAdapter();
- $this->assertInstanceOf(DoctrineODMMongoDBAdapter::class, $adapter);
-
- $this->assertAttributeSame($expectedBuilder, 'queryBuilder', $adapter);
+ $this->assertInstanceOf(QueryAdapter::class, $adapter);
+ $this->assertSame($expectedBuilder, $adapter->getQueryBuilder());
}
public function testShouldAllowCallCustomRepositoryMethod()
@@ -89,19 +102,22 @@ public function testShouldAllowCallCustomRepositoryMethod()
$repository
->expects($this->once())
->method('createCustomQueryBuilder')
- ->willReturn($this->createMock(Builder::class));
+ ->willReturn($this->createMock(Builder::class))
+ ;
$manager = $this->createMock(DocumentManager::class);
$manager
->expects($this->once())
->method('getRepository')
- ->willReturn($repository);
+ ->willReturn($repository)
+ ;
$doctrine = $this->createDoctrineMock();
$doctrine
->expects($this->once())
->method('getManagerForClass')
- ->willReturn($manager);
+ ->willReturn($manager)
+ ;
$provider = new MongoDBPagerProvider($doctrine, $this->createRegisterListenersServiceMock(), $objectClass, $baseConfig);
@@ -119,20 +135,22 @@ public function testShouldCallRegisterListenersService()
$repository
->expects($this->once())
->method('createQueryBuilder')
- ->willReturn($this->createMock(Builder::class));
+ ->willReturn($this->createMock(Builder::class))
+ ;
$manager = $this->createMock(DocumentManager::class);
$manager
->expects($this->once())
->method('getRepository')
- ->willReturn($repository);
-
+ ->willReturn($repository)
+ ;
$doctrine = $this->createDoctrineMock();
$doctrine
->expects($this->once())
->method('getManagerForClass')
- ->willReturn($manager);
+ ->willReturn($manager)
+ ;
$registerListenersMock = $this->createRegisterListenersServiceMock();
$registerListenersMock
@@ -141,13 +159,13 @@ public function testShouldCallRegisterListenersService()
->with($this->identicalTo($manager), $this->isInstanceOf(PagerInterface::class), $baseConfig)
;
- $provider = new MongoDBPagerProvider($doctrine,$registerListenersMock, $objectClass, $baseConfig);
+ $provider = new MongoDBPagerProvider($doctrine, $registerListenersMock, $objectClass, $baseConfig);
$provider->provide();
}
/**
- * @return \PHPUnit_Framework_MockObject_MockObject|ManagerRegistry
+ * @return \PHPUnit\Framework\MockObject\MockObject|ManagerRegistry
*/
private function createDoctrineMock()
{
@@ -155,10 +173,10 @@ private function createDoctrineMock()
}
/**
- * @return RegisterListenersService|\PHPUnit_Framework_MockObject_MockObject
+ * @return RegisterListenersService|\PHPUnit\Framework\MockObject\MockObject
*/
private function createRegisterListenersServiceMock()
{
return $this->createMock(RegisterListenersService::class);
}
-}
\ No newline at end of file
+}
diff --git a/tests/Unit/Doctrine/ORM/ElasticaToModelTransformerTest.php b/tests/Unit/Doctrine/ORM/ElasticaToModelTransformerTest.php
index ca84cadf8..16353fc7b 100644
--- a/tests/Unit/Doctrine/ORM/ElasticaToModelTransformerTest.php
+++ b/tests/Unit/Doctrine/ORM/ElasticaToModelTransformerTest.php
@@ -39,7 +39,7 @@ class ElasticaToModelTransformerTest extends TestCase
*/
protected $repository;
- protected function setUp()
+ protected function setUp(): void
{
$this->registry = $this->createMock(ManagerRegistry::class);
$this->manager = $this->createMock(ObjectManager::class);
diff --git a/tests/Unit/Doctrine/ORMPagerProviderTest.php b/tests/Unit/Doctrine/ORMPagerProviderTest.php
index f84c91807..7bf762360 100644
--- a/tests/Unit/Doctrine/ORMPagerProviderTest.php
+++ b/tests/Unit/Doctrine/ORMPagerProviderTest.php
@@ -1,5 +1,14 @@
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
namespace FOS\ElasticaBundle\Tests\Unit\Doctrine;
use Doctrine\ORM\EntityManager;
@@ -12,10 +21,13 @@
use FOS\ElasticaBundle\Provider\PagerInterface;
use FOS\ElasticaBundle\Provider\PagerProviderInterface;
use FOS\ElasticaBundle\Tests\Unit\Mocks\DoctrineORMCustomRepositoryMock;
-use Pagerfanta\Adapter\DoctrineORMAdapter;
+use Pagerfanta\Doctrine\ORM\QueryAdapter;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\ManagerRegistry;
+/**
+ * @internal
+ */
class ORMPagerProviderTest extends TestCase
{
public function testShouldImplementPagerProviderInterface()
@@ -42,28 +54,31 @@ public function testShouldReturnPagerfantaPagerWithDoctrineORMAdapter()
$expectedBuilder = $this->createMock(QueryBuilder::class);
$expectedBuilder->method('getDQLPart')
->with('orderBy')
- ->willReturn(array($this->createMock(OrderBy::class)));
+ ->willReturn([$this->createMock(OrderBy::class)])
+ ;
$repository = $this->createMock(EntityRepository::class);
$repository
->expects($this->once())
->method('createQueryBuilder')
- ->willReturn($expectedBuilder);
+ ->willReturn($expectedBuilder)
+ ;
$manager = $this->createMock(EntityManager::class);
$manager
->expects($this->once())
->method('getRepository')
->with($objectClass)
- ->willReturn($repository);
-
+ ->willReturn($repository)
+ ;
$doctrine = $this->createDoctrineMock();
$doctrine
->expects($this->once())
->method('getManagerForClass')
->with($objectClass)
- ->willReturn($manager);
+ ->willReturn($manager)
+ ;
$provider = new ORMPagerProvider($doctrine, $this->createRegisterListenersServiceMock(), $objectClass, $baseConfig);
@@ -72,7 +87,7 @@ public function testShouldReturnPagerfantaPagerWithDoctrineORMAdapter()
$this->assertInstanceOf(PagerfantaPager::class, $pager);
$adapter = $pager->getPagerfanta()->getAdapter();
- $this->assertInstanceOf(DoctrineORMAdapter::class, $adapter);
+ $this->assertInstanceOf(QueryAdapter::class, $adapter);
}
public function testShouldAllowCallCustomRepositoryMethod()
@@ -83,28 +98,31 @@ public function testShouldAllowCallCustomRepositoryMethod()
$expectedBuilder = $this->createMock(QueryBuilder::class);
$expectedBuilder->method('getDQLPart')
->with('orderBy')
- ->willReturn(array($this->createMock(OrderBy::class)));
+ ->willReturn([$this->createMock(OrderBy::class)])
+ ;
$repository = $this->createMock(DoctrineORMCustomRepositoryMock::class);
$repository
->expects($this->once())
->method('createCustomQueryBuilder')
- ->willReturn($expectedBuilder);
+ ->willReturn($expectedBuilder)
+ ;
$manager = $this->createMock(EntityManager::class);
$manager
->expects($this->once())
->method('getRepository')
->with($objectClass)
- ->willReturn($repository);
-
+ ->willReturn($repository)
+ ;
$doctrine = $this->createDoctrineMock();
$doctrine
->expects($this->once())
->method('getManagerForClass')
->with($objectClass)
- ->willReturn($manager);
+ ->willReturn($manager)
+ ;
$provider = new ORMPagerProvider($doctrine, $this->createRegisterListenersServiceMock(), $objectClass, $baseConfig);
@@ -121,28 +139,31 @@ public function testShouldCallRegisterListenersService()
$expectedBuilder = $this->createMock(QueryBuilder::class);
$expectedBuilder->method('getDQLPart')
->with('orderBy')
- ->willReturn(array($this->createMock(OrderBy::class)));
+ ->willReturn([$this->createMock(OrderBy::class)])
+ ;
$repository = $this->createMock(EntityRepository::class);
$repository
->expects($this->once())
->method('createQueryBuilder')
- ->willReturn($expectedBuilder);
+ ->willReturn($expectedBuilder)
+ ;
$manager = $this->createMock(EntityManager::class);
$manager
->expects($this->once())
->method('getRepository')
->with($objectClass)
- ->willReturn($repository);
-
+ ->willReturn($repository)
+ ;
$doctrine = $this->createDoctrineMock();
$doctrine
->expects($this->once())
->method('getManagerForClass')
->with($objectClass)
- ->willReturn($manager);
+ ->willReturn($manager)
+ ;
$registerListenersMock = $this->createRegisterListenersServiceMock();
$registerListenersMock
@@ -157,7 +178,7 @@ public function testShouldCallRegisterListenersService()
}
/**
- * @return RegisterListenersService|\PHPUnit_Framework_MockObject_MockObject
+ * @return RegisterListenersService|\PHPUnit\Framework\MockObject\MockObject
*/
private function createRegisterListenersServiceMock()
{
@@ -165,7 +186,7 @@ private function createRegisterListenersServiceMock()
}
/**
- * @return \PHPUnit_Framework_MockObject_MockObject|ManagerRegistry
+ * @return \PHPUnit\Framework\MockObject\MockObject|ManagerRegistry
*/
private function createDoctrineMock()
{
diff --git a/tests/Unit/Doctrine/PHPCR/ElasticaToModelTransformerTest.php b/tests/Unit/Doctrine/PHPCR/ElasticaToModelTransformerTest.php
index 24f280f27..f4684a7e9 100644
--- a/tests/Unit/Doctrine/PHPCR/ElasticaToModelTransformerTest.php
+++ b/tests/Unit/Doctrine/PHPCR/ElasticaToModelTransformerTest.php
@@ -37,7 +37,7 @@ class ElasticaToModelTransformerTest extends TestCase
protected $objectClass = 'stdClass';
- protected function setUp()
+ protected function setUp(): void
{
if (!class_exists(DocumentManager::class)) {
$this->markTestSkipped('Doctrine PHPCR is not present');
diff --git a/tests/Unit/Doctrine/PHPCR/ListenerTest.php b/tests/Unit/Doctrine/PHPCR/ListenerTest.php
index f920b404a..beeef979a 100644
--- a/tests/Unit/Doctrine/PHPCR/ListenerTest.php
+++ b/tests/Unit/Doctrine/PHPCR/ListenerTest.php
@@ -15,7 +15,7 @@
class ListenerTest extends BaseListenerTest
{
- protected function setUp()
+ protected function setUp(): void
{
if (!class_exists(\Doctrine\ODM\PHPCR\DocumentManager::class)) {
$this->markTestSkipped('Doctrine PHPCR is not present');
diff --git a/tests/Unit/Doctrine/PHPCRPagerProviderTest.php b/tests/Unit/Doctrine/PHPCRPagerProviderTest.php
index 46f39639a..0a39c40c4 100644
--- a/tests/Unit/Doctrine/PHPCRPagerProviderTest.php
+++ b/tests/Unit/Doctrine/PHPCRPagerProviderTest.php
@@ -1,5 +1,14 @@
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
namespace FOS\ElasticaBundle\Tests\Unit\Doctrine;
use Doctrine\ODM\PHPCR\DocumentManager;
@@ -12,14 +21,17 @@
use FOS\ElasticaBundle\Provider\PagerInterface;
use FOS\ElasticaBundle\Provider\PagerProviderInterface;
use FOS\ElasticaBundle\Tests\Unit\Mocks\DoctrinePHPCRCustomRepositoryMock;
-use Pagerfanta\Adapter\DoctrineODMPhpcrAdapter;
+use Pagerfanta\Doctrine\PHPCRODM\QueryAdapter;
use PHPUnit\Framework\TestCase;
+/**
+ * @internal
+ */
class PHPCRPagerProviderTest extends TestCase
{
- protected function setUp()
+ protected function setUp(): void
{
- if (!class_exists(DocumentManager::class)) {
+ if (!\class_exists(DocumentManager::class)) {
$this->markTestSkipped('Doctrine PHPCR is not present');
}
}
@@ -51,22 +63,24 @@ public function testShouldReturnPagerfanataPagerWithDoctrineODMMongoDBAdapter()
$repository
->expects($this->once())
->method('createQueryBuilder')
- ->willReturn($expectedBuilder);
+ ->willReturn($expectedBuilder)
+ ;
$manager = $this->createMock(DocumentManager::class);
$manager
->expects($this->once())
->method('getRepository')
->with($objectClass)
- ->willReturn($repository);
-
+ ->willReturn($repository)
+ ;
$doctrine = $this->createDoctrineMock();
$doctrine
->expects($this->once())
->method('getManagerForClass')
->with($objectClass)
- ->willReturn($manager);
+ ->willReturn($manager)
+ ;
$provider = new PHPCRPagerProvider($doctrine, $this->createRegisterListenersServiceMock(), $objectClass, $baseConfig);
@@ -75,9 +89,8 @@ public function testShouldReturnPagerfanataPagerWithDoctrineODMMongoDBAdapter()
$this->assertInstanceOf(PagerfantaPager::class, $pager);
$adapter = $pager->getPagerfanta()->getAdapter();
- $this->assertInstanceOf(DoctrineODMPhpcrAdapter::class, $adapter);
-
- $this->assertAttributeSame($expectedBuilder, 'queryBuilder', $adapter);
+ $this->assertInstanceOf(QueryAdapter::class, $adapter);
+ $this->assertSame($expectedBuilder, $adapter->getQueryBuilder());
}
public function testShouldAllowCallCustomRepositoryMethod()
@@ -89,20 +102,22 @@ public function testShouldAllowCallCustomRepositoryMethod()
$repository
->expects($this->once())
->method('createCustomQueryBuilder')
- ->willReturn($this->createMock(QueryBuilder::class));
+ ->willReturn($this->createMock(QueryBuilder::class))
+ ;
$manager = $this->createMock(DocumentManager::class);
$manager
->expects($this->once())
->method('getRepository')
- ->willReturn($repository);
-
+ ->willReturn($repository)
+ ;
$doctrine = $this->createDoctrineMock();
$doctrine
->expects($this->once())
->method('getManagerForClass')
- ->willReturn($manager);
+ ->willReturn($manager)
+ ;
$provider = new PHPCRPagerProvider($doctrine, $this->createRegisterListenersServiceMock(), $objectClass, $baseConfig);
@@ -122,20 +137,22 @@ public function testShouldCallRegisterListenersService()
$repository
->expects($this->once())
->method('createQueryBuilder')
- ->willReturn($queryBuilder);
+ ->willReturn($queryBuilder)
+ ;
$manager = $this->createMock(DocumentManager::class);
$manager
->expects($this->once())
->method('getRepository')
- ->willReturn($repository);
-
+ ->willReturn($repository)
+ ;
$doctrine = $this->createDoctrineMock();
$doctrine
->expects($this->once())
->method('getManagerForClass')
- ->willReturn($manager);
+ ->willReturn($manager)
+ ;
$registerListenersMock = $this->createRegisterListenersServiceMock();
$registerListenersMock
@@ -150,7 +167,7 @@ public function testShouldCallRegisterListenersService()
}
/**
- * @return \PHPUnit_Framework_MockObject_MockObject|ManagerRegistry
+ * @return \PHPUnit\Framework\MockObject\MockObject|ManagerRegistry
*/
private function createDoctrineMock()
{
@@ -158,7 +175,7 @@ private function createDoctrineMock()
}
/**
- * @return RegisterListenersService|\PHPUnit_Framework_MockObject_MockObject
+ * @return RegisterListenersService|\PHPUnit\Framework\MockObject\MockObject
*/
private function createRegisterListenersServiceMock()
{
diff --git a/tests/Unit/Doctrine/RegisterListenersServiceTest.php b/tests/Unit/Doctrine/RegisterListenersServiceTest.php
index 65a65e85e..b05f1e20d 100644
--- a/tests/Unit/Doctrine/RegisterListenersServiceTest.php
+++ b/tests/Unit/Doctrine/RegisterListenersServiceTest.php
@@ -173,14 +173,12 @@ public function testShouldNotCallSleepListenerForAnotherPagers()
public function testShouldRegisterDisableDebugLoggingByDefaultForEntityManager()
{
$dispatcher = $this->createDispatcherMock();
- $dispatcher
- ->expects($this->at(0))
- ->method('addListener')
- ->with(Events::PRE_FETCH_OBJECTS, $this->isInstanceOf(\Closure::class));
- $dispatcher
- ->expects($this->at(1))
+ $dispatcher->expects($this->exactly(2))
->method('addListener')
- ->with(Events::PRE_INSERT_OBJECTS, $this->isInstanceOf(\Closure::class));
+ ->withConsecutive(
+ [Events::PRE_FETCH_OBJECTS, $this->isInstanceOf(\Closure::class)],
+ [Events::PRE_INSERT_OBJECTS, $this->isInstanceOf(\Closure::class)]
+ );
$service = new RegisterListenersService($dispatcher);
@@ -234,50 +232,9 @@ public function testShouldNotRegisterDisableDebugLoggingIfOptionTrueForEntityMan
]);
}
- public function testShouldRegisterDisableDebugLoggingByDefaultForMongoDBDocumentManager()
+ public function testShouldIgnoreDebugLoggingOptionForMongoDBDocumentManager()
{
- if (!class_exists(\Doctrine\ODM\MongoDB\DocumentManager::class)) {
- $this->markTestSkipped('Doctrine MongoDB ODM is not available.');
- }
-
- $dispatcher = $this->createDispatcherMock();
- $dispatcher
- ->expects($this->at(0))
- ->method('addListener')
- ->with(Events::PRE_FETCH_OBJECTS, $this->isInstanceOf(\Closure::class));
- $dispatcher
- ->expects($this->at(1))
- ->method('addListener')
- ->with(Events::PRE_INSERT_OBJECTS, $this->isInstanceOf(\Closure::class));
-
- $service = new RegisterListenersService($dispatcher);
-
- $configuration = $this->createMock(\Doctrine\MongoDB\Configuration::class);
- $connection = $this->createMock(\Doctrine\MongoDB\Connection::class);
- $connection
- ->expects($this->once())
- ->method('getConfiguration')
- ->willReturn($configuration)
- ;
-
- $manager = $this->createMock(\Doctrine\ODM\MongoDB\DocumentManager::class);
- $manager
- ->expects($this->once())
- ->method('getConnection')
- ->willReturn($connection)
- ;
-
- $pager = $this->createPagerMock();
-
- $service->register($manager, $pager, [
- 'clear_object_manager' => false,
- 'sleep' => 0,
- ]);
- }
-
- public function testShouldNotRegisterDisableDebugLoggingIfOptionTrueForMongoDBDocumentManager()
- {
- if (!class_exists(\Doctrine\ODM\MongoDB\DocumentManager::class)) {
+ if (!\class_exists(\Doctrine\ODM\MongoDB\DocumentManager::class)) {
$this->markTestSkipped('Doctrine MongoDB ODM is not available.');
}
@@ -290,11 +247,6 @@ public function testShouldNotRegisterDisableDebugLoggingIfOptionTrueForMongoDBDo
$service = new RegisterListenersService($dispatcher);
$manager = $this->createMock(\Doctrine\ODM\MongoDB\DocumentManager::class);
- $manager
- ->expects($this->never())
- ->method('getConnection')
- ;
-
$pager = $this->createPagerMock();
@@ -307,7 +259,7 @@ public function testShouldNotRegisterDisableDebugLoggingIfOptionTrueForMongoDBDo
public function testShouldIgnoreDebugLoggingOptionForPHPCRManager()
{
- if (!class_exists(\Doctrine\ODM\PHPCR\DocumentManagerInterface::class)) {
+ if (!\interface_exists(\Doctrine\ODM\PHPCR\DocumentManagerInterface::class)) {
$this->markTestSkipped('Doctrine PHPCR is not present');
}
diff --git a/tests/Unit/Elastica/IndexTemplateTest.php b/tests/Unit/Elastica/IndexTemplateTest.php
index 907325a16..d74657337 100644
--- a/tests/Unit/Elastica/IndexTemplateTest.php
+++ b/tests/Unit/Elastica/IndexTemplateTest.php
@@ -6,12 +6,15 @@
use FOS\ElasticaBundle\Elastica\IndexTemplate;
use Elastica\IndexTemplate as BaseIndexTemplate;
use PHPUnit\Framework\TestCase;
+use Prophecy\PhpUnit\ProphecyTrait;
/**
* @author Dmitry Balabka
*/
class IndexTemplateTest extends TestCase
{
+ use ProphecyTrait;
+
public function testInstantiate()
{
$template = new IndexTemplate($this->prophesize(Client::class)->reveal(), 'some_name');
diff --git a/tests/Unit/Event/IndexEventTest.php b/tests/Unit/Event/IndexEventTest.php
index f22d4e9ed..49d9f70c0 100644
--- a/tests/Unit/Event/IndexEventTest.php
+++ b/tests/Unit/Event/IndexEventTest.php
@@ -21,7 +21,7 @@ class IndexEventTest extends TestCase
*/
private $event;
- protected function setUp()
+ protected function setUp(): void
{
$this->event = new IndexEvent('index');
}
diff --git a/tests/Unit/Event/IndexPopulateEventTest.php b/tests/Unit/Event/IndexPopulateEventTest.php
index c400800f4..b2b8f45d9 100644
--- a/tests/Unit/Event/IndexPopulateEventTest.php
+++ b/tests/Unit/Event/IndexPopulateEventTest.php
@@ -21,7 +21,7 @@ class IndexPopulateEventTest extends TestCase
*/
private $event;
- protected function setUp()
+ protected function setUp(): void
{
$this->event = new IndexPopulateEvent('index', false, []);
}
diff --git a/tests/Unit/Event/TransformEventTest.php b/tests/Unit/Event/TransformEventTest.php
index 5aae506c8..ce5c3b96b 100644
--- a/tests/Unit/Event/TransformEventTest.php
+++ b/tests/Unit/Event/TransformEventTest.php
@@ -22,7 +22,7 @@ class TransformEventTest extends TestCase
*/
private $event;
- protected function setUp()
+ protected function setUp(): void
{
$document = new Document();
$object = (object) [];
diff --git a/tests/Unit/Finder/TransformedFinderTest.php b/tests/Unit/Finder/TransformedFinderTest.php
index 15a1adc22..515965a69 100644
--- a/tests/Unit/Finder/TransformedFinderTest.php
+++ b/tests/Unit/Finder/TransformedFinderTest.php
@@ -62,7 +62,7 @@ public function testSearchMethodCreatesAQueryAndReturnsResultsFromSearchableDepe
$results = $method->invoke($finder, '', 10);
- $this->assertInternalType('array', $results);
+ $this->assertisArray($results);
}
public function testFindPaginatedReturnsAConfiguredPagerfantaObject()
diff --git a/tests/Unit/Index/AliasProcessorTest.php b/tests/Unit/Index/AliasProcessorTest.php
index 34a6ea939..fb0f0fd14 100644
--- a/tests/Unit/Index/AliasProcessorTest.php
+++ b/tests/Unit/Index/AliasProcessorTest.php
@@ -36,7 +36,7 @@ class AliasProcessorTest extends TestCase
*/
private $processor;
- protected function setUp()
+ protected function setUp(): void
{
$this->processor = new AliasProcessor();
}
@@ -62,17 +62,18 @@ public function testSetRootName($name, $configArray, $resultStartsWith)
public function testSwitchAliasNoAliasSet()
{
$indexConfig = new IndexConfig('name', [], []);
- list($index, $client) = $this->getMockedIndex('unique_name');
+ [$index, $client] = $this->getMockedIndex('unique_name');
- $client->expects($this->at(0))
- ->method('request')
- ->with('_aliases', 'GET')
- ->willReturn(new Response([]));
- $client->expects($this->at(1))
+ $client->expects($this->exactly(2))
->method('request')
- ->with('_aliases', 'POST', ['actions' => [
- ['add' => ['index' => 'unique_name', 'alias' => 'name']],
- ]]);
+ ->withConsecutive(
+ ['_aliases', 'GET'],
+ ['_aliases', 'POST', ['actions' => [
+ ['add' => ['index' => 'unique_name', 'alias' => 'name']],
+ ]]]
+ )
+ ->willReturn(new Response([]))
+ ;
$this->processor->switchIndexAlias($indexConfig, $index, false);
}
@@ -82,55 +83,51 @@ public function testSwitchAliasExistingAliasSet()
$indexConfig = new IndexConfig('name', [], []);
list($index, $client) = $this->getMockedIndex('unique_name');
- $client->expects($this->at(0))
- ->method('request')
- ->with('_aliases', 'GET')
- ->willReturn(new Response([
- 'old_unique_name' => ['aliases' => ['name']],
- ]));
- $client->expects($this->at(1))
+ $client->expects($this->exactly(2))
->method('request')
- ->with('_aliases', 'POST', ['actions' => [
- ['remove' => ['index' => 'old_unique_name', 'alias' => 'name']],
- ['add' => ['index' => 'unique_name', 'alias' => 'name']],
- ]]);
+ ->withConsecutive(
+ ['_aliases', 'GET'],
+ ['_aliases', 'POST', ['actions' => [
+ ['add' => ['index' => 'unique_name', 'alias' => 'name']],
+ ]]]
+ )
+ ->willReturn(new Response([]))
+ ;
$this->processor->switchIndexAlias($indexConfig, $index, false);
}
- /**
- * @expectedException \RuntimeException
- */
public function testSwitchAliasThrowsWhenMoreThanOneExists()
{
+ $this->expectException(\RuntimeException::class);
$indexConfig = new IndexConfig('name', [], []);
list($index, $client) = $this->getMockedIndex('unique_name');
- $client->expects($this->at(0))
+ $client->expects($this->once())
->method('request')
->with('_aliases', 'GET')
->willReturn(new Response([
- 'old_unique_name' => ['aliases' => ['name']],
- 'another_old_unique_name' => ['aliases' => ['name']],
- ]));
+ 'old_unique_name' => ['aliases' => ['name' => []]],
+ 'another_old_unique_name' => ['aliases' => ['name' => []]],
+ ]))
+ ;
$this->processor->switchIndexAlias($indexConfig, $index, false);
}
- /**
- * @expectedException \FOS\ElasticaBundle\Exception\AliasIsIndexException
- */
public function testSwitchAliasThrowsWhenAliasIsAnIndex()
{
+ $this->expectException(\FOS\ElasticaBundle\Exception\AliasIsIndexException::class);
$indexConfig = new IndexConfig('name', [], []);
list($index, $client) = $this->getMockedIndex('unique_name');
- $client->expects($this->at(0))
+ $client->expects($this->once())
->method('request')
->with('_aliases', 'GET')
->willReturn(new Response([
'name' => [],
- ]));
+ ]))
+ ;
$this->processor->switchIndexAlias($indexConfig, $index, false);
}
@@ -140,15 +137,21 @@ public function testSwitchAliasDeletesIndexCollisionIfForced()
$indexConfig = new IndexConfig('name', [], []);
list($index, $client) = $this->getMockedIndex('unique_name');
- $client->expects($this->at(0))
+ $client->expects($this->exactly(3))
->method('request')
- ->with('_aliases', 'GET')
- ->willReturn(new Response([
- 'name' => [],
- ]));
- $client->expects($this->at(1))
- ->method('request')
- ->with('name', 'DELETE');
+ ->withConsecutive(
+ ['_aliases', 'GET'],
+ ['name', 'DELETE'],
+ ['_aliases', 'POST', ['actions' => [
+ ['add' => ['index' => 'unique_name', 'alias' => 'name']],
+ ]]]
+ )
+ ->willReturnOnConsecutiveCalls(
+ new Response(['name' => []]),
+ new Response([]),
+ new Response([])
+ )
+ ;
$this->processor->switchIndexAlias($indexConfig, $index, true);
}
@@ -158,21 +161,22 @@ public function testSwitchAliasDeletesOldIndex()
$indexConfig = new IndexConfig('name', [], []);
list($index, $client) = $this->getMockedIndex('unique_name');
- $client->expects($this->at(0))
- ->method('request')
- ->with('_aliases', 'GET')
- ->willReturn(new Response([
- 'old_unique_name' => ['aliases' => ['name']],
- ]));
- $client->expects($this->at(1))
+ $client->expects($this->exactly(3))
->method('request')
- ->with('_aliases', 'POST', ['actions' => [
- ['remove' => ['index' => 'old_unique_name', 'alias' => 'name']],
- ['add' => ['index' => 'unique_name', 'alias' => 'name']],
- ]]);
- $client->expects($this->at(2))
- ->method('request')
- ->with('old_unique_name', 'DELETE');
+ ->withConsecutive(
+ ['_aliases', 'GET'],
+ ['_aliases', 'POST', ['actions' => [
+ ['remove' => ['index' => 'old_unique_name', 'alias' => 'name']],
+ ['add' => ['index' => 'unique_name', 'alias' => 'name']],
+ ]]],
+ ['old_unique_name', 'DELETE']
+ )
+ ->willReturnOnConsecutiveCalls(
+ new Response(['old_unique_name' => ['aliases' => ['name' => []]]]),
+ new Response([]),
+ new Response([])
+ )
+ ;
$this->processor->switchIndexAlias($indexConfig, $index, true);
}
@@ -182,22 +186,22 @@ public function testSwitchAliasCleansUpOnRenameFailure()
$indexConfig = new IndexConfig('name', [], []);
list($index, $client) = $this->getMockedIndex('unique_name');
- $client->expects($this->at(0))
- ->method('request')
- ->with('_aliases', 'GET')
- ->willReturn(new Response([
- 'old_unique_name' => ['aliases' => ['name']],
- ]));
- $client->expects($this->at(1))
- ->method('request')
- ->with('_aliases', 'POST', ['actions' => [
- ['remove' => ['index' => 'old_unique_name', 'alias' => 'name']],
- ['add' => ['index' => 'unique_name', 'alias' => 'name']],
- ]])
- ->will($this->throwException(new ResponseException(new Request(''), new Response(''))));
- $client->expects($this->at(2))
+ $client->expects($this->exactly(3))
->method('request')
- ->with('unique_name', 'DELETE');
+ ->withConsecutive(
+ ['_aliases', 'GET'],
+ ['_aliases', 'POST', ['actions' => [
+ ['remove' => ['index' => 'old_unique_name', 'alias' => 'name']],
+ ['add' => ['index' => 'unique_name', 'alias' => 'name']],
+ ]]],
+ ['unique_name', 'DELETE']
+ )
+ ->willReturnOnConsecutiveCalls(
+ new Response(['old_unique_name' => ['aliases' => ['name' => []]]]),
+ $this->throwException(new ResponseException(new Request(''), new Response(''))),
+ new Response([])
+ )
+ ;
// Not an annotation: we do not want a RuntimeException until now.
$this->expectException(\RuntimeException::class);
diff --git a/tests/Unit/Index/IndexManagerTest.php b/tests/Unit/Index/IndexManagerTest.php
index 452d3f284..55af93af0 100644
--- a/tests/Unit/Index/IndexManagerTest.php
+++ b/tests/Unit/Index/IndexManagerTest.php
@@ -24,7 +24,7 @@ class IndexManagerTest extends TestCase
*/
private $indexManager;
- protected function setUp()
+ protected function setUp(): void
{
foreach (['index1', 'index2', 'index3'] as $indexName) {
$index = $this->createMock(Index::class);
@@ -51,11 +51,9 @@ public function testGetIndex()
$this->assertSame($this->indexes['index3'], $this->indexManager->getIndex('index3'));
}
- /**
- * @expectedException \InvalidArgumentException
- */
public function testGetIndexShouldThrowExceptionForInvalidName()
{
+ $this->expectException(\InvalidArgumentException::class);
$this->indexManager->getIndex('index4');
}
diff --git a/tests/Unit/Index/MappingBuilderTest.php b/tests/Unit/Index/MappingBuilderTest.php
index 8faf9ff7a..fba95b7a8 100644
--- a/tests/Unit/Index/MappingBuilderTest.php
+++ b/tests/Unit/Index/MappingBuilderTest.php
@@ -33,7 +33,7 @@ class MappingBuilderTest extends TestCase
*/
private $typeMapping;
- protected function setUp()
+ protected function setUp(): void
{
$this->typeMapping = [
'properties' => [
@@ -49,9 +49,6 @@ protected function setUp()
'store' => false,
],
],
- '_parent' => [
- 'type' => 'parent_type',
- ],
];
$this->typeConfig = new TypeConfig('typename', [
'properties' => [
@@ -67,11 +64,6 @@ protected function setUp()
'store' => false,
],
],
- '_parent' => [
- 'type' => 'parent_type',
- 'identifier' => 'name',
- 'property' => 'parent_property',
- ],
]);
$this->builder = new MappingBuilder();
}
@@ -86,9 +78,7 @@ public function testMappingBuilderStoreProperty()
$this->assertArrayHasKey('store', $mapping['properties']['unstored']);
$this->assertFalse($mapping['properties']['unstored']['store']);
- $this->assertArrayHasKey('_parent', $mapping);
- $this->assertArrayNotHasKey('identifier', $mapping['_parent']);
- $this->assertArrayNotHasKey('property', $mapping['_parent']);
+ $this->assertArrayNotHasKey('_parent', $mapping);
}
public function testBuildIndexTemplateMapping()
diff --git a/tests/Unit/Index/ResetterTest.php b/tests/Unit/Index/ResetterTest.php
index 0b03f889f..82c23722d 100644
--- a/tests/Unit/Index/ResetterTest.php
+++ b/tests/Unit/Index/ResetterTest.php
@@ -41,7 +41,7 @@ class ResetterTest extends TestCase
private $indexManager;
private $mappingBuilder;
- protected function setUp()
+ protected function setUp(): void
{
$this->aliasProcessor = $this->createMock(AliasProcessor::class);
$this->configManager = $this->createMock(ConfigManager::class);
@@ -141,11 +141,9 @@ public function testResetIndexWithDifferentNameAndAlias()
$this->resetter->resetIndex('index1');
}
- /**
- * @expectedException \InvalidArgumentException
- */
public function testFailureWhenMissingIndexDoesntDispatch()
{
+ $this->expectException(\InvalidArgumentException::class);
$this->configManager->expects($this->once())
->method('getIndexConfiguration')
->with('nonExistant')
@@ -198,11 +196,9 @@ public function testResetTypeWithChangedSettings()
$this->resetter->resetIndexType('index', 'type');
}
- /**
- * @expectedException \InvalidArgumentException
- */
public function testNonExistantResetType()
{
+ $this->expectException(\InvalidArgumentException::class);
$this->configManager->expects($this->once())
->method('getTypeConfiguration')
->with('index', 'nonExistant')
diff --git a/tests/Unit/Index/TemplateResetterTest.php b/tests/Unit/Index/TemplateResetterTest.php
index 3a02b968a..cb3c934e2 100644
--- a/tests/Unit/Index/TemplateResetterTest.php
+++ b/tests/Unit/Index/TemplateResetterTest.php
@@ -13,12 +13,15 @@
use FOS\ElasticaBundle\Index\TemplateResetter;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
+use Prophecy\PhpUnit\ProphecyTrait;
/**
* @author Dmitry Balabka
*/
class TemplateResetterTest extends TestCase
{
+ use ProphecyTrait;
+
/**
* @var ManagerInterface
*/
@@ -44,7 +47,7 @@ class TemplateResetterTest extends TestCase
*/
private $resetter;
- protected function setUp()
+ protected function setUp(): void
{
$this->configManager = $this->prophesize(ManagerInterface::class);
$this->mappingBuilder = $this->prophesize(MappingBuilder::class);
diff --git a/tests/Unit/Manager/RepositoryManagerTest.php b/tests/Unit/Manager/RepositoryManagerTest.php
index 535433ea9..300445e55 100644
--- a/tests/Unit/Manager/RepositoryManagerTest.php
+++ b/tests/Unit/Manager/RepositoryManagerTest.php
@@ -53,11 +53,9 @@ public function testThatGetRepositoryReturnsCustomRepository()
$this->assertInstanceOf(CustomRepository::class, $repository);
}
- /**
- * @expectedException \RuntimeException
- */
public function testThatGetRepositoryThrowsExceptionIfEntityNotConfigured()
{
+ $this->expectException(\RuntimeException::class);
$finderMock = $this->createMock(TransformedFinder::class);
$typeName = 'index/type';
@@ -67,11 +65,9 @@ public function testThatGetRepositoryThrowsExceptionIfEntityNotConfigured()
$manager->getRepository('Missing type');
}
- /**
- * @expectedException \RuntimeException
- */
public function testThatGetRepositoryThrowsExceptionIfCustomRepositoryNotFound()
{
+ $this->expectException(\RuntimeException::class);
$finderMock = $this->createMock(TransformedFinder::class);
$typeName = 'index/type';
diff --git a/tests/Unit/Mocks/DoctrineMongoDBCustomRepositoryMock.php b/tests/Unit/Mocks/DoctrineMongoDBCustomRepositoryMock.php
index b1186db5c..93205eb18 100644
--- a/tests/Unit/Mocks/DoctrineMongoDBCustomRepositoryMock.php
+++ b/tests/Unit/Mocks/DoctrineMongoDBCustomRepositoryMock.php
@@ -1,9 +1,21 @@
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
namespace FOS\ElasticaBundle\Tests\Unit\Mocks;
-use Doctrine\ODM\MongoDB\DocumentRepository;
+use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
class DoctrineMongoDBCustomRepositoryMock extends DocumentRepository
{
- public function createCustomQueryBuilder() {}
+ public function createCustomQueryBuilder()
+ {
+ }
}
diff --git a/tests/Unit/Persister/InPlacePagerPersisterTest.php b/tests/Unit/Persister/InPlacePagerPersisterTest.php
index 6927f441f..247ac5f95 100644
--- a/tests/Unit/Persister/InPlacePagerPersisterTest.php
+++ b/tests/Unit/Persister/InPlacePagerPersisterTest.php
@@ -211,7 +211,7 @@ public function testShouldCallObjectPersisterInsertManyMethodForEachPage()
$objectPersisterMock
->expects($this->exactly(3))
->method('insertMany')
- ->withConsecutive($this->identicalTo([$firstPage]), $this->identicalTo([$secondPage]), $this->identicalTo([$thirdPage]))
+ ->withConsecutive([$this->identicalTo($firstPage)], [$this->identicalTo($secondPage)], [$this->identicalTo($thirdPage)])
;
$registryMock = $this->createPersisterRegistryStub($objectPersisterMock);
@@ -243,7 +243,7 @@ public function testShouldCallObjectPersisterInsertManyMethodOnlyForSecondPage()
$objectPersisterMock
->expects($this->once())
->method('insertMany')
- ->withConsecutive($this->identicalTo([$secondPage]))
+ ->with($this->identicalTo($secondPage))
;
$registryMock = $this->createPersisterRegistryStub($objectPersisterMock);
@@ -405,4 +405,4 @@ private function createPersisterRegistryStub($objectPersister = null)
return $registryMock;
}
-}
\ No newline at end of file
+}
diff --git a/tests/Unit/Persister/ObjectPersisterTest.php b/tests/Unit/Persister/ObjectPersisterTest.php
index 2b232a393..d921a8e83 100644
--- a/tests/Unit/Persister/ObjectPersisterTest.php
+++ b/tests/Unit/Persister/ObjectPersisterTest.php
@@ -42,11 +42,9 @@ public function testThatCanReplaceObject()
$objectPersister->replaceOne(new POPO());
}
- /**
- * @expectedException \BadMethodCallException
- */
public function testThatErrorIsHandledWhenCannotReplaceObject()
{
+ $this->expectException(\BadMethodCallException::class);
$transformer = $this->getTransformer();
$typeMock = $this->createMock(Type::class);
@@ -77,11 +75,9 @@ public function testThatCanInsertObject()
$objectPersister->insertOne(new POPO());
}
- /**
- * @expectedException \BadMethodCallException
- */
public function testThatErrorIsHandledWhenCannotInsertObject()
{
+ $this->expectException(\BadMethodCallException::class);
$transformer = $this->getTransformer();
$typeMock = $this->createMock(Type::class);
@@ -112,11 +108,9 @@ public function testThatCanDeleteObject()
$objectPersister->deleteOne(new POPO());
}
- /**
- * @expectedException \BadMethodCallException
- */
public function testThatErrorIsHandledWhenCannotDeleteObject()
{
+ $this->expectException(\BadMethodCallException::class);
$transformer = $this->getTransformer();
$typeMock = $this->createMock(Type::class);
@@ -149,11 +143,9 @@ public function testThatCanInsertManyObjects()
$objectPersister->insertMany([new POPO(), new POPO()]);
}
- /**
- * @expectedException \BadMethodCallException
- */
public function testThatErrorIsHandledWhenCannotInsertManyObject()
{
+ $this->expectException(\BadMethodCallException::class);
$transformer = $this->getTransformer();
$typeMock = $this->createMock(Type::class);
diff --git a/tests/Unit/Provider/IndexableTest.php b/tests/Unit/Provider/IndexableTest.php
index 99f241936..13ddb5e2e 100644
--- a/tests/Unit/Provider/IndexableTest.php
+++ b/tests/Unit/Provider/IndexableTest.php
@@ -39,10 +39,11 @@ public function testValidIndexableCallbacks($callback, $return)
/**
* @dataProvider provideInvalidIsIndexableCallbacks
- * @expectedException \InvalidArgumentException
+ *
*/
public function testInvalidIsIndexableCallbacks($callback)
{
+ $this->expectException(\InvalidArgumentException::class);
$indexable = new Indexable([
'index/type' => $callback,
]);
diff --git a/tests/Unit/Subscriber/PaginateElasticaQuerySubscriberTest.php b/tests/Unit/Subscriber/PaginateElasticaQuerySubscriberTest.php
index 1d66b7766..b51e20099 100644
--- a/tests/Unit/Subscriber/PaginateElasticaQuerySubscriberTest.php
+++ b/tests/Unit/Subscriber/PaginateElasticaQuerySubscriberTest.php
@@ -3,7 +3,7 @@
/*
* This file is part of the FOSElasticaBundle package.
*
- * (c) FriendsOfSymfony
+ * (c) FriendsOfSymfony
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -20,6 +20,9 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
+/**
+ * @internal
+ */
class PaginateElasticaQuerySubscriberTest extends TestCase
{
public function testShouldDoNothingIfSortParamIsEmpty()
@@ -28,9 +31,11 @@ public function testShouldDoNothingIfSortParamIsEmpty()
$adapter = $this->getAdapterMock();
$adapter->expects($this->never())
- ->method('getQuery');
+ ->method('getQuery')
+ ;
$adapter->method('getResults')
- ->willReturn($this->getResultSetMock());
+ ->willReturn($this->getResultSetMock())
+ ;
$event = new ItemsEvent(0, 10);
$event->target = $adapter;
@@ -76,10 +81,12 @@ public function testShouldSort(array $expected, Request $request)
$query = new Query();
$adapter = $this->getAdapterMock();
$adapter->method('getQuery')
- ->willReturn($query);
+ ->willReturn($query)
+ ;
$adapter->method('getResults')
- ->willReturn($this->getResultSetMock());
+ ->willReturn($this->getResultSetMock())
+ ;
$event = new ItemsEvent(0, 10);
$event->target = $adapter;
@@ -94,9 +101,6 @@ public function testShouldSort(array $expected, Request $request)
$this->assertSame($expected, $query->getParam('sort'));
}
- /**
- * @expectedException \UnexpectedValueException
- */
public function testShouldThrowIfFieldIsNotWhitelisted()
{
$subscriber = new PaginateElasticaQuerySubscriber($this->getRequestStack(new Request(['ord' => 'owner'])));
@@ -104,10 +108,12 @@ public function testShouldThrowIfFieldIsNotWhitelisted()
$query = new Query();
$adapter = $this->getAdapterMock();
$adapter->method('getQuery')
- ->willReturn($query);
+ ->willReturn($query)
+ ;
$adapter->method('getResults')
- ->willReturn($this->getResultSetMock());
+ ->willReturn($this->getResultSetMock())
+ ;
$event = new ItemsEvent(0, 10);
$event->target = $adapter;
@@ -115,9 +121,10 @@ public function testShouldThrowIfFieldIsNotWhitelisted()
'defaultSortFieldName' => 'createdAt',
'sortFieldParameterName' => 'ord',
'sortDirectionParameterName' => 'az',
- 'sortFieldWhitelist' => ['createdAt', 'updatedAt'],
+ 'sortFieldAllowList' => ['createdAt', 'updatedAt'],
];
+ $this->expectException(\UnexpectedValueException::class);
$subscriber->items($event);
}
@@ -128,10 +135,12 @@ public function testShouldAddNestedPath()
$query = new Query();
$adapter = $this->getAdapterMock();
$adapter->method('getQuery')
- ->willReturn($query);
+ ->willReturn($query)
+ ;
$adapter->method('getResults')
- ->willReturn($this->getResultSetMock());
+ ->willReturn($this->getResultSetMock())
+ ;
$event = new ItemsEvent(0, 10);
$event->target = $adapter;
@@ -158,10 +167,12 @@ public function testShouldInvokeCallableNestedPath()
$query = new Query();
$adapter = $this->getAdapterMock();
$adapter->method('getQuery')
- ->willReturn($query);
+ ->willReturn($query)
+ ;
$adapter->method('getResults')
- ->willReturn($this->getResultSetMock());
+ ->willReturn($this->getResultSetMock())
+ ;
$event = new ItemsEvent(0, 10);
$event->target = $adapter;
@@ -192,10 +203,12 @@ public function testShouldAddNestedFilter()
$query = new Query();
$adapter = $this->getAdapterMock();
$adapter->method('getQuery')
- ->willReturn($query);
+ ->willReturn($query)
+ ;
$adapter->method('getResults')
- ->willReturn($this->getResultSetMock());
+ ->willReturn($this->getResultSetMock())
+ ;
$event = new ItemsEvent(0, 10);
$event->target = $adapter;
@@ -233,10 +246,12 @@ public function testShouldInvokeNestedFilterCallable()
$query = new Query();
$adapter = $this->getAdapterMock();
$adapter->method('getQuery')
- ->willReturn($query);
+ ->willReturn($query)
+ ;
$adapter->method('getResults')
- ->willReturn($this->getResultSetMock());
+ ->willReturn($this->getResultSetMock())
+ ;
$event = new ItemsEvent(0, 10);
$event->target = $adapter;
@@ -277,9 +292,11 @@ public function testShouldDoNothingIfNoRequest()
$adapter = $this->getAdapterMock();
$adapter->expects($this->never())
- ->method('getQuery');
+ ->method('getQuery')
+ ;
$adapter->method('getResults')
- ->willReturn($this->getResultSetMock());
+ ->willReturn($this->getResultSetMock())
+ ;
$event = new ItemsEvent(0, 10);
$event->target = $adapter;
@@ -297,7 +314,7 @@ protected function getResultSetMock()
return $this->createMock(PartialResultsInterface::class);
}
- private function getRequestStack(Request $request = null)
+ private function getRequestStack(?Request $request = null)
{
$stack = new RequestStack();
diff --git a/tests/Unit/Transformer/ElasticaToModelTransformerCollectionTest.php b/tests/Unit/Transformer/ElasticaToModelTransformerCollectionTest.php
index 3ce7d3588..3c4c1554d 100644
--- a/tests/Unit/Transformer/ElasticaToModelTransformerCollectionTest.php
+++ b/tests/Unit/Transformer/ElasticaToModelTransformerCollectionTest.php
@@ -116,12 +116,12 @@ public function testGetIdentifierFieldReturnsAMapOfIdentifiers()
{
$collection = new ElasticaToModelTransformerCollection([]);
$identifiers = $collection->getIdentifierField();
- $this->assertInternalType('array', $identifiers);
+ $this->assertisArray($identifiers);
$this->assertEmpty($identifiers);
$this->collectionSetup();
$identifiers = $this->collection->getIdentifierField();
- $this->assertInternalType('array', $identifiers);
+ $this->assertisArray($identifiers);
$this->assertSame(['type1' => 'id', 'type2' => 'id'], $identifiers);
}
@@ -154,7 +154,7 @@ public function testHybridTransformDecoratesResultsWithHybridResultObjects($resu
$hybridResults = $collection->hybridTransform([$result]);
- $this->assertInternalType('array', $hybridResults);
+ $this->assertisArray($hybridResults);
$this->assertNotEmpty($hybridResults);
$this->assertContainsOnlyInstancesOf(HybridResult::class, $hybridResults);
diff --git a/tests/Unit/Transformer/ModelToElasticaAutoTransformerTest.php b/tests/Unit/Transformer/ModelToElasticaAutoTransformerTest.php
index d8058dc29..b9fe6946c 100644
--- a/tests/Unit/Transformer/ModelToElasticaAutoTransformerTest.php
+++ b/tests/Unit/Transformer/ModelToElasticaAutoTransformerTest.php
@@ -289,11 +289,9 @@ public function testThatNullValuesAreNotFilteredOut()
$this->assertTrue(array_key_exists('nullValue', $data));
}
- /**
- * @expectedException \Symfony\Component\PropertyAccess\Exception\RuntimeException
- */
public function testThatCannotTransformObjectWhenGetterDoesNotExistForPrivateMethod()
{
+ $this->expectException(\Symfony\Component\PropertyAccess\Exception\RuntimeException::class);
$transformer = $this->getTransformer();
$transformer->transform(new POPO3(), ['desc' => []]);
}
@@ -330,7 +328,7 @@ public function testNestedMapping()
$data = $document->getData();
$this->assertTrue(array_key_exists('sub', $data));
- $this->assertInternalType('array', $data['sub']);
+ $this->assertisArray($data['sub']);
$this->assertSame([
['foo' => 'foo'],
['foo' => 'bar'],
@@ -349,7 +347,7 @@ public function tesObjectMapping()
$data = $document->getData();
$this->assertTrue(array_key_exists('sub', $data));
- $this->assertInternalType('array', $data['sub']);
+ $this->assertisArray($data['sub']);
$this->assertSame([
['bar' => 'foo'],
['bar' => 'bar'],
@@ -367,7 +365,7 @@ public function testObjectDoesNotRequireProperties()
$data = $document->getData();
$this->assertTrue(array_key_exists('obj', $data));
- $this->assertInternalType('array', $data['obj']);
+ $this->assertisArray($data['obj']);
$this->assertSame([
'foo' => 'foo',
'bar' => 'foo',
@@ -401,8 +399,8 @@ public function testObjectsMappingOfAtLeastOneAutoMappedObjectAndAtLeastOneManua
$this->assertTrue(array_key_exists('obj', $data));
$this->assertTrue(array_key_exists('nestedObject', $data));
- $this->assertInternalType('array', $data['obj']);
- $this->assertInternalType('array', $data['nestedObject']);
+ $this->assertisArray($data['obj']);
+ $this->assertisArray($data['nestedObject']);
$this->assertSame(
[
'foo' => 'foo',
@@ -475,7 +473,7 @@ public function testThatMappedObjectsDontNeedAnIdentifierField()
$data = $document->getData();
$this->assertTrue(array_key_exists('objWithoutIdentifier', $data));
- $this->assertInternalType('array', $data['objWithoutIdentifier']);
+ $this->assertisArray($data['objWithoutIdentifier']);
$this->assertSame([
'foo' => 'foo',
'bar' => 'foo',
@@ -497,7 +495,7 @@ public function testThatNestedObjectsDontNeedAnIdentifierField()
$data = $document->getData();
$this->assertTrue(array_key_exists('subWithoutIdentifier', $data));
- $this->assertInternalType('array', $data['subWithoutIdentifier']);
+ $this->assertisArray($data['subWithoutIdentifier']);
$this->assertSame([
['foo' => 'foo', 'bar' => 'foo'],
['foo' => 'bar', 'bar' => 'bar'],
@@ -532,7 +530,7 @@ public function testNestedTransformReturnsAnEmptyArrayForNullValues()
]);
$data = $document->getData();
- $this->assertInternalType('array', $data['nullValue']);
+ $this->assertisArray($data['nullValue']);
$this->assertEmpty($data['nullValue']);
}