diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..a441c78 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,14 @@ +on: [push, pull_request] +name: Lint +jobs: + doctor-rst: + name: DOCtor-RST + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: DOCtor-RST + uses: docker://oskarstark/doctor-rst + with: + args: --short + env: + DOCS_DIR: 'docs/' diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000..a2d1e3b --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,30 @@ +# https://github.com/actions/stale + +name: "Stale" + +on: + schedule: + - cron: "0 9-18 * * *" + +jobs: + stale: + runs-on: "ubuntu-latest" + + steps: + - name: "Close stale issues and pull requests" + uses: "actions/stale@v1.1.0" + with: + days-before-close: 7 + days-before-stale: 180 + repo-token: "${{ secrets.GITHUB_TOKEN }}" + exempt-issue-label: "keep" + stale-issue-label: "stale" + stale-issue-message: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. + stale-pr-label: "stale" + stale-pr-message: > + This PR has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. diff --git a/.travis.yml b/.travis.yml index e32d24f..c78a443 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ env: - SYMFONY_DEPRECATIONS_HELPER=max[self]=0 - TARGET=test - UPSTREAM_URL=https://github.com/sonata-project/SonataAdminSearchBundle.git - - PHPUNIT_VERSION=7 + - PHPUNIT_VERSION=8 matrix: fast_finish: true @@ -45,9 +45,9 @@ matrix: - php: '7.2' env: COMPOSER_FLAGS="--prefer-lowest" - php: '7.3' - env: SYMFONY=3.4.* + env: SYMFONY=4.4.* - php: '7.3' - env: SYMFONY='dev-master as 3.4.x-dev' + env: SYMFONY='dev-master as 4.4.x-dev' - php: '7.3' env: SONATA_ADMIN=3.* - php: '7.3' @@ -62,7 +62,7 @@ matrix: - php: 7.4snapshot - php: nightly - env: SYMFONY_DEPRECATIONS_HELPER=0 - - env: SYMFONY='dev-master as 3.4.x-dev' + - env: SYMFONY='dev-master as 4.4.x-dev' - env: SONATA_ADMIN='dev-master as 3.x-dev' - env: RUFLIN_ELASTICA='dev-master as 2.x-dev' diff --git a/composer.json b/composer.json index 245b9fc..397bf8a 100644 --- a/composer.json +++ b/composer.json @@ -33,8 +33,8 @@ }, "require-dev": { "matthiasnoback/symfony-config-test": "^4.0", - "matthiasnoback/symfony-dependency-injection-test": "^3.1", - "symfony/phpunit-bridge": "^4.2" + "matthiasnoback/symfony-dependency-injection-test": "^4.1", + "symfony/phpunit-bridge": "^5.0" }, "config": { "sort-packages": true diff --git a/docs/.doctor-rst.yaml b/docs/.doctor-rst.yaml new file mode 100644 index 0000000..1cbf665 --- /dev/null +++ b/docs/.doctor-rst.yaml @@ -0,0 +1,32 @@ +rules: + blank_line_after_directive: ~ + short_array_syntax: ~ + typo: ~ + replacement: ~ + composer_dev_option_at_the_end: ~ + yarn_dev_option_at_the_end: ~ + versionadded_directive_should_have_version: ~ + no_composer_req: ~ + no_php_open_tag_in_code_block_php_directive: ~ + blank_line_after_filepath_in_code_block: ~ + no_php_prefix_before_bin_console: ~ + use_deprecated_directive_instead_of_versionadded: ~ + no_space_before_self_xml_closing_tag: ~ + no_explicit_use_of_code_block_php: ~ + ensure_order_of_code_blocks_in_configuration_block: ~ + american_english: ~ + valid_use_statements: ~ + yaml_instead_of_yml_suffix: ~ + extend_abstract_admin: ~ + final_admin_class: ~ + final_admin_extension_classes: ~ + no_admin_yaml: ~ + no_bash_prompt: ~ + no_composer_phar: ~ + no_inheritdoc: ~ + + # can be enabled when no Symfony 3.4 support anymore + #no_app_bundle: ~ + #no_config_yaml: ~ + #kernel_instead_of_app_kernel: ~ + #no_app_console: ~ diff --git a/docs/reference/createquery.rst b/docs/reference/createquery.rst index 927e2c2..01a2440 100644 --- a/docs/reference/createquery.rst +++ b/docs/reference/createquery.rst @@ -1,12 +1,7 @@ Customizing the query used to generate the list =============================================== - -You can customize the list query thanks to the ``createQuery`` method. - -.. code-block:: php - - add('title') - ->add('name', Sonata\AdminSearchBundle\Filter\CallbackFilter::class, array( + ->add('name', Sonata\AdminSearchBundle\Filter\CallbackFilter::class, [ 'callback' => function (ElasticaProxyQuery $query, $alias, $field, $data) { if (!$data || !is_array($data) || !array_key_exists('value', $data)) { return; @@ -54,29 +51,28 @@ modified according to your needs. $query->addMust($queryBuilder); } - )) + ]) ; } } - Date ^^^^ -To make query on date/datetime type, you can use one of the `sonata_search_elastica_date` filter types. -For example if you have a date in the ISO 8601 date format : +To make query on date/datetime type, you can use one of the `sonata_search_elastica_date` +filter types. For example if you have a date in the ISO 8601 date format:: -.. code-block:: php - protected function configureDatagridFilters(DatagridMapper $datagridMapper) { $datagridMapper - ->add('date', Sonata\AdminSearchBundle\Filter\DateTimeFilter::class, null, 'datetime', array( - 'format' => 'c' - )) + ->add('date', Sonata\AdminSearchBundle\Filter\DateTimeFilter::class, null, 'datetime', [ + 'format' => 'c', + ]) ; } -The format must be a string formatted according to the `php format date`_ and be the one used to map the data in elasticsearch. If it is not the same, ElasticSearch will raise an exception ``failed to parse date field [15/05/28] Invalid format`` +The format must be a string formatted according to the `php format date`_ and be the one used +to map the data in elasticsearch. If it is not the same, ElasticSearch will raise an exception +``failed to parse date field [15/05/28] Invalid format``. .. _php format date: http://php.net/manual/en/function.date.php diff --git a/tests/DependencyInjection/Compiler/DatagridBuilderInjectionCompilerPassTest.php b/tests/DependencyInjection/Compiler/DatagridBuilderInjectionCompilerPassTest.php index 9fe9b19..2ccfdc3 100644 --- a/tests/DependencyInjection/Compiler/DatagridBuilderInjectionCompilerPassTest.php +++ b/tests/DependencyInjection/Compiler/DatagridBuilderInjectionCompilerPassTest.php @@ -14,6 +14,7 @@ namespace Sonata\AdminSearchBundle\Tests\DependencyInjection\Compiler; use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; +use Sonata\AdminSearchBundle\Builder\DatagridBuilder; use Sonata\AdminSearchBundle\DependencyInjection\Compiler\DatagridBuilderInjectionCompilerPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -21,7 +22,7 @@ class DatagridBuilderInjectionCompilerPassTest extends AbstractCompilerPassTestCase { - public function testDatagridBuilderIsInjected() + public function testDatagridBuilderIsInjected(): void { $this->setParameter( 'sonata.admin.search.admin_finder_services', @@ -32,7 +33,7 @@ public function testDatagridBuilderIsInjected() $this->setDefinition( 'sonata.admin.search.datagrid_builder', new Definition( - 'Sonata\AdminSearchBundle\Builder\DatagridBuilder', + DatagridBuilder::class, [ new Reference('sonata.admin.search.elastica_datagrid_builder'), null, @@ -47,7 +48,7 @@ public function testDatagridBuilderIsInjected() ); } - protected function registerCompilerPass(ContainerBuilder $container) + protected function registerCompilerPass(ContainerBuilder $container): void { $container->addCompilerPass(new DatagridBuilderInjectionCompilerPass()); } diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index 2e8172c..a5f6e69 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -14,13 +14,14 @@ namespace Sonata\AdminSearchBundle\Tests\DependencyInjection; use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; +use PHPUnit\Framework\TestCase; use Sonata\AdminSearchBundle\DependencyInjection\Configuration; -class ConfigurationTest +class ConfigurationTest extends TestCase { use ConfigurationTestCaseTrait; - public function testValidation() + public function testValidation(): void { $this->assertConfigurationIsInvalid( [ @@ -33,7 +34,7 @@ public function testValidation() ); } - public function testProcessing() + public function testProcessing(): void { $this->assertProcessedConfigurationEquals( [ @@ -53,7 +54,7 @@ public function testProcessing() ); } - protected function getConfiguration() + protected function getConfiguration(): Configuration { return new Configuration(); } diff --git a/tests/DependencyInjection/SonataAdminSearchExtensionTest.php b/tests/DependencyInjection/SonataAdminSearchExtensionTest.php index c5160bb..7d9fda6 100644 --- a/tests/DependencyInjection/SonataAdminSearchExtensionTest.php +++ b/tests/DependencyInjection/SonataAdminSearchExtensionTest.php @@ -18,14 +18,14 @@ class SonataAdminSearchExtensionTest extends AbstractExtensionTestCase { - public function getContainerExtensions() + public function getContainerExtensions(): array { return [ new SonataAdminSearchExtension(), ]; } - public function testLoad() + public function testLoad(): void { $this->load([ 'admin_finder_services' => $expectedParameterValue = [ diff --git a/tests/Filter/BooleanFilterTest.php b/tests/Filter/BooleanFilterTest.php index 7cdb8e0..b035bc1 100644 --- a/tests/Filter/BooleanFilterTest.php +++ b/tests/Filter/BooleanFilterTest.php @@ -13,6 +13,7 @@ namespace Sonata\AdminSearchBundle\Tests\Filter; +use FOS\ElasticaBundle\Finder\TransformedFinder; use PHPUnit\Framework\TestCase; use Sonata\AdminSearchBundle\Filter\BooleanFilter; use Sonata\AdminSearchBundle\ProxyQuery\ElasticaProxyQuery; @@ -25,16 +26,14 @@ class BooleanFilterTest extends TestCase */ protected $proxyQuery; - public function setup() + protected function setUp(): void { - $finder = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder') - ->disableOriginalConstructor() - ->getMock(); + $finder = $this->createMock(TransformedFinder::class); $this->proxyQuery = new ElasticaProxyQuery($finder); } - public function testNoFilterSimple() + public function testNoFilterSimple(): void { $filter = new BooleanFilter(); $value = BooleanType::TYPE_NO; @@ -51,7 +50,7 @@ public function testNoFilterSimple() $this->assertSame('false', $queryArray['query']['bool']['must'][0]['term']['foo']); } - public function testYesFilterSimple() + public function testYesFilterSimple(): void { $filter = new BooleanFilter(); $value = BooleanType::TYPE_YES; diff --git a/tests/Filter/DateFilterTest.php b/tests/Filter/DateFilterTest.php index 9facc8c..538692f 100644 --- a/tests/Filter/DateFilterTest.php +++ b/tests/Filter/DateFilterTest.php @@ -22,7 +22,7 @@ */ class DateFilterTest extends TestCase { - public function testGetFilterTypeClass() + public function testGetFilterTypeClass(): void { $filter = new DateFilter(); diff --git a/tests/Filter/DateRangeFilterTest.php b/tests/Filter/DateRangeFilterTest.php index 32eb384..73ad380 100644 --- a/tests/Filter/DateRangeFilterTest.php +++ b/tests/Filter/DateRangeFilterTest.php @@ -22,7 +22,7 @@ */ class DateRangeFilterTest extends TestCase { - public function testGetFilterTypeClass() + public function testGetFilterTypeClass(): void { $filter = new DateRangeFilter(); diff --git a/tests/Filter/DateTimeFilterTest.php b/tests/Filter/DateTimeFilterTest.php index fd6a19a..1b2d930 100644 --- a/tests/Filter/DateTimeFilterTest.php +++ b/tests/Filter/DateTimeFilterTest.php @@ -22,7 +22,7 @@ */ class DateTimeFilterTest extends TestCase { - public function testGetFilterTypeClass() + public function testGetFilterTypeClass(): void { $filter = new DateTimeFilter(); diff --git a/tests/Filter/DateTimeRangeFilterTest.php b/tests/Filter/DateTimeRangeFilterTest.php index 79ef849..39d429d 100644 --- a/tests/Filter/DateTimeRangeFilterTest.php +++ b/tests/Filter/DateTimeRangeFilterTest.php @@ -22,7 +22,7 @@ */ class DateTimeRangeFilterTest extends TestCase { - public function testGetFilterTypeClass() + public function testGetFilterTypeClass(): void { $filter = new DateTimeRangeFilter(); diff --git a/tests/Filter/StringFilterTest.php b/tests/Filter/StringFilterTest.php index 13290ad..4779ea1 100644 --- a/tests/Filter/StringFilterTest.php +++ b/tests/Filter/StringFilterTest.php @@ -13,6 +13,7 @@ namespace Sonata\AdminSearchBundle\Tests\Filter; +use FOS\ElasticaBundle\Finder\TransformedFinder; use PHPUnit\Framework\TestCase; use Sonata\AdminSearchBundle\Filter\StringFilter; use Sonata\AdminSearchBundle\ProxyQuery\ElasticaProxyQuery; @@ -24,16 +25,14 @@ class StringFilterTest extends TestCase */ protected $proxyQuery; - public function setup() + protected function setUp(): void { - $finder = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder') - ->disableOriginalConstructor() - ->getMock(); + $finder = $this->createMock(TransformedFinder::class); $this->proxyQuery = new ElasticaProxyQuery($finder); } - public function testFilterSimple() + public function testFilterSimple(): void { $filter = new StringFilter(); $value = 'bar'; @@ -53,7 +52,7 @@ public function testFilterSimple() /** * Check if filter query with special characters can be translated into JSON. */ - public function testFilterSpecialCharacters() + public function testFilterSpecialCharacters(): void { $filter = new StringFilter(); $value = 'bar \ + - && || ! ( ) { } [ ] ^ " ~ * ? : baz'; diff --git a/tests/Model/FinderProviderTest.php b/tests/Model/FinderProviderTest.php index 3bec559..4cdf2b5 100644 --- a/tests/Model/FinderProviderTest.php +++ b/tests/Model/FinderProviderTest.php @@ -14,14 +14,16 @@ namespace Sonata\AdminSearchBundle\Tests\Model; use PHPUnit\Framework\TestCase; +use Sonata\AdminBundle\Admin\AdminInterface; use Sonata\AdminSearchBundle\Model\FinderProvider; +use Symfony\Component\DependencyInjection\ContainerInterface; class FinderProviderTest extends TestCase { - public function testGetFinderByAdmin() + public function testGetFinderByAdmin(): void { - $admin = $this->createMock('Sonata\AdminBundle\Admin\AdminInterface'); - $container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $admin = $this->createMock(AdminInterface::class); + $container = $this->createMock(ContainerInterface::class); $provider = new FinderProvider( $container, [ diff --git a/tests/ProxyQuery/ElasticaProxyQueryTest.php b/tests/ProxyQuery/ElasticaProxyQueryTest.php index e6e8747..fc0f791 100644 --- a/tests/ProxyQuery/ElasticaProxyQueryTest.php +++ b/tests/ProxyQuery/ElasticaProxyQueryTest.php @@ -14,13 +14,14 @@ namespace Sonata\AdminSearchBundle\Tests\ProxyQuery; use FOS\ElasticaBundle\Finder\TransformedFinder; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Sonata\AdminSearchBundle\ProxyQuery\ElasticaProxyQuery; class ElasticaProxyQueryTest extends TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject|TransformedFinder + * @var MockObject|TransformedFinder */ protected $finder; @@ -35,23 +36,21 @@ class ElasticaProxyQueryTest extends TestCase 'columnName' => 'name', ]; - public function setup() + protected function setUp(): void { - $this->finder = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder') - ->disableOriginalConstructor() - ->getMock(); + $this->finder = $this->createMock(TransformedFinder::class); $this->proxyQuery = new ElasticaProxyQuery($this->finder); } - public function testSortByNoParent() + public function testSortByNoParent(): void { $this->proxyQuery->setSortBy(null, $this->fieldMapping); $this->assertSame('name', $this->proxyQuery->getSortBy()); } - public function testSortByWithParent() + public function testSortByWithParent(): void { $parentMapping = [ [ @@ -64,7 +63,7 @@ public function testSortByWithParent() $this->assertSame('category.name', $this->proxyQuery->getSortBy()); } - public function testSortOrder() + public function testSortOrder(): void { $this->proxyQuery->setSortOrder('ASC'); @@ -74,7 +73,7 @@ public function testSortOrder() /** * Test if "setSort" method of Elastica query has been called. */ - public function testExecuteWithSort() + public function testExecuteWithSort(): void { $this->finder->expects($this->once()) ->method('createPaginatorAdapter');