diff --git a/.editorconfig b/.editorconfig index 34b3f473..ee0d74ca 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,13 +11,13 @@ charset = utf-8 insert_final_newline = true trim_trailing_whitespace = true -[*.{yaml,yml,twig,php}] +[*.{xml,yaml,yml,twig,php}] indent_size = 4 [.yamllint] indent_size = 4 -[*.{js,json,scss,css}] +[*.{xliff,js,json,scss,css}] indent_size = 2 [composer.json] diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index fcd727fc..db5377cb 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -72,5 +72,8 @@ jobs: - name: Install required dependencies run: sudo apt-get update && sudo apt-get install libxml2-utils - - name: Lint files + - name: Lint xml files run: make lint-xml + + - name: Lint xliff files + run: make lint-xliff diff --git a/Makefile b/Makefile index 241cb4b7..ae6a5e2b 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ all: @echo "Please choose a task." .PHONY: all -lint: lint-composer lint-yaml lint-xml lint-php +lint: lint-composer lint-yaml lint-xml lint-xliff lint-php .PHONY: lint lint-composer: @@ -19,7 +19,7 @@ lint-yaml: .PHONY: lint-yaml lint-xml: - find . \( -name '*.xml' -or -name '*.xliff' \) \ + find . -name '*.xml' \ -not -path './vendor/*' \ -not -path './src/Resources/public/vendor/*' \ | while read xmlFile; \ @@ -30,6 +30,18 @@ lint-xml: .PHONY: lint-xml +lint-xliff: + find . -name '*.xliff' \ + -not -path './vendor/*' \ + -not -path './src/Resources/public/vendor/*' \ + | while read xmlFile; \ + do \ + XMLLINT_INDENT=' ' xmllint --encode UTF-8 --format "$$xmlFile"|diff - "$$xmlFile"; \ + if [ $$? -ne 0 ] ;then exit 1; fi; \ + done + +.PHONY: lint-xliff + lint-php: php-cs-fixer fix --ansi --verbose --diff --dry-run .PHONY: lint-php diff --git a/composer.json b/composer.json index 1b3fb263..43d8e921 100644 --- a/composer.json +++ b/composer.json @@ -55,6 +55,7 @@ "phpstan/extension-installer": "^1.1", "phpstan/phpstan": "^0.12.52", "phpstan/phpstan-phpunit": "^0.12.17", + "phpstan/phpstan-strict-rules": "^0.12.10", "phpstan/phpstan-symfony": "^0.12.20", "psalm/plugin-phpunit": "^0.15.1", "psalm/plugin-symfony": "^2.0", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 08d11cfc..467192d2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,7 +1,9 @@ parameters: - ignoreErrors: - - # Fixed in https://github.com/doctrine/mongodb-odm/pull/2307 - message: "#^Parameter \\#1 \\$expression of method Doctrine\\\\ODM\\\\MongoDB\\\\Query\\\\Builder\\:\\:not\\(\\) expects array\\|Doctrine\\\\ODM\\\\MongoDB\\\\Query\\\\Expr, MongoDB\\\\BSON\\\\Regex given\\.$#" - count: 1 - path: src/Filter/StringFilter.php + ignoreErrors: + - # Disallow VariableMethodCallRule and VariablePropertyFetchRule + message: '#^Variable (method call|property access)#' + path: . + - # https://github.com/phpstan/phpstan/issues/5357 + message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'Sonata\\\\\\\\AdminBundle\\\\\\\\Datagrid\\\\\\\\Pager' and \\*NEVER\\* will always evaluate to true\\.$#" + path: tests/Builder/DatagridBuilderTest.php diff --git a/src/Builder/DatagridBuilder.php b/src/Builder/DatagridBuilder.php index 2cf69c4c..445d9efb 100644 --- a/src/Builder/DatagridBuilder.php +++ b/src/Builder/DatagridBuilder.php @@ -17,6 +17,8 @@ use Sonata\AdminBundle\Builder\DatagridBuilderInterface; use Sonata\AdminBundle\Datagrid\Datagrid; use Sonata\AdminBundle\Datagrid\DatagridInterface; +use Sonata\AdminBundle\Datagrid\PagerInterface; +use Sonata\AdminBundle\Datagrid\SimplePager; use Sonata\AdminBundle\FieldDescription\FieldDescriptionInterface; use Sonata\AdminBundle\FieldDescription\TypeGuesserInterface; use Sonata\AdminBundle\Filter\FilterFactoryInterface; @@ -124,7 +126,7 @@ public function addFilter(DatagridInterface $datagrid, ?string $type, FieldDescr public function getBaseDatagrid(AdminInterface $admin, array $values = []): DatagridInterface { - $pager = new Pager(); + $pager = $this->getPager($admin->getPagerType()); $defaultOptions = []; if ($this->csrfTokenEnabled) { @@ -140,4 +142,28 @@ public function getBaseDatagrid(AdminInterface $admin, array $values = []): Data return new Datagrid($query, $admin->getList(), $pager, $formBuilder, $values); } + + /** + * Get pager by pagerType. + * + * @throws \RuntimeException If invalid pager type is set + * + * @return PagerInterface + */ + private function getPager(string $pagerType): PagerInterface + { + switch ($pagerType) { + case Pager::TYPE_DEFAULT: + return new Pager(); + + case Pager::TYPE_SIMPLE: + /** @var SimplePager $simplePager */ + $simplePager = new SimplePager(); + + return $simplePager; + + default: + throw new \RuntimeException(sprintf('Unknown pager type "%s".', $pagerType)); + } + } } diff --git a/src/Builder/ListBuilder.php b/src/Builder/ListBuilder.php index 9f8192d7..cd32ea6c 100644 --- a/src/Builder/ListBuilder.php +++ b/src/Builder/ListBuilder.php @@ -94,7 +94,7 @@ public function fixFieldDescription(FieldDescriptionInterface $fieldDescription) $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName())); - if (!$fieldDescription->getTemplate()) { + if (null === $fieldDescription->getTemplate()) { $fieldDescription->setTemplate($this->getTemplate($type)); } diff --git a/src/Builder/ShowBuilder.php b/src/Builder/ShowBuilder.php index f2e3887a..b0d5c560 100644 --- a/src/Builder/ShowBuilder.php +++ b/src/Builder/ShowBuilder.php @@ -78,7 +78,7 @@ public function fixFieldDescription(FieldDescriptionInterface $fieldDescription) $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName())); - if (!$fieldDescription->getTemplate()) { + if (null === $fieldDescription->getTemplate()) { $fieldDescription->setTemplate($this->getTemplate($type)); } diff --git a/src/Datagrid/ProxyQuery.php b/src/Datagrid/ProxyQuery.php index 4605a2a3..f4450df9 100644 --- a/src/Datagrid/ProxyQuery.php +++ b/src/Datagrid/ProxyQuery.php @@ -79,7 +79,7 @@ public function execute() // todo : check how doctrine behave, potential SQL injection here ... $sortBy = $this->getSortBy(); - if ($sortBy) { + if (null !== $sortBy) { $queryBuilder->sort($sortBy, $this->getSortOrder() ?? 'asc'); } diff --git a/src/FieldDescription/FieldDescription.php b/src/FieldDescription/FieldDescription.php index ad56fb79..bf8a7399 100644 --- a/src/FieldDescription/FieldDescription.php +++ b/src/FieldDescription/FieldDescription.php @@ -20,11 +20,7 @@ final class FieldDescription extends BaseFieldDescription { public function getTargetModel(): ?string { - if ($this->associationMapping) { - return $this->associationMapping['targetDocument']; - } - - return null; + return $this->associationMapping['targetDocument'] ?? null; } public function isIdentifier(): bool diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index 088dbc8d..4704a267 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -26,7 +26,7 @@ final public function apply(BaseProxyQueryInterface $query, FilterData $filterDa throw new \TypeError(sprintf('The query MUST implement "%s".', ProxyQueryInterface::class)); } - $field = $this->getParentAssociationMappings() ? $this->getName() : $this->getFieldName(); + $field = [] !== $this->getParentAssociationMappings() ? $this->getName() : $this->getFieldName(); $this->filter($query, $field, $filterData); } diff --git a/src/Filter/ModelFilter.php b/src/Filter/ModelFilter.php index 65775131..44354a60 100644 --- a/src/Filter/ModelFilter.php +++ b/src/Filter/ModelFilter.php @@ -90,10 +90,6 @@ protected function handleMultiple(ProxyQueryInterface $query, string $field, Fil protected function handleScalar(ProxyQueryInterface $query, string $field, FilterData $data): void { - if (empty($data->getValue())) { - return; - } - $id = self::fixIdentifier($data->getValue()->getId()); if ($data->isType(EqualOperatorType::TYPE_NOT_EQUAL)) { diff --git a/tests/Builder/DatagridBuilderTest.php b/tests/Builder/DatagridBuilderTest.php index 8836fa25..c57badcc 100644 --- a/tests/Builder/DatagridBuilderTest.php +++ b/tests/Builder/DatagridBuilderTest.php @@ -20,6 +20,7 @@ use Sonata\AdminBundle\Datagrid\Datagrid; use Sonata\AdminBundle\Datagrid\DatagridInterface; use Sonata\AdminBundle\Datagrid\Pager; +use Sonata\AdminBundle\Datagrid\SimplePager; use Sonata\AdminBundle\FieldDescription\FieldDescriptionCollection; use Sonata\AdminBundle\FieldDescription\TypeGuesserInterface; use Sonata\AdminBundle\Filter\FilterFactoryInterface; @@ -79,22 +80,43 @@ protected function setUp(): void $this->admin = $this->createMock(AdminInterface::class); } - public function testGetBaseDatagrid(): void + /** + * @phpstan-param class-string $pager + * + * @dataProvider getBaseDatagridData + */ + public function testGetBaseDatagrid(string $pagerType, string $pager): void { $proxyQuery = $this->createStub(ProxyQueryInterface::class); $fieldDescription = new FieldDescriptionCollection(); $formBuilder = $this->createStub(FormBuilderInterface::class); + $this->admin->method('getPagerType')->willReturn($pagerType); $this->admin->method('createQuery')->willReturn($proxyQuery); $this->admin->method('getList')->willReturn($fieldDescription); $this->formFactory->method('createNamedBuilder')->willReturn($formBuilder); - $this->assertInstanceOf( - Datagrid::class, - $datagrid = $this->datagridBuilder->getBaseDatagrid($this->admin) - ); - $this->assertInstanceOf(Pager::class, $datagrid->getPager()); + $datagrid = $this->datagridBuilder->getBaseDatagrid($this->admin); + self::assertInstanceOf(Datagrid::class, $datagrid); + self::assertInstanceOf(Pager::class, $datagrid->getPager()); + } + + /** + * @phpstan-return iterable + */ + public function getBaseDatagridData(): iterable + { + return [ + 'simple' => [ + Pager::TYPE_SIMPLE, + SimplePager::class, + ], + 'default' => [ + Pager::TYPE_DEFAULT, + Pager::class, + ], + ]; } public function testFixFieldDescription(): void @@ -111,7 +133,7 @@ public function testFixFieldDescription(): void $this->datagridBuilder->fixFieldDescription($fieldDescription); - $this->assertSame($classMetadata->fieldMappings['name'], $fieldDescription->getOption('field_mapping')); + self::assertSame($classMetadata->fieldMappings['name'], $fieldDescription->getOption('field_mapping')); } public function testFixFieldDescriptionWithAssociationMapping(): void @@ -128,18 +150,18 @@ public function testFixFieldDescriptionWithAssociationMapping(): void $fieldDescription->setAdmin($this->admin); $this->admin - ->expects($this->once()) + ->expects(self::once()) ->method('attachAdminClass'); $this->datagridBuilder->fixFieldDescription($fieldDescription); - $this->assertSame($classMetadata->associationMappings['embeddedDocument'], $fieldDescription->getOption('association_mapping')); + self::assertSame($classMetadata->associationMappings['embeddedDocument'], $fieldDescription->getOption('association_mapping')); } public function testAddFilterNoType(): void { $this->admin - ->expects($this->once()) + ->expects(self::once()) ->method('addFilterFieldDescription'); $datagrid = $this->createMock(DatagridInterface::class); @@ -162,12 +184,12 @@ public function testAddFilterNoType(): void $this->admin->method('getLabelTranslatorStrategy')->willReturn(new FormLabelTranslatorStrategy()); $datagrid - ->expects($this->once()) + ->expects(self::once()) ->method('addFilter') - ->with($this->isInstanceOf(ModelFilter::class)); + ->with(self::isInstanceOf(ModelFilter::class)); $this->filterFactory - ->expects($this->once()) + ->expects(self::once()) ->method('create') ->with('test', ModelFilter::class); @@ -177,14 +199,14 @@ public function testAddFilterNoType(): void $fieldDescription ); - $this->assertSame('guess_value', $fieldDescription->getOption('guess_option')); - $this->assertSame(['guess_array_value'], $fieldDescription->getOption('guess_array_option')); + self::assertSame('guess_value', $fieldDescription->getOption('guess_option')); + self::assertSame(['guess_array_value'], $fieldDescription->getOption('guess_array_option')); } public function testAddFilterWithType(): void { $this->admin - ->expects($this->once()) + ->expects(self::once()) ->method('addFilterFieldDescription'); $datagrid = $this->createMock(DatagridInterface::class); @@ -197,9 +219,9 @@ public function testAddFilterWithType(): void $this->admin->method('getLabelTranslatorStrategy')->willReturn(new FormLabelTranslatorStrategy()); $datagrid - ->expects($this->once()) + ->expects(self::once()) ->method('addFilter') - ->with($this->isInstanceOf(ModelFilter::class)); + ->with(self::isInstanceOf(ModelFilter::class)); $this->datagridBuilder->addFilter( $datagrid, @@ -207,6 +229,6 @@ public function testAddFilterWithType(): void $fieldDescription ); - $this->assertSame(ModelFilter::class, $fieldDescription->getType()); + self::assertSame(ModelFilter::class, $fieldDescription->getType()); } } diff --git a/tests/Builder/ListBuilderTest.php b/tests/Builder/ListBuilderTest.php index 19418722..2a15d386 100644 --- a/tests/Builder/ListBuilderTest.php +++ b/tests/Builder/ListBuilderTest.php @@ -69,13 +69,13 @@ public function testAddListActionField(): void $list = $this->listBuilder->getBaseList(); $this->admin - ->expects($this->once()) + ->expects(self::once()) ->method('addListFieldDescription'); $this->listBuilder ->addField($list, 'actions', $fieldDescription); - $this->assertSame( + self::assertSame( '@SonataAdmin/CRUD/list__action.html.twig', $list->get('foo')->getTemplate(), 'Custom list action field has a default list action template assigned' @@ -96,12 +96,12 @@ public function testCorrectFixedActionsFieldType(): void $list = $this->listBuilder->getBaseList(); $this->admin - ->expects($this->once()) + ->expects(self::once()) ->method('addListFieldDescription'); $this->listBuilder->addField($list, null, $fieldDescription); - $this->assertSame( + self::assertSame( ListMapper::TYPE_ACTIONS, $list->get(ListMapper::NAME_ACTIONS)->getType(), 'Standard list _action field has "actions" type' @@ -127,8 +127,8 @@ public function testFixFieldDescriptionWithFieldMapping(): void $this->listBuilder->fixFieldDescription($fieldDescription); - $this->assertSame('@SonataAdmin/CRUD/list_string.html.twig', $fieldDescription->getTemplate()); - $this->assertSame($classMetadata->getFieldMapping('name'), $fieldDescription->getFieldMapping()); + self::assertSame('@SonataAdmin/CRUD/list_string.html.twig', $fieldDescription->getTemplate()); + self::assertSame($classMetadata->getFieldMapping('name'), $fieldDescription->getFieldMapping()); } public function testFixFieldDescriptionException(): void diff --git a/tests/Builder/ShowBuilderTest.php b/tests/Builder/ShowBuilderTest.php index ab9c8ba6..a61e0b2a 100644 --- a/tests/Builder/ShowBuilderTest.php +++ b/tests/Builder/ShowBuilderTest.php @@ -67,8 +67,8 @@ public function testAddFieldNoType(): void $fieldDescription = new FieldDescription('FakeName', [], ['type' => ClassMetadata::ONE]); $fieldDescription->setAdmin($this->admin); - $this->admin->expects($this->once())->method('attachAdminClass'); - $this->admin->expects($this->once())->method('addShowFieldDescription'); + $this->admin->expects(self::once())->method('attachAdminClass'); + $this->admin->expects(self::once())->method('addShowFieldDescription'); $typeGuess->method('getType')->willReturn('fakeType'); @@ -80,7 +80,7 @@ public function testAddFieldNoType(): void $fieldDescription ); - $this->assertSame('fakeType', $fieldDescription->getType()); + self::assertSame('fakeType', $fieldDescription->getType()); } public function testAddFieldWithType(): void @@ -88,7 +88,7 @@ public function testAddFieldWithType(): void $fieldDescription = new FieldDescription('FakeName'); $fieldDescription->setAdmin($this->admin); - $this->admin->expects($this->once())->method('addShowFieldDescription'); + $this->admin->expects(self::once())->method('addShowFieldDescription'); $this->showBuilder->addField( new FieldDescriptionCollection(), @@ -96,7 +96,7 @@ public function testAddFieldWithType(): void $fieldDescription ); - $this->assertSame('someType', $fieldDescription->getType()); + self::assertSame('someType', $fieldDescription->getType()); } public function testFixFieldDescriptionException(): void diff --git a/tests/Datagrid/ProxyQueryTest.php b/tests/Datagrid/ProxyQueryTest.php index f9631b25..9a3232e4 100644 --- a/tests/Datagrid/ProxyQueryTest.php +++ b/tests/Datagrid/ProxyQueryTest.php @@ -54,13 +54,13 @@ public function testSetLimitToZeroWhenResettingMaxResults(): void $proxyQuery = new ProxyQuery($this->queryBuilder); $this->queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('limit') ->with(0); $proxyQuery->setMaxResults(null); - $this->assertNull($proxyQuery->getMaxResults()); + self::assertNull($proxyQuery->getMaxResults()); } public function testSetSkipToZeroWhenResettingFirstResult(): void @@ -68,13 +68,13 @@ public function testSetSkipToZeroWhenResettingFirstResult(): void $proxyQuery = new ProxyQuery($this->queryBuilder); $this->queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('skip') ->with(0); $proxyQuery->setFirstResult(null); - $this->assertNull($proxyQuery->getFirstResult()); + self::assertNull($proxyQuery->getFirstResult()); } public function testSorting(): void @@ -83,12 +83,12 @@ public function testSorting(): void $proxyQuery->setSortBy([], ['fieldName' => 'name']); $proxyQuery->setSortOrder('ASC'); - $this->assertSame( + self::assertSame( 'name', $proxyQuery->getSortBy() ); - $this->assertSame( + self::assertSame( 'ASC', $proxyQuery->getSortOrder() ); @@ -101,7 +101,7 @@ public function testSortingWithWithEmbedded(): void $proxyQuery = new ProxyQuery($queryBuilder); $proxyQuery->setSortBy([['fieldName' => 'embeddedDocument']], ['fieldName' => 'position']); - $this->assertSame( + self::assertSame( 'embeddedDocument.position', $proxyQuery->getSortBy() ); @@ -125,7 +125,7 @@ public function testExecuteAllowsSorting(): void /** @var array{array{name: string}} $result */ $result = $proxyQuery->execute()->toArray(); - $this->assertSame(['B', 'A'], $this->getNames($result)); + self::assertSame(['B', 'A'], $this->getNames($result)); } public function testExecuteAllowsSortingWithEmbedded(): void @@ -149,7 +149,7 @@ public function testExecuteAllowsSortingWithEmbedded(): void /** @var array{array{name: string}} $result */ $result = $proxyQuery->execute()->toArray(); - $this->assertSame(['B', 'A'], $this->getNames($result)); + self::assertSame(['B', 'A'], $this->getNames($result)); } /** @@ -159,7 +159,7 @@ public function testExecuteAllowsSortingWithEmbedded(): void */ private function getNames(array $results): array { - return array_values(array_map(static function (array $result) { + return array_values(array_map(static function (array $result): string { return $result['name']; }, $results)); } diff --git a/tests/DependencyInjection/Compiler/AddGuesserCompilerPassTest.php b/tests/DependencyInjection/Compiler/AddGuesserCompilerPassTest.php index 577de245..27da784a 100644 --- a/tests/DependencyInjection/Compiler/AddGuesserCompilerPassTest.php +++ b/tests/DependencyInjection/Compiler/AddGuesserCompilerPassTest.php @@ -33,7 +33,7 @@ public function testAddsGuessers(string $builderServiceId, string $guesserTag): $this->compile(); - $this->assertContainerBuilderHasServiceDefinitionWithArgument( + self::assertContainerBuilderHasServiceDefinitionWithArgument( $builderServiceId, 0, [ diff --git a/tests/DependencyInjection/Compiler/AddTemplatesCompilerPassTest.php b/tests/DependencyInjection/Compiler/AddTemplatesCompilerPassTest.php index ee3a23f5..b9e37bbc 100644 --- a/tests/DependencyInjection/Compiler/AddTemplatesCompilerPassTest.php +++ b/tests/DependencyInjection/Compiler/AddTemplatesCompilerPassTest.php @@ -36,7 +36,7 @@ public function testSetThemes(): void $this->compile(); - $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( + self::assertContainerBuilderHasServiceDefinitionWithMethodCall( $adminServiceId, 'setFormTheme', [ @@ -44,7 +44,7 @@ public function testSetThemes(): void ] ); - $this->assertContainerBuilderHasServiceDefinitionWithMethodCall( + self::assertContainerBuilderHasServiceDefinitionWithMethodCall( $adminServiceId, 'setFilterTheme', [ diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index 6bb6d92d..dec1f087 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -23,14 +23,14 @@ final class ConfigurationTest extends TestCase public function testDefaultOptions(): void { - $this->assertProcessedConfigurationEquals([], [ + self::assertProcessedConfigurationEquals([], [ 'templates' => [], ]); } public function testCustomTemplates(): void { - $this->assertProcessedConfigurationEquals([[ + self::assertProcessedConfigurationEquals([[ 'templates' => [ 'types' => [ 'list' => [ @@ -57,7 +57,7 @@ public function testCustomTemplates(): void public function testTemplateTypesWithInvalidValues(): void { - $this->assertConfigurationIsInvalid( + self::assertConfigurationIsInvalid( [[ 'templates' => [ 'types' => [ diff --git a/tests/DependencyInjection/SonataDoctrineMongoDBAdminExtensionTest.php b/tests/DependencyInjection/SonataDoctrineMongoDBAdminExtensionTest.php index 7915db23..71190acc 100644 --- a/tests/DependencyInjection/SonataDoctrineMongoDBAdminExtensionTest.php +++ b/tests/DependencyInjection/SonataDoctrineMongoDBAdminExtensionTest.php @@ -23,31 +23,31 @@ public function testEntityManagerSetFactory(): void $this->container->setParameter('kernel.bundles', []); $this->load(); - $this->assertContainerBuilderHasService('sonata.admin.manager.doctrine_mongodb'); - $this->assertContainerBuilderHasService('sonata.admin.builder.doctrine_mongodb_form'); - $this->assertContainerBuilderHasService('sonata.admin.builder.doctrine_mongodb_list'); - $this->assertContainerBuilderHasService('sonata.admin.guesser.doctrine_mongodb_list'); - $this->assertContainerBuilderHasService('sonata.admin.guesser.doctrine_mongodb_list_chain'); - $this->assertContainerBuilderHasService('sonata.admin.builder.doctrine_mongodb_show'); - $this->assertContainerBuilderHasService('sonata.admin.guesser.doctrine_mongodb_show'); - $this->assertContainerBuilderHasService('sonata.admin.guesser.doctrine_mongodb_show_chain'); - $this->assertContainerBuilderHasService('sonata.admin.builder.doctrine_mongodb_datagrid'); - $this->assertContainerBuilderHasService('sonata.admin.guesser.doctrine_mongodb_datagrid'); - $this->assertContainerBuilderHasService('sonata.admin.guesser.doctrine_mongodb_datagrid_chain'); - - $this->assertContainerBuilderHasService('sonata.admin.manager.doctrine_mongodb'); - $this->assertContainerBuilderHasService('sonata.admin.odm.filter.type.boolean'); - $this->assertContainerBuilderHasService('sonata.admin.odm.filter.type.callback'); - $this->assertContainerBuilderHasService('sonata.admin.odm.filter.type.choice'); - $this->assertContainerBuilderHasService('sonata.admin.odm.filter.type.id'); - $this->assertContainerBuilderHasService('sonata.admin.odm.filter.type.model'); - $this->assertContainerBuilderHasService('sonata.admin.odm.filter.type.string'); - $this->assertContainerBuilderHasService('sonata.admin.odm.filter.type.number'); - $this->assertContainerBuilderHasService('sonata.admin.odm.filter.type.date'); - $this->assertContainerBuilderHasService('sonata.admin.odm.filter.type.datetime'); - - $this->assertContainerBuilderHasService('sonata.admin.manipulator.acl.object.doctrine_mongodb'); - $this->assertContainerBuilderHasServiceDefinitionWithArgument( + self::assertContainerBuilderHasService('sonata.admin.manager.doctrine_mongodb'); + self::assertContainerBuilderHasService('sonata.admin.builder.doctrine_mongodb_form'); + self::assertContainerBuilderHasService('sonata.admin.builder.doctrine_mongodb_list'); + self::assertContainerBuilderHasService('sonata.admin.guesser.doctrine_mongodb_list'); + self::assertContainerBuilderHasService('sonata.admin.guesser.doctrine_mongodb_list_chain'); + self::assertContainerBuilderHasService('sonata.admin.builder.doctrine_mongodb_show'); + self::assertContainerBuilderHasService('sonata.admin.guesser.doctrine_mongodb_show'); + self::assertContainerBuilderHasService('sonata.admin.guesser.doctrine_mongodb_show_chain'); + self::assertContainerBuilderHasService('sonata.admin.builder.doctrine_mongodb_datagrid'); + self::assertContainerBuilderHasService('sonata.admin.guesser.doctrine_mongodb_datagrid'); + self::assertContainerBuilderHasService('sonata.admin.guesser.doctrine_mongodb_datagrid_chain'); + + self::assertContainerBuilderHasService('sonata.admin.manager.doctrine_mongodb'); + self::assertContainerBuilderHasService('sonata.admin.odm.filter.type.boolean'); + self::assertContainerBuilderHasService('sonata.admin.odm.filter.type.callback'); + self::assertContainerBuilderHasService('sonata.admin.odm.filter.type.choice'); + self::assertContainerBuilderHasService('sonata.admin.odm.filter.type.id'); + self::assertContainerBuilderHasService('sonata.admin.odm.filter.type.model'); + self::assertContainerBuilderHasService('sonata.admin.odm.filter.type.string'); + self::assertContainerBuilderHasService('sonata.admin.odm.filter.type.number'); + self::assertContainerBuilderHasService('sonata.admin.odm.filter.type.date'); + self::assertContainerBuilderHasService('sonata.admin.odm.filter.type.datetime'); + + self::assertContainerBuilderHasService('sonata.admin.manipulator.acl.object.doctrine_mongodb'); + self::assertContainerBuilderHasServiceDefinitionWithArgument( 'sonata.admin.manipulator.acl.object.doctrine_mongodb', 0, 'doctrine_mongodb' diff --git a/tests/Exporter/DataSourceTest.php b/tests/Exporter/DataSourceTest.php index a1e84a14..d710f541 100644 --- a/tests/Exporter/DataSourceTest.php +++ b/tests/Exporter/DataSourceTest.php @@ -55,8 +55,8 @@ public function testItResetsTheQueryBeforeCreatingIterator(): void $this->dataSource->createIterator($proxyQuery, []); - $this->assertNull($proxyQuery->getFirstResult()); - $this->assertNull($proxyQuery->getMaxResults()); + self::assertNull($proxyQuery->getFirstResult()); + self::assertNull($proxyQuery->getMaxResults()); } public function testItThrowAnExceptionWithInvalidQuery(): void diff --git a/tests/FieldDescription/FieldDescriptionFactoryTest.php b/tests/FieldDescription/FieldDescriptionFactoryTest.php index 91d0989e..fca06e73 100644 --- a/tests/FieldDescription/FieldDescriptionFactoryTest.php +++ b/tests/FieldDescription/FieldDescriptionFactoryTest.php @@ -26,21 +26,21 @@ public function testCreate(): void $fieldDescription = $fieldDescriptionFactory->create(ContainerDocument::class, 'plainField'); - $this->assertSame('edit', $fieldDescription->getOption('route')['name']); + self::assertSame('edit', $fieldDescription->getOption('route')['name']); $fieldDescription = $fieldDescriptionFactory->create(ContainerDocument::class, 'plainField'); - $this->assertSame(Type::INT, $fieldDescription->getMappingType()); + self::assertSame(Type::INT, $fieldDescription->getMappingType()); $fieldDescription = $fieldDescriptionFactory->create(ContainerDocument::class, 'associatedDocument.plainField'); - $this->assertSame(Type::INT, $fieldDescription->getMappingType()); + self::assertSame(Type::INT, $fieldDescription->getMappingType()); $fieldDescription = $fieldDescriptionFactory->create(ContainerDocument::class, 'embeddedDocument.plainField'); - $this->assertSame(Type::BOOL, $fieldDescription->getMappingType()); + self::assertSame(Type::BOOL, $fieldDescription->getMappingType()); $fieldDescription = $fieldDescriptionFactory->create(ContainerDocument::class, 'embeddedDocument'); - $this->assertSame(ClassMetadata::ONE, $fieldDescription->getMappingType()); + self::assertSame(ClassMetadata::ONE, $fieldDescription->getMappingType()); $fieldDescription = $fieldDescriptionFactory->create(ContainerDocument::class, 'embeddedDocument'); - $this->assertNotSame([], $fieldDescription->getAssociationMapping()); + self::assertNotSame([], $fieldDescription->getAssociationMapping()); } } diff --git a/tests/FieldDescription/FieldDescriptionTest.php b/tests/FieldDescription/FieldDescriptionTest.php index a7774c2a..0cb690c9 100644 --- a/tests/FieldDescription/FieldDescriptionTest.php +++ b/tests/FieldDescription/FieldDescriptionTest.php @@ -30,7 +30,7 @@ public function testAssociationMapping(): void ] ); - $this->assertSame('integer', $field->getMappingType()); + self::assertSame('integer', $field->getMappingType()); } public function testGetAssociationMapping(): void @@ -42,7 +42,7 @@ public function testGetAssociationMapping(): void $field = new FieldDescription('name', [], [], $associationMapping); - $this->assertSame($associationMapping, $field->getAssociationMapping()); + self::assertSame($associationMapping, $field->getAssociationMapping()); } public function testSetFieldMappingSetMappingType(): void @@ -54,7 +54,7 @@ public function testSetFieldMappingSetMappingType(): void $field = new FieldDescription('name', [], $fieldMapping); - $this->assertSame('integer', $field->getMappingType()); + self::assertSame('integer', $field->getMappingType()); } public function testGetTargetModel(): void @@ -67,11 +67,11 @@ public function testGetTargetModel(): void $field = new FieldDescription('name'); - $this->assertNull($field->getTargetModel()); + self::assertNull($field->getTargetModel()); $field = new FieldDescription('name', [], [], $associationMapping); - $this->assertSame(\stdClass::class, $field->getTargetModel()); + self::assertSame(\stdClass::class, $field->getTargetModel()); } public function testIsIdentifierFromFieldMapping(): void @@ -84,7 +84,7 @@ public function testIsIdentifierFromFieldMapping(): void $field = new FieldDescription('name', [], $fieldMapping); - $this->assertTrue($field->isIdentifier()); + self::assertTrue($field->isIdentifier()); } public function testGetFieldMapping(): void @@ -97,7 +97,7 @@ public function testGetFieldMapping(): void $field = new FieldDescription('name', [], $fieldMapping); - $this->assertSame($fieldMapping, $field->getFieldMapping()); + self::assertSame($fieldMapping, $field->getFieldMapping()); } public function testGetParentValue(): void @@ -130,6 +130,6 @@ public function parent(): object } }; - $this->assertSame('hi', $field->getValue($dummyChild)); + self::assertSame('hi', $field->getValue($dummyChild)); } } diff --git a/tests/FieldDescription/FilterTypeGuesserTest.php b/tests/FieldDescription/FilterTypeGuesserTest.php index 1bb3b882..8258c0ee 100644 --- a/tests/FieldDescription/FilterTypeGuesserTest.php +++ b/tests/FieldDescription/FilterTypeGuesserTest.php @@ -91,12 +91,12 @@ public function testGuessTypeWithAssociation(): void $options = $result->getOptions(); - $this->assertSame(ModelFilter::class, $result->getType()); - $this->assertSame(Guess::HIGH_CONFIDENCE, $result->getConfidence()); - $this->assertSame($parentAssociation, $options['parent_association_mappings']); - $this->assertSame(ClassMetadata::ONE, $options['mapping_type']); - $this->assertSame($property, $options['field_name']); - $this->assertSame($targetDocument, $options['field_options']['class']); + self::assertSame(ModelFilter::class, $result->getType()); + self::assertSame(Guess::HIGH_CONFIDENCE, $result->getConfidence()); + self::assertSame($parentAssociation, $options['parent_association_mappings']); + self::assertSame(ClassMetadata::ONE, $options['mapping_type']); + self::assertSame($property, $options['field_name']); + self::assertSame($targetDocument, $options['field_options']['class']); } /** @@ -125,8 +125,8 @@ public function testGuessTypeNoAssociation(string $type, string $resultType, int $result = $this->guesser->guess($fieldDescription); - $this->assertSame($resultType, $result->getType()); - $this->assertSame($confidence, $result->getConfidence()); + self::assertSame($resultType, $result->getType()); + self::assertSame($confidence, $result->getConfidence()); } /** diff --git a/tests/FieldDescription/TypeGuesserTest.php b/tests/FieldDescription/TypeGuesserTest.php index fbb7dd2f..a917f0f0 100644 --- a/tests/FieldDescription/TypeGuesserTest.php +++ b/tests/FieldDescription/TypeGuesserTest.php @@ -57,8 +57,8 @@ public function testGuessTypeWithAssociation(string $mappingType, string $type): $result = $this->guesser->guess($fieldDescription); - $this->assertSame($type, $result->getType()); - $this->assertSame(Guess::HIGH_CONFIDENCE, $result->getConfidence()); + self::assertSame($type, $result->getType()); + self::assertSame(Guess::HIGH_CONFIDENCE, $result->getConfidence()); } /** @@ -98,8 +98,8 @@ public function testGuessTypeNoAssociation(string $type, string $resultType, int $result = $this->guesser->guess($fieldDescription); - $this->assertSame($resultType, $result->getType()); - $this->assertSame($confidence, $result->getConfidence()); + self::assertSame($resultType, $result->getType()); + self::assertSame($confidence, $result->getConfidence()); } /** diff --git a/tests/Filter/BooleanFilterTest.php b/tests/Filter/BooleanFilterTest.php index 13f79aac..8dc80df4 100644 --- a/tests/Filter/BooleanFilterTest.php +++ b/tests/Filter/BooleanFilterTest.php @@ -26,14 +26,14 @@ public function testFilterEmpty(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->never()) + ->expects(self::never()) ->method('field'); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray([])); - $this->assertFalse($filter->isActive()); + self::assertFalse($filter->isActive()); } /** @@ -45,7 +45,7 @@ public function testFilterScalar(bool $equalsReturnValue, int $value): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('equals') ->with($equalsReturnValue); @@ -53,7 +53,7 @@ public function testFilterScalar(bool $equalsReturnValue, int $value): void $filter->apply($builder, FilterData::fromArray(['type' => null, 'value' => $value])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } /** @@ -73,7 +73,7 @@ public function testFilterArray(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('in') ->with([false]); @@ -81,14 +81,14 @@ public function testFilterArray(): void $filter->apply($builder, FilterData::fromArray(['type' => null, 'value' => [BooleanType::TYPE_NO]])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } public function testDefaultValues(): void { $filter = $this->createFilter(); - $this->assertSame(BooleanType::class, $filter->getFieldType()); + self::assertSame(BooleanType::class, $filter->getFieldType()); } private function createFilter(): BooleanFilter diff --git a/tests/Filter/CallbackFilterTest.php b/tests/Filter/CallbackFilterTest.php index 7ac4df9e..70f072f9 100644 --- a/tests/Filter/CallbackFilterTest.php +++ b/tests/Filter/CallbackFilterTest.php @@ -34,7 +34,7 @@ public function testFilterClosureEmpty(): void $filter->apply($builder, FilterData::fromArray([])); - $this->assertFalse($filter->isActive()); + self::assertFalse($filter->isActive()); } public function testFilterClosureNotEmpty(): void @@ -51,7 +51,7 @@ public function testFilterClosureNotEmpty(): void $filter->apply($builder, FilterData::fromArray(['value' => 'myValue'])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } public function testFilterMethodEmpty(): void @@ -66,7 +66,7 @@ public function testFilterMethodEmpty(): void $filter->apply($builder, FilterData::fromArray([])); - $this->assertFalse($filter->isActive()); + self::assertFalse($filter->isActive()); } public function testFilterMethodNotEmpty(): void @@ -81,7 +81,7 @@ public function testFilterMethodNotEmpty(): void $filter->apply($builder, FilterData::fromArray(['value' => 'myValue'])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } public function customCallback(ProxyQueryInterface $proxyQuery, string $field, FilterData $data): bool diff --git a/tests/Filter/ChoiceFilterTest.php b/tests/Filter/ChoiceFilterTest.php index 86bf926f..4e1367b5 100644 --- a/tests/Filter/ChoiceFilterTest.php +++ b/tests/Filter/ChoiceFilterTest.php @@ -26,14 +26,14 @@ public function testFilterEmpty(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->never()) + ->expects(self::never()) ->method('field'); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray([])); - $this->assertFalse($filter->isActive()); + self::assertFalse($filter->isActive()); } public function testFilterArray(): void @@ -42,7 +42,7 @@ public function testFilterArray(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('in') ->with(['1', '2']); @@ -50,7 +50,7 @@ public function testFilterArray(): void $filter->apply($builder, FilterData::fromArray(['type' => ContainsOperatorType::TYPE_CONTAINS, 'value' => ['1', '2']])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } public function testFilterScalar(): void @@ -59,7 +59,7 @@ public function testFilterScalar(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('equals') ->with('1'); @@ -67,7 +67,7 @@ public function testFilterScalar(): void $filter->apply($builder, FilterData::fromArray(['type' => ContainsOperatorType::TYPE_CONTAINS, 'value' => '1'])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } public function testFilterZero(): void @@ -76,7 +76,7 @@ public function testFilterZero(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('equals') ->with('0'); @@ -84,7 +84,7 @@ public function testFilterZero(): void $filter->apply($builder, FilterData::fromArray(['type' => ContainsOperatorType::TYPE_CONTAINS, 'value' => 0])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } private function createFilter(): ChoiceFilter diff --git a/tests/Filter/DateFilterTest.php b/tests/Filter/DateFilterTest.php index e95084ca..bd6ac76e 100644 --- a/tests/Filter/DateFilterTest.php +++ b/tests/Filter/DateFilterTest.php @@ -26,19 +26,19 @@ public function testEmpty(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->never()) + ->expects(self::never()) ->method('field'); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray([])); - $this->assertFalse($filter->isActive()); + self::assertFalse($filter->isActive()); } public function testGetType(): void { - $this->assertSame(DateType::class, $this->createFilter()->getFieldType()); + self::assertSame(DateType::class, $this->createFilter()->getFieldType()); } public function testFilterRecordsWholeDay(): void @@ -50,12 +50,12 @@ public function testFilterRecordsWholeDay(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('gte') ->with($date); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('lt') ->with($datePlusOneDay); @@ -63,7 +63,7 @@ public function testFilterRecordsWholeDay(): void $filter->apply($builder, FilterData::fromArray(['value' => $date])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } private function createFilter(): DateFilter diff --git a/tests/Filter/DateRangeFilterTest.php b/tests/Filter/DateRangeFilterTest.php index 6aeeb03c..fd45d368 100644 --- a/tests/Filter/DateRangeFilterTest.php +++ b/tests/Filter/DateRangeFilterTest.php @@ -32,14 +32,14 @@ public function testEmpty(array $value): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->never()) + ->expects(self::never()) ->method('field'); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray($value)); - $this->assertFalse($filter->isActive()); + self::assertFalse($filter->isActive()); } /** @@ -58,7 +58,7 @@ public function getNotApplicableValues(): iterable public function testGetType(): void { - $this->assertSame(DateRangeType::class, $this->createFilter()->getFieldType()); + self::assertSame(DateRangeType::class, $this->createFilter()->getFieldType()); } /** @@ -73,7 +73,7 @@ public function testFilterEndDateCoversWholeDay( $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('lte') ->with($expectedEndDateTime); @@ -85,8 +85,8 @@ public function testFilterEndDateCoversWholeDay( $modelEndDateTime = clone $viewEndDateTime; $modelEndDateTime->setTimezone($modelTimeZone); - $this->assertSame($modelTimeZone->getName(), $modelEndDateTime->getTimezone()->getName()); - $this->assertNotSame($modelTimeZone->getName(), $viewEndDateTime->getTimezone()->getName()); + self::assertSame($modelTimeZone->getName(), $modelEndDateTime->getTimezone()->getName()); + self::assertNotSame($modelTimeZone->getName(), $viewEndDateTime->getTimezone()->getName()); $filter->apply($proxyQuery, FilterData::fromArray([ 'type' => DateRangeOperatorType::TYPE_BETWEEN, @@ -96,8 +96,8 @@ public function testFilterEndDateCoversWholeDay( ], ])); - $this->assertTrue($filter->isActive()); - $this->assertSame($expectedEndDateTime->getTimestamp(), $modelEndDateTime->getTimestamp()); + self::assertTrue($filter->isActive()); + self::assertSame($expectedEndDateTime->getTimestamp(), $modelEndDateTime->getTimestamp()); } /** diff --git a/tests/Filter/DateTimeFilterTest.php b/tests/Filter/DateTimeFilterTest.php index e52048a4..8c7d5c8a 100644 --- a/tests/Filter/DateTimeFilterTest.php +++ b/tests/Filter/DateTimeFilterTest.php @@ -27,19 +27,19 @@ public function testEmpty(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->never()) + ->expects(self::never()) ->method('field'); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray([])); - $this->assertFalse($filter->isActive()); + self::assertFalse($filter->isActive()); } public function testGetType(): void { - $this->assertSame(DateTimeType::class, $this->createFilter()->getFieldType()); + self::assertSame(DateTimeType::class, $this->createFilter()->getFieldType()); } /** @@ -53,7 +53,7 @@ public function testFilter(array $data, string $method): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method($method) ->with($data['value'] ?? null); @@ -61,7 +61,7 @@ public function testFilter(array $data, string $method): void $filter->apply($builder, FilterData::fromArray($data)); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } /** diff --git a/tests/Filter/DateTimeRangeFilterTest.php b/tests/Filter/DateTimeRangeFilterTest.php index a63586c4..4df798c9 100644 --- a/tests/Filter/DateTimeRangeFilterTest.php +++ b/tests/Filter/DateTimeRangeFilterTest.php @@ -32,14 +32,14 @@ public function testEmpty(array $value): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->never()) + ->expects(self::never()) ->method('field'); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray($value)); - $this->assertFalse($filter->isActive()); + self::assertFalse($filter->isActive()); } /** @@ -58,7 +58,7 @@ public function getNotApplicableValues(): iterable public function testGetType(): void { - $this->assertSame(DateTimeRangeType::class, $this->createFilter()->getFieldType()); + self::assertSame(DateTimeRangeType::class, $this->createFilter()->getFieldType()); } /** @@ -73,12 +73,12 @@ public function testFilterBetween(?int $type): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('gte') ->with($startDate); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('lte') ->with($endDate); @@ -92,7 +92,7 @@ public function testFilterBetween(?int $type): void ], ])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } /** @@ -113,12 +113,12 @@ public function testFilterNotBetween(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('lt') ->with($startDate); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('gt') ->with($endDate); @@ -132,7 +132,7 @@ public function testFilterNotBetween(): void ], ])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } private function createFilter(): DateTimeRangeFilter diff --git a/tests/Filter/FilterTest.php b/tests/Filter/FilterTest.php index 62dc3054..c1e33875 100644 --- a/tests/Filter/FilterTest.php +++ b/tests/Filter/FilterTest.php @@ -48,18 +48,18 @@ final class FilterTest extends TestCase public function testFieldDescription(): void { $filter = new TestFilter(); - $this->assertSame(['option1' => 2], $filter->getDefaultOptions()); - $this->assertNull($filter->getOption('1')); + self::assertSame(['option1' => 2], $filter->getDefaultOptions()); + self::assertNull($filter->getOption('1')); $filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); - $this->assertSame(2, $filter->getOption('option1')); - $this->assertNull($filter->getOption('foo')); - $this->assertSame('bar', $filter->getOption('foo', 'bar')); + self::assertSame(2, $filter->getOption('option1')); + self::assertNull($filter->getOption('foo')); + self::assertSame('bar', $filter->getOption('foo', 'bar')); - $this->assertSame('field_name', $filter->getName()); - $this->assertSame(TextType::class, $filter->getFieldType()); - $this->assertSame(['class' => 'FooBar'], $filter->getFieldOptions()); + self::assertSame('field_name', $filter->getName()); + self::assertSame(TextType::class, $filter->getFieldType()); + self::assertSame(['class' => 'FooBar'], $filter->getFieldOptions()); } public function testExceptionOnEmptyFieldName(): void @@ -73,7 +73,7 @@ public function testExceptionOnEmptyFieldName(): void public function testIsActive(): void { $filter = new TestFilter(); - $this->assertFalse($filter->isActive()); + self::assertFalse($filter->isActive()); } public function testUseNameWithParentAssociationMappings(): void @@ -94,13 +94,13 @@ public function testUseNameWithParentAssociationMappings(): void $builder = new ProxyQuery($queryBuilder); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('field') ->with('field.name') ->willReturnSelf(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('equals') ->with('foo'); @@ -121,13 +121,13 @@ public function testUseFieldNameWithoutParentAssociationMappings(): void $builder = new ProxyQuery($queryBuilder); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('field') ->with('field_name') ->willReturnSelf(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('equals') ->with('foo'); diff --git a/tests/Filter/IdFilterTest.php b/tests/Filter/IdFilterTest.php index 57b4ce0e..5ae53e54 100644 --- a/tests/Filter/IdFilterTest.php +++ b/tests/Filter/IdFilterTest.php @@ -30,14 +30,14 @@ public function testEmpty(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->never()) + ->expects(self::never()) ->method('field'); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray([])); - $this->assertFalse($filter->isActive()); + self::assertFalse($filter->isActive()); } public function testItDoesNotApplyWithWrongObjectId(): void @@ -52,7 +52,7 @@ public function testItDoesNotApplyWithWrongObjectId(): void $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray(['value' => 'wrong_object_id', 'type' => null])); - $this->assertFalse($filter->isActive()); + self::assertFalse($filter->isActive()); } /** @@ -67,7 +67,7 @@ public function testDefaultTypeIsEquals(?int $type): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('equals') ->with(new ObjectId('507f1f77bcf86cd799439011')); @@ -75,7 +75,7 @@ public function testDefaultTypeIsEquals(?int $type): void $filter->apply($builder, FilterData::fromArray(['value' => '507f1f77bcf86cd799439011', 'type' => $type])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } /** @@ -96,7 +96,7 @@ public function testNotEquals(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('notEqual') ->with(new ObjectId('507f1f77bcf86cd799439011')); @@ -107,6 +107,6 @@ public function testNotEquals(): void 'value' => '507f1f77bcf86cd799439011', 'type' => EqualOperatorType::TYPE_NOT_EQUAL, ] )); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } } diff --git a/tests/Filter/ModelFilterTest.php b/tests/Filter/ModelFilterTest.php index a7dec216..f832ca47 100644 --- a/tests/Filter/ModelFilterTest.php +++ b/tests/Filter/ModelFilterTest.php @@ -63,14 +63,14 @@ public function testFilterEmpty(): void ]); $this->queryBuilder - ->expects($this->never()) + ->expects(self::never()) ->method('field'); $builder = new ProxyQuery($this->queryBuilder); $filter->apply($builder, FilterData::fromArray([])); - $this->assertFalse($filter->isActive()); + self::assertFalse($filter->isActive()); } public function testFilterArray(): void @@ -87,7 +87,7 @@ public function testFilterArray(): void ]); $this->queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('field') ->with('field._id') ->willReturnSelf(); @@ -96,7 +96,7 @@ public function testFilterArray(): void $otherDocument = new DocumentStub(); $this->queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('in') ->with([new ObjectId($oneDocument->getId()), new ObjectId($otherDocument->getId())]); @@ -107,7 +107,7 @@ public function testFilterArray(): void 'value' => [$oneDocument, $otherDocument], ])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } public function testFilterScalar(): void @@ -124,7 +124,7 @@ public function testFilterScalar(): void ]); $this->queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('field') ->with('field._id') ->willReturnSelf(); @@ -132,7 +132,7 @@ public function testFilterScalar(): void $document1 = new DocumentStub(); $this->queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('equals') ->with(new ObjectId($document1->getId())); @@ -143,7 +143,7 @@ public function testFilterScalar(): void 'value' => $document1, ])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } public function testAssociationWithInvalidMapping(): void @@ -196,7 +196,7 @@ public function testAssociationWithValidMapping(): void 'value' => new DocumentStub(), ])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } public function testAssociationWithValidParentAssociationMappings(): void @@ -233,7 +233,7 @@ public function testAssociationWithValidParentAssociationMappings(): void 'value' => new DocumentStub(), ])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } /** @@ -262,7 +262,7 @@ public function testDifferentIdentifiersBasedOnMapping(string $storeAs, string $ 'value' => new DocumentStub(), ])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } /** @@ -285,7 +285,7 @@ public function testDefaultValues(): void 'field_name' => 'field_name', ]); - $this->assertSame(DocumentType::class, $filter->getFieldType()); - $this->assertSame(EqualOperatorType::class, $filter->getOption('operator_type')); + self::assertSame(DocumentType::class, $filter->getFieldType()); + self::assertSame(EqualOperatorType::class, $filter->getOption('operator_type')); } } diff --git a/tests/Filter/NumberFilterTest.php b/tests/Filter/NumberFilterTest.php index 6cf64520..b919cdf7 100644 --- a/tests/Filter/NumberFilterTest.php +++ b/tests/Filter/NumberFilterTest.php @@ -27,13 +27,13 @@ public function testFilterEmpty(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->never()) + ->expects(self::never()) ->method('field'); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray([])); - $this->assertFalse($filter->isActive()); + self::assertFalse($filter->isActive()); } public function testFilterInvalidOperator(): void @@ -42,14 +42,14 @@ public function testFilterInvalidOperator(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->never()) + ->expects(self::never()) ->method('field'); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray(['type' => 9999999])); - $this->assertFalse($filter->isActive()); + self::assertFalse($filter->isActive()); } /** @@ -63,14 +63,14 @@ public function testFilter(array $data, string $method): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method($method) ->with($data['value']); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray($data)); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } /** @@ -92,7 +92,7 @@ public function testDefaultValues(): void { $filter = $this->createFilter(); - $this->assertSame(NumberType::class, $filter->getFieldType()); + self::assertSame(NumberType::class, $filter->getFieldType()); } private function createFilter(): NumberFilter diff --git a/tests/Filter/StringFilterTest.php b/tests/Filter/StringFilterTest.php index 3f0ce04e..76769911 100644 --- a/tests/Filter/StringFilterTest.php +++ b/tests/Filter/StringFilterTest.php @@ -28,11 +28,11 @@ public function testSearchEnabled(): void { $filter = new StringFilter(); $filter->initialize('field_name', []); - $this->assertTrue($filter->isSearchEnabled()); + self::assertTrue($filter->isSearchEnabled()); $filter = new StringFilter(); $filter->initialize('field_name', ['global_search' => false]); - $this->assertFalse($filter->isSearchEnabled()); + self::assertFalse($filter->isSearchEnabled()); } public function testEmpty(): void @@ -45,14 +45,14 @@ public function testEmpty(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->never()) + ->expects(self::never()) ->method('field'); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray([])); - $this->assertFalse($filter->isActive()); + self::assertFalse($filter->isActive()); } public function testDefaultTypeIsContains(): void @@ -65,14 +65,14 @@ public function testDefaultTypeIsContains(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('equals') ->with(new Regex('asd', 'i')); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray(['value' => 'asd', 'type' => null])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } /** @@ -90,14 +90,14 @@ public function testContains(string $method, int $type, $value): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method($method) ->with($value); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray(['value' => 'asd', 'type' => $type])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } /** @@ -122,14 +122,14 @@ public function testNotContains(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('not') ->with(new Regex('asd', 'i')); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray(['value' => 'asd', 'type' => ContainsOperatorType::TYPE_NOT_CONTAINS])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } public function testEquals(): void @@ -142,14 +142,14 @@ public function testEquals(): void $queryBuilder = $this->getQueryBuilder(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('equals') ->with('asd'); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray(['value' => 'asd', 'type' => ContainsOperatorType::TYPE_EQUAL])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } public function testEqualsWithValidParentAssociationMappings(): void @@ -178,14 +178,14 @@ public function testEqualsWithValidParentAssociationMappings(): void ->willReturnSelf(); $queryBuilder - ->expects($this->once()) + ->expects(self::once()) ->method('equals') ->with('asd'); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray(['type' => ContainsOperatorType::TYPE_EQUAL, 'value' => 'asd'])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } public function testOr(): void @@ -198,18 +198,18 @@ public function testOr(): void $filter->setCondition(Filter::CONDITION_OR); $queryBuilder = $this->getQueryBuilder(); - $queryBuilder->expects($this->once())->method('addOr'); + $queryBuilder->expects(self::once())->method('addOr'); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray(['value' => 'asd', 'type' => ContainsOperatorType::TYPE_CONTAINS])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); $filter->setCondition(Filter::CONDITION_AND); $queryBuilder = $this->getQueryBuilder(); - $queryBuilder->expects($this->never())->method('addOr'); + $queryBuilder->expects(self::never())->method('addOr'); $builder = new ProxyQuery($queryBuilder); $filter->apply($builder, FilterData::fromArray(['value' => 'asd', 'type' => ContainsOperatorType::TYPE_CONTAINS])); - $this->assertTrue($filter->isActive()); + self::assertTrue($filter->isActive()); } public function testDefaultValues(): void @@ -220,6 +220,6 @@ public function testDefaultValues(): void 'format' => '%s', ]); - $this->assertSame(TextType::class, $filter->getFieldType()); + self::assertSame(TextType::class, $filter->getFieldType()); } } diff --git a/tests/Functional/EmbeddedMappingTest.php b/tests/Functional/EmbeddedMappingTest.php index eca6e211..d4eeaacd 100644 --- a/tests/Functional/EmbeddedMappingTest.php +++ b/tests/Functional/EmbeddedMappingTest.php @@ -38,11 +38,11 @@ public function testCreateDocumentWithEmbedded(): void $crawler = $this->client->request(Request::METHOD_GET, '/admin/tests/app/author/create'); $attributeId = $crawler->filter('.author_id')->attr('name'); - $this->assertIsString($attributeId); + self::assertIsString($attributeId); $attributeName = $crawler->filter('.author_name')->attr('name'); - $this->assertIsString($attributeName); + self::assertIsString($attributeName); $attributeAddressStreet = $crawler->filter('.address_street')->attr('name'); - $this->assertIsString($attributeAddressStreet); + self::assertIsString($attributeAddressStreet); $form = $crawler->selectButton('Create and return to list')->form(); $form[$attributeId] = 'author_new_id'; @@ -53,7 +53,7 @@ public function testCreateDocumentWithEmbedded(): void $crawler = $this->client->waitFor('.phone_number_number'); $attributePhoneNumber = $crawler->filter('.phone_number_number')->attr('name'); - $this->assertIsString($attributePhoneNumber); + self::assertIsString($attributePhoneNumber); $form[$attributePhoneNumber] = '333-333-333'; diff --git a/tests/Functional/ReferenceMappingTest.php b/tests/Functional/ReferenceMappingTest.php index e689911c..6d4d6773 100644 --- a/tests/Functional/ReferenceMappingTest.php +++ b/tests/Functional/ReferenceMappingTest.php @@ -24,9 +24,9 @@ public function testCreateDocumentWithReferences(): void $crawler = $this->client->request(Request::METHOD_GET, '/admin/tests/app/book/create'); $attributeId = $crawler->filter('.book_id')->attr('name'); - $this->assertIsString($attributeId); + self::assertIsString($attributeId); $attributeName = $crawler->filter('.book_name')->attr('name'); - $this->assertIsString($attributeName); + self::assertIsString($attributeName); $form = $crawler->selectButton('Create and return to list')->form(); $form[$attributeId] = 'book_new_id'; @@ -51,11 +51,11 @@ public function testCreateDocumentWithReferences(): void private function createAuthorForm(Crawler $crawler): Form { $authorAttributeId = $crawler->filter('.author_id')->attr('name'); - $this->assertIsString($authorAttributeId); + self::assertIsString($authorAttributeId); $authorAttributeName = $crawler->filter('.author_name')->attr('name'); - $this->assertIsString($authorAttributeName); + self::assertIsString($authorAttributeName); $addressAttributeName = $crawler->filter('.address_street')->attr('name'); - $this->assertIsString($addressAttributeName); + self::assertIsString($addressAttributeName); $authorForm = $crawler->filter('.modal-content button[name="btn_create"]')->form(); $authorForm[$authorAttributeId] = 'new_author_id'; diff --git a/tests/Model/ModelManagerTest.php b/tests/Model/ModelManagerTest.php index e5099d2f..9a018bfa 100644 --- a/tests/Model/ModelManagerTest.php +++ b/tests/Model/ModelManagerTest.php @@ -67,7 +67,7 @@ public function testGetIdentifierFieldNames(): void ->method('getClassMetadata') ->willReturn($this->getMetadataForDocumentWithAnnotations($documentWithReferencesClass)); - $this->assertSame(['id'], $modelManager->getIdentifierFieldNames($documentWithReferencesClass)); + self::assertSame(['id'], $modelManager->getIdentifierFieldNames($documentWithReferencesClass)); } public function testReverseTransformWithSetter(): void @@ -86,9 +86,9 @@ public function testReverseTransformWithSetter(): void ] ); - $this->assertSame(42, $testDocument->getSchmeckles()); - $this->assertSame('hello', $testDocument->getMultiWordProperty()); - $this->assertTrue($testDocument->schwifty); + self::assertSame(42, $testDocument->getSchmeckles()); + self::assertSame('hello', $testDocument->getMultiWordProperty()); + self::assertTrue($testDocument->schwifty); } public function testReverseTransformFailsWithPrivateSetter(): void @@ -148,7 +148,7 @@ public function testSupportsQuery(bool $expected, object $object): void { $modelManager = new ModelManager($this->registry, $this->propertyAccessor); - $this->assertSame($expected, $modelManager->supportsQuery($object)); + self::assertSame($expected, $modelManager->supportsQuery($object)); } /** @@ -173,11 +173,11 @@ private function createModelManagerForClass(string $class): ModelManager $classMetadata = $this->getMetadataForDocumentWithAnnotations($class); - $modelManager->expects($this->once()) + $modelManager->expects(self::once()) ->method('getClassMetadata') ->with($class) ->willReturn($classMetadata); - $registry->expects($this->once()) + $registry->expects(self::once()) ->method('getManagerForClass') ->with($class) ->willReturn($modelManager); diff --git a/tests/SonataDoctrineMongoDBAdminBundleTest.php b/tests/SonataDoctrineMongoDBAdminBundleTest.php index 8b2ac4ca..9ef18db5 100644 --- a/tests/SonataDoctrineMongoDBAdminBundleTest.php +++ b/tests/SonataDoctrineMongoDBAdminBundleTest.php @@ -25,9 +25,9 @@ public function testBuild(): void { $containerBuilder = $this->createMock(ContainerBuilder::class); - $containerBuilder->expects($this->exactly(2))->method('addCompilerPass')->withConsecutive( - [$this->isInstanceOf(AddGuesserCompilerPass::class)], - [$this->isInstanceOf(AddTemplatesCompilerPass::class)], + $containerBuilder->expects(self::exactly(2))->method('addCompilerPass')->withConsecutive( + [self::isInstanceOf(AddGuesserCompilerPass::class)], + [self::isInstanceOf(AddTemplatesCompilerPass::class)], ); $bundle = new SonataDoctrineMongoDBAdminBundle();