From 909d0eed30acaafddf4e7bcf77cdaa74b61a3e50 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 14:22:42 +0200 Subject: [PATCH] Update rector/rector requirement from ^0.18.6 to ^1.0.3 (#154) * Update rector/rector requirement from ^0.18.6 to ^1.0.3 Updates the requirements on [rector/rector](https://github.com/rectorphp/rector) to permit the latest version. - [Release notes](https://github.com/rectorphp/rector/releases) - [Commits](https://github.com/rectorphp/rector/compare/0.18.6...1.0.3) --- updated-dependencies: - dependency-name: rector/rector dependency-type: direct:development ... Signed-off-by: dependabot[bot] * Migrate Rector config after 1.0 upgrade * Re-apply Rector after upgrade * Fix PHPStan consequent issues --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Alessandro Lai --- composer.json | 2 +- phpstan-baseline.neon | 25 --------- rector.php | 34 ++++++----- src/Capsule/Client.php | 6 +- src/Capsule/Collection.php | 11 ++-- src/Capsule/Database.php | 9 +-- src/Command/AbstractCommand.php | 3 +- src/Command/LoadFixturesCommand.php | 3 +- src/Controller/ProfilerController.php | 9 +-- src/DataCollector/MongoDbDataCollector.php | 3 +- src/DataCollector/MongoQuerySerializer.php | 8 +-- src/DependencyInjection/Configuration.php | 20 +++---- .../MongoDbBundleExtension.php | 5 +- src/Event/Listener/DataCollectorListener.php | 7 +-- .../AbstractContainerAwareFixture.php | 5 +- src/Fixtures/MongoFixturesLoader.php | 14 ++--- src/Models/ClientConfiguration.php | 30 ++++------ src/Models/Query.php | 56 ++++++------------- src/Services/ClientRegistry.php | 25 +++------ src/Services/ConnectionFactory.php | 3 +- src/Services/Explain/ExplainQueryService.php | 3 +- src/Services/Loggers/MongoQueryLogger.php | 9 ++- src/Twig/FacileMongoDbBundleExtension.php | 8 +-- tests/Fixtures/DataFixtures/TestFixtures.php | 5 +- .../DataFixtures/TestOrderedMongoFixtures.php | 2 +- .../TestOrderedMongoFixtures1.php | 2 +- .../TestOrderedMongoFixtures2.php | 5 +- tests/Functional/AppTestCase.php | 5 +- tests/Functional/Capsule/CollectionTest.php | 35 ++++++------ .../Command/AbstractCommandTest.php | 8 +-- .../Command/DropCollectionCommandTest.php | 4 +- .../Command/DropDatabaseCommandTest.php | 4 +- .../Command/LoadFixturesCommandTest.php | 8 +-- .../Controller/ProfilerControllerTest.php | 7 ++- .../MongoDbBundleExtensionTest.php | 10 ++-- .../Explain/ExplainQueryServiceTest.php | 4 +- tests/Functional/TestApp/TestKernel.php | 2 +- tests/Unit/Capsule/ClientTest.php | 7 ++- tests/Unit/Capsule/DatabaseTest.php | 3 +- .../MongoQuerySerializerTest.php | 9 +-- .../DependencyInjection/ConfigurationTest.php | 14 ++--- .../Listener/DataCollectorListenerTest.php | 4 +- tests/Unit/Fixtures/FixtureSorterTest.php | 27 ++++----- tests/Unit/Models/ClientConfigurationTest.php | 8 +-- tests/Unit/MongoBundleTest.php | 2 +- tests/Unit/Services/ClientRegistryTest.php | 9 +-- .../Explain/ExplainCommandBuilderTest.php | 16 +++--- .../Services/Loggers/Model/LogEventTest.php | 2 +- .../Unit/Services/Loggers/MongoLoggerTest.php | 4 +- .../Twig/FacileMongoDbBundleExtensionTest.php | 6 +- 50 files changed, 216 insertions(+), 294 deletions(-) diff --git a/composer.json b/composer.json index 86d5a990..39ca033a 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "phpstan/extension-installer": "1.3.1", "jangregor/phpstan-prophecy": "1.0.1", "phpspec/prophecy": "^1.17", - "rector/rector": "^0.18.6", + "rector/rector": "^1.0.3", "phpspec/prophecy-phpunit": "^2.0" }, "minimum-stability": "stable", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ef89a961..f9602656 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,15 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Property Facile\\\\MongoDbBundle\\\\Controller\\\\ProfilerController\\:\\:\\$container \\(Symfony\\\\Component\\\\DependencyInjection\\\\Container\\) does not accept Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\|null\\.$#" - count: 1 - path: src/Controller/ProfilerController.php - - - - message: "#^Method Facile\\\\MongoDbBundle\\\\DataCollector\\\\MongoQuerySerializer\\:\\:prepareUnserializableData\\(\\) never returns object so it can be removed from the return type\\.$#" - count: 1 - path: src/DataCollector/MongoQuerySerializer.php - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#" count: 7 @@ -50,31 +40,16 @@ parameters: count: 1 path: src/Twig/FacileMongoDbBundleExtension.php - - - message: "#^Method Facile\\\\MongoDbBundle\\\\Tests\\\\Fixtures\\\\DataFixtures\\\\TestFixtures\\:\\:loadData\\(\\) should return array but return statement is missing\\.$#" - count: 1 - path: tests/Fixtures/DataFixtures/TestFixtures.php - - message: "#^Method Facile\\\\MongoDbBundle\\\\Tests\\\\Fixtures\\\\DataFixtures\\\\TestFixtures\\:\\:loadIndexes\\(\\) should return array but return statement is missing\\.$#" count: 1 path: tests/Fixtures/DataFixtures/TestFixtures.php - - - message: "#^Method Facile\\\\MongoDbBundle\\\\Tests\\\\Fixtures\\\\DataFixtures\\\\TestOrderedMongoFixtures2\\:\\:loadData\\(\\) should return array but return statement is missing\\.$#" - count: 1 - path: tests/Fixtures/DataFixtures/TestOrderedMongoFixtures2.php - - message: "#^Method Facile\\\\MongoDbBundle\\\\Tests\\\\Fixtures\\\\DataFixtures\\\\TestOrderedMongoFixtures2\\:\\:loadIndexes\\(\\) should return array but return statement is missing\\.$#" count: 1 path: tests/Fixtures/DataFixtures/TestOrderedMongoFixtures2.php - - - message: "#^Property Facile\\\\MongoDbBundle\\\\Tests\\\\Functional\\\\AppTestCase\\:\\:\\$application \\(Symfony\\\\Bundle\\\\FrameworkBundle\\\\Console\\\\Application\\) does not accept null\\.$#" - count: 1 - path: tests/Functional/AppTestCase.php - - message: "#^Access to an undefined property MongoDB\\\\Model\\\\BSONDocument\\:\\:\\$fqcn\\.$#" count: 1 diff --git a/rector.php b/rector.php index 321b6225..0d1cab1b 100644 --- a/rector.php +++ b/rector.php @@ -4,22 +4,30 @@ use Rector\Config\RectorConfig; use Rector\PHPUnit\PHPUnit100\Rector\Class_\AddProphecyTraitRector; -use Rector\PHPUnit\Set\PHPUnitLevelSetList; use Rector\PHPUnit\Set\PHPUnitSetList; -use Rector\Symfony\Set\SymfonyLevelSetList; +use Rector\Symfony\Set\SymfonySetList; -return static function (RectorConfig $rectorConfig): void { - $rectorConfig->paths([ +return RectorConfig::configure() + ->withPaths([ __DIR__ . '/src', __DIR__ . '/tests', - ]); - - // register a single rule - $rectorConfig->rule(AddProphecyTraitRector::class); - - $rectorConfig->sets([ + ]) + ->withPhpSets() + ->withPreparedSets( + true, + true, + false, + true + ) + ->withImportNames( + true, + true, + false + ) + ->withRules([ + AddProphecyTraitRector::class, + ]) + ->withSets([ PHPUnitSetList::PHPUNIT_90, - PHPUnitLevelSetList::UP_TO_PHPUNIT_90, - SymfonyLevelSetList::UP_TO_SYMFONY_44 + SymfonySetList::SYMFONY_44, ]); -}; diff --git a/src/Capsule/Client.php b/src/Capsule/Client.php index 1e18d27a..86b46f1f 100644 --- a/src/Capsule/Client.php +++ b/src/Capsule/Client.php @@ -14,11 +14,9 @@ */ final class Client extends MongoClient { - /** @var EventDispatcherInterface */ - private $eventDispatcher; + private EventDispatcherInterface $eventDispatcher; - /** @var string */ - private $clientName; + private string $clientName; /** * Client constructor. diff --git a/src/Capsule/Collection.php b/src/Capsule/Collection.php index 3a1a7eb4..f49311c9 100644 --- a/src/Capsule/Collection.php +++ b/src/Capsule/Collection.php @@ -16,14 +16,11 @@ */ final class Collection extends MongoCollection { - /** @var EventDispatcherInterface */ - private $eventDispatcher; + private EventDispatcherInterface $eventDispatcher; - /** @var string */ - private $clientName; + private string $clientName; - /** @var string */ - private $databaseName; + private string $databaseName; public function __construct( Manager $manager, @@ -225,7 +222,7 @@ private function translateReadPreference(ReadPreference $readPreference): string } } - private function notifyQueryExecution(Query $queryLog) + private function notifyQueryExecution(Query $queryLog): void { $queryLog->setExecutionTime(microtime(true) - $queryLog->getStart()); diff --git a/src/Capsule/Database.php b/src/Capsule/Database.php index fc6a2f5b..c531b492 100644 --- a/src/Capsule/Database.php +++ b/src/Capsule/Database.php @@ -15,14 +15,11 @@ */ final class Database extends MongoDatabase { - /** @var EventDispatcherInterface */ - private $eventDispatcher; + private EventDispatcherInterface $eventDispatcher; - /** @var string */ - private $clientName; + private string $clientName; - /** @var string */ - private $databaseName; + private string $databaseName; /** * Database constructor. diff --git a/src/Command/AbstractCommand.php b/src/Command/AbstractCommand.php index 7a60a837..4314534c 100644 --- a/src/Command/AbstractCommand.php +++ b/src/Command/AbstractCommand.php @@ -23,8 +23,7 @@ abstract class AbstractCommand extends Command /** @var Connection */ protected $connection; - /** @var ContainerInterface */ - private $container; + private ContainerInterface $container; /** * AbstractCommand constructor. diff --git a/src/Command/LoadFixturesCommand.php b/src/Command/LoadFixturesCommand.php index 4b0f75d0..01246113 100644 --- a/src/Command/LoadFixturesCommand.php +++ b/src/Command/LoadFixturesCommand.php @@ -18,8 +18,7 @@ */ class LoadFixturesCommand extends AbstractCommand { - /** @var MongoFixturesLoader */ - private $loader; + private ?MongoFixturesLoader $loader = null; /** * @inheritDoc diff --git a/src/Controller/ProfilerController.php b/src/Controller/ProfilerController.php index 707eafde..b5a7b025 100644 --- a/src/Controller/ProfilerController.php +++ b/src/Controller/ProfilerController.php @@ -15,25 +15,22 @@ class ProfilerController implements ContainerAwareInterface { - /** @var Container */ - private $container; + private ?ContainerInterface $container = null; /** * Sets the container. * * @param ContainerInterface|null $container A ContainerInterface instance or null */ - public function setContainer(ContainerInterface $container = null) + public function setContainer(ContainerInterface $container = null): void { $this->container = $container; } /** * @throws \Exception - * - * @return JsonResponse */ - public function explainAction($token, $queryNumber) + public function explainAction(string $token, $queryNumber): JsonResponse { /** @var Profiler $profiler */ $profiler = $this->container->get('profiler'); diff --git a/src/DataCollector/MongoDbDataCollector.php b/src/DataCollector/MongoDbDataCollector.php index 5d305e6e..43e0d73c 100644 --- a/src/DataCollector/MongoDbDataCollector.php +++ b/src/DataCollector/MongoDbDataCollector.php @@ -23,8 +23,7 @@ class MongoDbDataCollector extends DataCollector public const TIME_KEYWORD = 'totalTime'; - /** @var DataCollectorLoggerInterface */ - private $logger; + private ?DataCollectorLoggerInterface $logger = null; public function __construct() { diff --git a/src/DataCollector/MongoQuerySerializer.php b/src/DataCollector/MongoQuerySerializer.php index a46b0d88..01096a2d 100644 --- a/src/DataCollector/MongoQuerySerializer.php +++ b/src/DataCollector/MongoQuerySerializer.php @@ -12,7 +12,7 @@ */ final class MongoQuerySerializer { - public static function serialize(Query $query) + public static function serialize(Query $query): void { $query->setFilters(self::prepareUnserializableData($query->getFilters())); $query->setData(self::prepareUnserializableData($query->getData())); @@ -22,9 +22,9 @@ public static function serialize(Query $query) /** * @param array|object $data * - * @return array|object + * @return mixed[] */ - private static function prepareUnserializableData($data) + private static function prepareUnserializableData($data): array { if ($data instanceof Serializable) { $data = $data->bsonSerialize(); @@ -50,7 +50,7 @@ public static function prepareItemData($item) } if (\is_array($item)) { - return self::prepareUnserializableData((array) $item); + return self::prepareUnserializableData($item); } if (\is_object($item)) { diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 64a20e60..c690fb26 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -23,15 +23,15 @@ public function getConfigTreeBuilder(): TreeBuilder $treeBuilder = new TreeBuilder('mongo_db_bundle'); $rootBuilder = $treeBuilder->getRootNode(); - self::addDataCollection($rootBuilder->children()); - self::addClients($rootBuilder->children()); - self::addConnections($rootBuilder->children()); - self::addDriversOption($rootBuilder->children()); + $this->addDataCollection($rootBuilder->children()); + $this->addClients($rootBuilder->children()); + $this->addConnections($rootBuilder->children()); + $this->addDriversOption($rootBuilder->children()); return $treeBuilder; } - private static function addDataCollection(NodeBuilder $builder): void + private function addDataCollection(NodeBuilder $builder): void { $builder ->booleanNode('data_collection') @@ -39,7 +39,7 @@ private static function addDataCollection(NodeBuilder $builder): void ->info('Disables Data Collection if needed'); } - private static function addClients(NodeBuilder $builder): void + private function addClients(NodeBuilder $builder): void { $clientsBuilder = $builder ->arrayNode('clients') @@ -49,7 +49,7 @@ private static function addClients(NodeBuilder $builder): void ->prototype('array') ->children(); - self::addClientsHosts($clientsBuilder); + $this->addClientsHosts($clientsBuilder); $clientsBuilder ->scalarNode('uri') @@ -89,7 +89,7 @@ private static function addClients(NodeBuilder $builder): void ->defaultNull(); } - private static function addClientsHosts(NodeBuilder $builder): void + private function addClientsHosts(NodeBuilder $builder): void { $hostsBuilder = $builder ->arrayNode('hosts') @@ -106,13 +106,13 @@ private static function addClientsHosts(NodeBuilder $builder): void ->defaultValue(27_017); } - private static function addDriversOption(NodeBuilder $builder): void + private function addDriversOption(NodeBuilder $builder): void { $builder ->scalarNode('driverOptions'); } - private static function addConnections(NodeBuilder $builder): void + private function addConnections(NodeBuilder $builder): void { $connectionBuilder = $builder ->arrayNode('connections') diff --git a/src/DependencyInjection/MongoDbBundleExtension.php b/src/DependencyInjection/MongoDbBundleExtension.php index 31beb449..84620617 100644 --- a/src/DependencyInjection/MongoDbBundleExtension.php +++ b/src/DependencyInjection/MongoDbBundleExtension.php @@ -23,8 +23,7 @@ */ final class MongoDbBundleExtension extends Extension { - /** @var ContainerBuilder */ - private $containerBuilder; + private ?ContainerBuilder $containerBuilder = null; public function load(array $configs, ContainerBuilder $container): void { @@ -76,7 +75,7 @@ private function defineConnectionFactory(): void $this->containerBuilder->setDefinition('mongo.connection_factory', $factoryDefinition); } - private function defineConnections(array $connections) + private function defineConnections(array $connections): void { foreach ($connections as $name => $conf) { $connectionDefinition = new Definition( diff --git a/src/Event/Listener/DataCollectorListener.php b/src/Event/Listener/DataCollectorListener.php index fbae4167..7c62b2f4 100644 --- a/src/Event/Listener/DataCollectorListener.php +++ b/src/Event/Listener/DataCollectorListener.php @@ -15,20 +15,19 @@ */ final class DataCollectorListener { - /** @var DataCollectorLoggerInterface */ - private $logger; + private DataCollectorLoggerInterface $logger; public function __construct(DataCollectorLoggerInterface $logger) { $this->logger = $logger; } - public function onConnectionClientCreated(ConnectionEvent $event) + public function onConnectionClientCreated(ConnectionEvent $event): void { $this->logger->addConnection($event->getClientName()); } - public function onQueryExecuted(QueryEvent $event) + public function onQueryExecuted(QueryEvent $event): void { $this->logger->logQuery($event->getQueryLog()); } diff --git a/src/Fixtures/AbstractContainerAwareFixture.php b/src/Fixtures/AbstractContainerAwareFixture.php index 0fd31438..ee446243 100644 --- a/src/Fixtures/AbstractContainerAwareFixture.php +++ b/src/Fixtures/AbstractContainerAwareFixture.php @@ -8,15 +8,14 @@ abstract class AbstractContainerAwareFixture { - /** @var ContainerInterface */ - private $container; + private ContainerInterface $container; protected function getContainer(): ContainerInterface { return $this->container; } - public function setContainer(ContainerInterface $container) + public function setContainer(ContainerInterface $container): void { $this->container = $container; } diff --git a/src/Fixtures/MongoFixturesLoader.php b/src/Fixtures/MongoFixturesLoader.php index 86ec9f40..b4d75bb2 100644 --- a/src/Fixtures/MongoFixturesLoader.php +++ b/src/Fixtures/MongoFixturesLoader.php @@ -9,10 +9,9 @@ final class MongoFixturesLoader { /** @var array|MongoFixtureInterface[] */ - private $loadedClasses; + private ?array $loadedClasses = null; - /** @var ContainerInterface */ - private $container; + private ContainerInterface $container; public function __construct(ContainerInterface $container) { @@ -75,10 +74,7 @@ function ($classList, string $className) use ($includedFiles) { ); } - /** - * @param mixed $instance - */ - private function buildFixture($instance): MongoFixtureInterface + private function buildFixture(object $instance): MongoFixtureInterface { if ($instance instanceof AbstractContainerAwareFixture) { $instance->setContainer($this->container); @@ -87,7 +83,7 @@ private function buildFixture($instance): MongoFixtureInterface return $instance; } - public function addInstance(MongoFixtureInterface $list) + public function addInstance(MongoFixtureInterface $list): void { $listClass = \get_class($list); @@ -113,7 +109,7 @@ public function loadFromFile(string $fileName) /** * @return array|MongoFixtureInterface[] */ - public function getLoadedClasses() + public function getLoadedClasses(): ?array { return $this->loadedClasses; } diff --git a/src/Models/ClientConfiguration.php b/src/Models/ClientConfiguration.php index d4aab176..1c694b66 100644 --- a/src/Models/ClientConfiguration.php +++ b/src/Models/ClientConfiguration.php @@ -11,23 +11,17 @@ */ final class ClientConfiguration { - /** @var string */ - private $uri; + private string $uri; - /** @var string */ - private $username; + private string $username; - /** @var string */ - private $password; + private string $password; - /** @var array */ - private $options; + private array $options; - /** @var null|string */ - private $authSource; + private ?string $authSource; - /** @var array */ - private $driverOptions; + private array $driverOptions; public function __construct( string $uri, @@ -60,10 +54,7 @@ public function getPassword(): string return $this->password; } - /** - * @return null|string - */ - public function getAuthSource() + public function getAuthSource(): ?string { return $this->authSource; } @@ -90,9 +81,10 @@ private function cleanOptions(array $options): array { return array_filter( $options, - function ($value): bool { - return ! empty($value) || \is_int($value) || \is_bool($value) || \is_float($value); - } + fn($value): bool => ! empty($value) + || \is_int($value) + || \is_bool($value) + || \is_float($value) ); } } diff --git a/src/Models/Query.php b/src/Models/Query.php index 4f4f6d8f..f15c0202 100644 --- a/src/Models/Query.php +++ b/src/Models/Query.php @@ -11,51 +11,31 @@ */ final class Query { - /** @var float */ - private $start; + private float $start; - /** @var string */ - private $method; + private string $method = 'undefined'; - /** @var string */ - private $collection; + private string $collection = 'undefined'; - /** @var array */ - private $filters; + private array $filters = []; /** @var array|object */ - private $data; + private $data = []; - /** @var array */ - private $options; + private array $options = []; /** @var float */ - private $executionTime; + private $executionTime = 0; - /** @var string */ - private $readPreference; + private string $readPreference = 'undefined'; - /** @var string */ - private $client; + private string $client = 'undefined'; - /** @var string */ - private $database; + private string $database = 'undefined'; - /** - * Query constructor. - */ public function __construct() { $this->start = microtime(true); - $this->client = 'undefined'; - $this->database = 'undefined'; - $this->collection = 'undefined'; - $this->method = 'undefined'; - $this->filters = []; - $this->data = []; - $this->options = []; - $this->executionTime = 0; - $this->readPreference = 'undefined'; } public function getStart(): float @@ -68,7 +48,7 @@ public function getCollection(): string return $this->collection; } - public function setCollection(string $collection) + public function setCollection(string $collection): void { $this->collection = $collection; } @@ -78,7 +58,7 @@ public function getMethod(): string return $this->method; } - public function setMethod(string $method) + public function setMethod(string $method): void { $this->method = $method; } @@ -91,7 +71,7 @@ public function getFilters(): array /** * @param array|object $filters */ - public function setFilters($filters) + public function setFilters($filters): void { $this->filters = (array) ($filters ?? []); } @@ -117,7 +97,7 @@ public function getOptions(): array return $this->options; } - public function setOptions(array $options) + public function setOptions(array $options): void { $this->options = $options; } @@ -127,7 +107,7 @@ public function getExecutionTime(): float return $this->executionTime; } - public function setExecutionTime(float $executionTime) + public function setExecutionTime(float $executionTime): void { $this->executionTime = $executionTime; } @@ -137,7 +117,7 @@ public function getReadPreference(): string return $this->readPreference; } - public function setReadPreference(string $readPreference) + public function setReadPreference(string $readPreference): void { $this->readPreference = $readPreference; } @@ -147,7 +127,7 @@ public function getClient(): string return $this->client; } - public function setClient(string $client) + public function setClient(string $client): void { $this->client = $client; } @@ -157,7 +137,7 @@ public function getDatabase(): string return $this->database; } - public function setDatabase(string $database) + public function setDatabase(string $database): void { $this->database = $database; } diff --git a/src/Services/ClientRegistry.php b/src/Services/ClientRegistry.php index 3c923bae..9ed6088d 100644 --- a/src/Services/ClientRegistry.php +++ b/src/Services/ClientRegistry.php @@ -19,27 +19,22 @@ final class ClientRegistry { /** @var Client[] */ - private $clients; + private array $clients = []; /** @var ClientConfiguration[] */ - private $configurations; + private array $configurations = []; - /** @var bool */ - private $debug; + private bool $debug; - /** @var EventDispatcherInterface */ - private $eventDispatcher; + private EventDispatcherInterface $eventDispatcher; - /** @var DriverOptionsInterface */ - private $driverOptionsService; + private ?DriverOptionsInterface $driverOptionsService; public function __construct( EventDispatcherInterface $eventDispatcher, bool $debug, ?DriverOptionsInterface $driverOptionsService ) { - $this->clients = []; - $this->configurations = []; $this->debug = $debug; $this->eventDispatcher = $eventDispatcher; $this->driverOptionsService = $driverOptionsService; @@ -55,7 +50,7 @@ public function addClientsConfigurations(array $configurations): void private function buildClientConfiguration(array $conf): ClientConfiguration { if (! $conf['uri']) { - $conf['uri'] = self::buildConnectionUri($conf['hosts']); + $conf['uri'] = $this->buildConnectionUri($conf['hosts']); } $conf['driverOptions'] = []; @@ -78,14 +73,12 @@ private function buildClientConfiguration(array $conf): ClientConfiguration ); } - private static function buildConnectionUri(array $hosts): string + private function buildConnectionUri(array $hosts): string { return 'mongodb://' . implode( ',', array_map( - static function (array $host): string { - return sprintf('%s:%d', $host['host'], $host['port']); - }, + static fn(array $host): string => sprintf('%s:%d', $host['host'], $host['port']), $hosts ) ); @@ -123,7 +116,7 @@ public function getClient(string $name, ?string $databaseName = null): Client private function buildClient(string $clientName, string $uri, array $options, array $driverOptions): Client { - if (true === $this->debug) { + if ($this->debug) { return new BundleClient($uri, $options, $driverOptions, $clientName, $this->eventDispatcher); } diff --git a/src/Services/ConnectionFactory.php b/src/Services/ConnectionFactory.php index 83fc1604..488d13ab 100644 --- a/src/Services/ConnectionFactory.php +++ b/src/Services/ConnectionFactory.php @@ -13,8 +13,7 @@ */ final class ConnectionFactory { - /** @var ClientRegistry */ - private $clientRegistry; + private ClientRegistry $clientRegistry; public function __construct(ClientRegistry $clientRegistry) { diff --git a/src/Services/Explain/ExplainQueryService.php b/src/Services/Explain/ExplainQueryService.php index b3ef09e3..a52119d3 100644 --- a/src/Services/Explain/ExplainQueryService.php +++ b/src/Services/Explain/ExplainQueryService.php @@ -27,8 +27,7 @@ class ExplainQueryService 'aggregate', ]; - /** @var ClientRegistry */ - private $clientRegistry; + private ClientRegistry $clientRegistry; /** * Constructs a explain command. diff --git a/src/Services/Loggers/MongoQueryLogger.php b/src/Services/Loggers/MongoQueryLogger.php index e17e2254..5f977dcd 100644 --- a/src/Services/Loggers/MongoQueryLogger.php +++ b/src/Services/Loggers/MongoQueryLogger.php @@ -9,10 +9,10 @@ class MongoQueryLogger implements DataCollectorLoggerInterface { /** @var \SplQueue|Query[] */ - private $logs; + private \SplQueue $logs; /** @var array|string[] */ - private $connections; + private array $connections = []; /** * MongoQueryLogger constructor. @@ -20,10 +20,9 @@ class MongoQueryLogger implements DataCollectorLoggerInterface public function __construct() { $this->logs = new \SplQueue(); - $this->connections = []; } - public function addConnection(string $connection) + public function addConnection(string $connection): void { $this->connections[] = $connection; } @@ -36,7 +35,7 @@ public function getConnections(): array return $this->connections; } - public function logQuery(Query $event) + public function logQuery(Query $event): void { $this->logs->enqueue($event); } diff --git a/src/Twig/FacileMongoDbBundleExtension.php b/src/Twig/FacileMongoDbBundleExtension.php index a50e9d43..348070d9 100644 --- a/src/Twig/FacileMongoDbBundleExtension.php +++ b/src/Twig/FacileMongoDbBundleExtension.php @@ -8,12 +8,12 @@ use Twig\Extension\AbstractExtension; use Twig\TwigFunction; -if (! class_exists('\Twig\Extension\AbstractExtension')) { - class_alias(\Twig_Extension::class, '\Twig\Extension\AbstractExtension'); +if (! class_exists(AbstractExtension::class)) { + class_alias(\Twig_Extension::class, AbstractExtension::class); } -if (! class_exists('\Twig\TwigFunction')) { - class_alias(\Twig_Function::class, '\Twig\TwigFunction'); +if (! class_exists(TwigFunction::class)) { + class_alias(\Twig_Function::class, TwigFunction::class); } class FacileMongoDbBundleExtension extends AbstractExtension diff --git a/tests/Fixtures/DataFixtures/TestFixtures.php b/tests/Fixtures/DataFixtures/TestFixtures.php index 872b378c..64a2dd20 100644 --- a/tests/Fixtures/DataFixtures/TestFixtures.php +++ b/tests/Fixtures/DataFixtures/TestFixtures.php @@ -10,10 +10,7 @@ class TestFixtures extends AbstractContainerAwareFixture implements MongoFixtureInterface { - /** - * @return array - */ - public function loadData() + public function loadData(): void { $doc = [ 'type' => 'fixture', diff --git a/tests/Fixtures/DataFixtures/TestOrderedMongoFixtures.php b/tests/Fixtures/DataFixtures/TestOrderedMongoFixtures.php index f8f04db4..df707220 100644 --- a/tests/Fixtures/DataFixtures/TestOrderedMongoFixtures.php +++ b/tests/Fixtures/DataFixtures/TestOrderedMongoFixtures.php @@ -11,7 +11,7 @@ class TestOrderedMongoFixtures extends AbstractContainerAwareFixture implements MongoFixtureInterface, OrderedFixtureInterface { - public function loadData() + public function loadData(): void { $doc = [ 'type' => 'fixture', diff --git a/tests/Fixtures/DataFixtures/TestOrderedMongoFixtures1.php b/tests/Fixtures/DataFixtures/TestOrderedMongoFixtures1.php index 85633e2d..cfed5943 100644 --- a/tests/Fixtures/DataFixtures/TestOrderedMongoFixtures1.php +++ b/tests/Fixtures/DataFixtures/TestOrderedMongoFixtures1.php @@ -11,7 +11,7 @@ class TestOrderedMongoFixtures1 extends AbstractContainerAwareFixture implements MongoFixtureInterface, OrderedFixtureInterface { - public function loadData() + public function loadData(): void { $doc = [ 'type' => 'fixture', diff --git a/tests/Fixtures/DataFixtures/TestOrderedMongoFixtures2.php b/tests/Fixtures/DataFixtures/TestOrderedMongoFixtures2.php index 91194e90..40196317 100644 --- a/tests/Fixtures/DataFixtures/TestOrderedMongoFixtures2.php +++ b/tests/Fixtures/DataFixtures/TestOrderedMongoFixtures2.php @@ -10,10 +10,7 @@ class TestOrderedMongoFixtures2 extends AbstractContainerAwareFixture implements MongoFixtureInterface { - /** - * @return array - */ - public function loadData() + public function loadData(): void { $doc = [ 'type' => 'fixture', diff --git a/tests/Functional/AppTestCase.php b/tests/Functional/AppTestCase.php index e46f52f1..f5485520 100644 --- a/tests/Functional/AppTestCase.php +++ b/tests/Functional/AppTestCase.php @@ -11,10 +11,9 @@ class AppTestCase extends TestCase { - /** @var Application */ - private $application; + private ?Application $application = null; - private $env = 'test'; + private string $env = 'test'; protected function setUp(): void { diff --git a/tests/Functional/Capsule/CollectionTest.php b/tests/Functional/Capsule/CollectionTest.php index eb0bb234..69f4bf98 100644 --- a/tests/Functional/Capsule/CollectionTest.php +++ b/tests/Functional/Capsule/CollectionTest.php @@ -4,6 +4,9 @@ namespace Facile\MongoDbBundle\Tests\Functional\Capsule; +use Prophecy\PhpUnit\ProphecyTrait; +use Facile\MongoDbBundle\Services\ClientRegistry; +use MongoDB\Client; use Facile\MongoDbBundle\Capsule\Collection; use Facile\MongoDbBundle\Event\QueryEvent; use Facile\MongoDbBundle\Tests\Functional\AppTestCase; @@ -13,19 +16,19 @@ class CollectionTest extends AppTestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; private function getManager(): Manager { - /** @var \Facile\MongoDbBundle\Services\ClientRegistry $reg */ + /** @var ClientRegistry $reg */ $reg = $this->getContainer()->get('mongo.client_registry'); - /** @var \MongoDB\Client $client */ + /** @var Client $client */ $client = $reg->getClient('test_client', 'testdb'); return $client->__debugInfo()['manager']; } - public function test_construction() + public function test_construction(): void { $manager = $this->getManager(); $ev = $this->prophesize(EventDispatcherInterface::class); @@ -35,7 +38,7 @@ public function test_construction() self::assertInstanceOf(\MongoDB\Collection::class, $coll); } - public function test_insertOne() + public function test_insertOne(): void { $manager = $this->getManager(); $ev = $this->prophesize(EventDispatcherInterface::class); @@ -46,7 +49,7 @@ public function test_insertOne() $coll->insertOne(['test' => 1]); } - public function test_updateOne() + public function test_updateOne(): void { $manager = $this->getManager(); $ev = $this->prophesize(EventDispatcherInterface::class); @@ -57,7 +60,7 @@ public function test_updateOne() $coll->updateOne(['filter' => 1], ['$set' => ['testField' => 1]]); } - public function test_count() + public function test_count(): void { $manager = $this->getManager(); $ev = $this->prophesize(EventDispatcherInterface::class); @@ -68,7 +71,7 @@ public function test_count() $coll->count(['test' => 1]); } - public function test_find() + public function test_find(): void { $manager = $this->getManager(); $ev = $this->prophesize(EventDispatcherInterface::class); @@ -79,7 +82,7 @@ public function test_find() $coll->find([]); } - public function test_findOne() + public function test_findOne(): void { $manager = $this->getManager(); $ev = $this->prophesize(EventDispatcherInterface::class); @@ -90,7 +93,7 @@ public function test_findOne() $coll->findOne([]); } - public function test_findOneAndUpdate() + public function test_findOneAndUpdate(): void { $manager = $this->getManager(); $ev = $this->prophesize(EventDispatcherInterface::class); @@ -101,7 +104,7 @@ public function test_findOneAndUpdate() $coll->findOneAndUpdate([], ['$set' => ['country' => 'us']]); } - public function test_findOneAndDelete() + public function test_findOneAndDelete(): void { $manager = $this->getManager(); $ev = $this->prophesize(EventDispatcherInterface::class); @@ -112,7 +115,7 @@ public function test_findOneAndDelete() $coll->findOneAndDelete([]); } - public function test_deleteOne() + public function test_deleteOne(): void { $manager = $this->getManager(); $ev = $this->prophesize(EventDispatcherInterface::class); @@ -123,7 +126,7 @@ public function test_deleteOne() $coll->deleteOne([]); } - public function test_replaceOne() + public function test_replaceOne(): void { $manager = $this->getManager(); $ev = $this->prophesize(EventDispatcherInterface::class); @@ -134,7 +137,7 @@ public function test_replaceOne() $coll->replaceOne([], []); } - public function test_aggregate() + public function test_aggregate(): void { $manager = $this->getManager(); $ev = $this->prophesize(EventDispatcherInterface::class); @@ -165,7 +168,7 @@ public function test_aggregate() } /** leave this test as last one to clean the collection*/ - public function test_deleteMany() + public function test_deleteMany(): void { $manager = $this->getManager(); $ev = $this->prophesize(EventDispatcherInterface::class); @@ -176,7 +179,7 @@ public function test_deleteMany() $coll->deleteMany([]); } - public function test_distinct() + public function test_distinct(): void { $manager = $this->getManager(); $ev = $this->prophesize(EventDispatcherInterface::class); diff --git a/tests/Functional/Command/AbstractCommandTest.php b/tests/Functional/Command/AbstractCommandTest.php index 241b5bcd..0e88b653 100644 --- a/tests/Functional/Command/AbstractCommandTest.php +++ b/tests/Functional/Command/AbstractCommandTest.php @@ -15,7 +15,7 @@ class AbstractCommandTest extends AppTestCase /** * @dataProvider commandOptionsProvider */ - public function test_AbstractCommand_execution(array $arguments) + public function test_AbstractCommand_execution(array $arguments): void { $this->addCommandToApplication(); @@ -27,7 +27,7 @@ public function test_AbstractCommand_execution(array $arguments) self::assertStringContainsString('Executed', $commandTester->getDisplay()); } - public function test_AbstractCommand_connection_exception() + public function test_AbstractCommand_connection_exception(): void { $this->addCommandToApplication(); @@ -42,7 +42,7 @@ public function test_AbstractCommand_connection_exception() $commandTester->execute(['command' => $command->getName(), '--connection' => $unexistantConnectionName]); } - public function commandOptionsProvider() + public function commandOptionsProvider(): array { return [ [[]], @@ -50,7 +50,7 @@ public function commandOptionsProvider() ]; } - private function addCommandToApplication() + private function addCommandToApplication(): void { $container = $this->getApplication() ->getKernel() diff --git a/tests/Functional/Command/DropCollectionCommandTest.php b/tests/Functional/Command/DropCollectionCommandTest.php index c2778cd1..aaec340c 100644 --- a/tests/Functional/Command/DropCollectionCommandTest.php +++ b/tests/Functional/Command/DropCollectionCommandTest.php @@ -11,7 +11,7 @@ class DropCollectionCommandTest extends AppTestCase { - public function test_command() + public function test_command(): void { /** @var Database $conn */ $conn = $this->getContainer()->get('mongo.connection'); @@ -30,7 +30,7 @@ public function test_command() self::assertStringContainsString('Collection dropped', $commandTester->getDisplay()); } - private function addCommandToApplication() + private function addCommandToApplication(): void { $container = $this->getApplication() ->getKernel() diff --git a/tests/Functional/Command/DropDatabaseCommandTest.php b/tests/Functional/Command/DropDatabaseCommandTest.php index cd13b6af..44214777 100644 --- a/tests/Functional/Command/DropDatabaseCommandTest.php +++ b/tests/Functional/Command/DropDatabaseCommandTest.php @@ -11,7 +11,7 @@ class DropDatabaseCommandTest extends AppTestCase { - public function test_command() + public function test_command(): void { /** @var Database $conn */ $conn = $this->getContainer()->get('mongo.connection'); @@ -29,7 +29,7 @@ public function test_command() self::assertStringContainsString('Database dropped', $commandTester->getDisplay()); } - private function addCommandToApplication() + private function addCommandToApplication(): void { $container = $this->getApplication() ->getKernel() diff --git a/tests/Functional/Command/LoadFixturesCommandTest.php b/tests/Functional/Command/LoadFixturesCommandTest.php index 05070eb5..91ad570d 100644 --- a/tests/Functional/Command/LoadFixturesCommandTest.php +++ b/tests/Functional/Command/LoadFixturesCommandTest.php @@ -30,7 +30,7 @@ protected function tearDown(): void $this->conn->dropCollection('testFixturesOrderedCollection'); } - public function test_command() + public function test_command(): void { $this->conn->createCollection('testFixturesCollection'); @@ -55,7 +55,7 @@ public function test_command() self::assertStringContainsString('Done, loaded 4 fixtures files', $commandTester->getDisplay()); } - public function test_command_not_fixtures_found() + public function test_command_not_fixtures_found(): void { $this->addCommandToApplication(); $command = $this->getApplication()->find('mongodb:fixtures:load'); @@ -65,7 +65,7 @@ public function test_command_not_fixtures_found() $commandTester->execute([]); } - public function test_command_order_fixtures() + public function test_command_order_fixtures(): void { $this->conn->createCollection('testFixturesOrderedCollection'); @@ -107,7 +107,7 @@ public function test_command_order_fixtures() $this->conn->dropCollection('testFixturesOrderedCollection'); } - private function addCommandToApplication() + private function addCommandToApplication(): void { $container = $this->getApplication() ->getKernel() diff --git a/tests/Functional/Controller/ProfilerControllerTest.php b/tests/Functional/Controller/ProfilerControllerTest.php index 1a5412b0..22be035a 100644 --- a/tests/Functional/Controller/ProfilerControllerTest.php +++ b/tests/Functional/Controller/ProfilerControllerTest.php @@ -4,6 +4,7 @@ namespace Facile\MongoDbBundle\Tests\Functional\Controller; +use Prophecy\PhpUnit\ProphecyTrait; use Facile\MongoDbBundle\Controller\ProfilerController; use Facile\MongoDbBundle\DataCollector\MongoDbDataCollector; use Facile\MongoDbBundle\Models\Query; @@ -16,7 +17,7 @@ class ProfilerControllerTest extends AppTestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; protected function setUp(): void { @@ -24,7 +25,7 @@ protected function setUp(): void parent::setUp(); } - public function test_explainAction() + public function test_explainAction(): void { $query = new Query(); $query->setClient('test_client'); @@ -64,7 +65,7 @@ public function test_explainAction() $this->assertArrayNotHasKey('err', $data); } - public function test_explainAction_error() + public function test_explainAction_error(): void { $query = new Query(); $query->setMethod('fooo'); diff --git a/tests/Functional/DependencyInjection/MongoDbBundleExtensionTest.php b/tests/Functional/DependencyInjection/MongoDbBundleExtensionTest.php index 18c5e312..7cb754c4 100644 --- a/tests/Functional/DependencyInjection/MongoDbBundleExtensionTest.php +++ b/tests/Functional/DependencyInjection/MongoDbBundleExtensionTest.php @@ -33,7 +33,7 @@ protected function setUp(): void $this->container->setAlias(self::DISPATCHER_PUBLIC_ALIAS, new Alias('facile_mongo_db.event_dispatcher', true)); } - public function test_load() + public function test_load(): void { $this->load( [ @@ -85,7 +85,7 @@ public function test_load() $this->assertContainerBuilderHasService('mongo.explain_query_service', ExplainQueryService::class); } - public function test_load_data_collection_disabled() + public function test_load_data_collection_disabled(): void { $this->load( [ @@ -131,7 +131,7 @@ public function test_load_data_collection_disabled() self::assertCount(0, $ed->getListeners()); } - public function test_load_env_prod() + public function test_load_env_prod(): void { $this->setParameter('kernel.debug', false); $this->load( @@ -170,7 +170,7 @@ public function test_load_env_prod() $this->assertSame('testdb', $defaultConnection->getDatabaseName()); } - public function test_load_multiple() + public function test_load_multiple(): void { $this->load( [ @@ -236,7 +236,7 @@ public function test_load_multiple() /** * @dataProvider commandNamesProvider */ - public function testCommands() + public function testCommands(): void { $command = 'facile_mongo_db.command.drop_database'; $publicAlias = $command . '.public'; diff --git a/tests/Functional/Services/Explain/ExplainQueryServiceTest.php b/tests/Functional/Services/Explain/ExplainQueryServiceTest.php index e19062ff..cb966dd1 100644 --- a/tests/Functional/Services/Explain/ExplainQueryServiceTest.php +++ b/tests/Functional/Services/Explain/ExplainQueryServiceTest.php @@ -15,7 +15,7 @@ protected function setUp(): void parent::setUp(); } - public function test_execute() + public function test_execute(): void { $query = new Query(); $query->setMethod('findOne'); @@ -29,7 +29,7 @@ public function test_execute() $this->assertNotEmpty($explain); } - public function test_execute_not_available_method() + public function test_execute_not_available_method(): void { $query = new Query(); $query->setMethod('fooooo'); diff --git a/tests/Functional/TestApp/TestKernel.php b/tests/Functional/TestApp/TestKernel.php index 851b59e7..1e46cf59 100644 --- a/tests/Functional/TestApp/TestKernel.php +++ b/tests/Functional/TestApp/TestKernel.php @@ -28,7 +28,7 @@ public function registerBundles(): array /** * @inheritDoc */ - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { $suffix = ''; $version = ''; diff --git a/tests/Unit/Capsule/ClientTest.php b/tests/Unit/Capsule/ClientTest.php index 44596561..5ac4825a 100644 --- a/tests/Unit/Capsule/ClientTest.php +++ b/tests/Unit/Capsule/ClientTest.php @@ -2,6 +2,9 @@ declare(strict_types=1); +namespace Facile\MongoDbBundle\Tests\Unit\Capsule; + +use Prophecy\PhpUnit\ProphecyTrait; use Facile\MongoDbBundle\Capsule\Client; use MongoDB\Client as MongoClient; use MongoDB\Collection as MongoCollection; @@ -11,9 +14,9 @@ class ClientTest extends TestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; - public function test_mongodb_client_encapsulation() + public function test_mongodb_client_encapsulation(): void { $client = new Client('mongodb://localhost:27017', [], [], 'test_client', $this->prophesize(EventDispatcherInterface::class)->reveal()); diff --git a/tests/Unit/Capsule/DatabaseTest.php b/tests/Unit/Capsule/DatabaseTest.php index a7268590..bc1ca9c3 100644 --- a/tests/Unit/Capsule/DatabaseTest.php +++ b/tests/Unit/Capsule/DatabaseTest.php @@ -4,6 +4,7 @@ namespace Facile\MongoDbBundle\Tests\Unit\Capsule; +use Prophecy\PhpUnit\ProphecyTrait; use Facile\MongoDbBundle\Capsule\Collection; use Facile\MongoDbBundle\Capsule\Database; use MongoDB\Driver\Manager; @@ -13,7 +14,7 @@ class DatabaseTest extends TestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; public function test_selectCollection(): void { diff --git a/tests/Unit/DataCollector/MongoQuerySerializerTest.php b/tests/Unit/DataCollector/MongoQuerySerializerTest.php index 5beb0274..b283c0cf 100644 --- a/tests/Unit/DataCollector/MongoQuerySerializerTest.php +++ b/tests/Unit/DataCollector/MongoQuerySerializerTest.php @@ -4,6 +4,7 @@ namespace Facile\MongoDbBundle\Tests\Unit\DataCollector; +use Prophecy\PhpUnit\ProphecyTrait; use Facile\MongoDbBundle\DataCollector\MongoQuerySerializer; use Facile\MongoDbBundle\Models\Query; use MongoDB\BSON\UTCDateTime; @@ -12,12 +13,12 @@ class MongoQuerySerializerTest extends TestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; /** * @dataProvider unserializedDataProvider */ - public function test_serializer($unserializedData, $expectedSerialization) + public function test_serializer(array $unserializedData, $expectedSerialization): void { $query = new Query(); $query->setFilters($unserializedData); @@ -31,7 +32,7 @@ public function test_serializer($unserializedData, $expectedSerialization) $this->assertEquals($expectedSerialization, $query->getOptions()['test']); } - public function unserializedDataProvider() + public function unserializedDataProvider(): array { $date = new UTCDateTime(1_000); $dateTime = $date->toDateTime(); @@ -51,7 +52,7 @@ public function unserializedDataProvider() ]; } - public function test_serializer_regression_with_replaceOne() + public function test_serializer_regression_with_replaceOne(): void { $stdClass = new \stdClass(); $stdClass->one = 'one'; diff --git a/tests/Unit/DependencyInjection/ConfigurationTest.php b/tests/Unit/DependencyInjection/ConfigurationTest.php index 6a205a1c..5028d6ac 100644 --- a/tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/tests/Unit/DependencyInjection/ConfigurationTest.php @@ -14,7 +14,7 @@ class ConfigurationTest extends AbstractExtensionConfigurationTestCase { - public function test_empty_configuration_process() + public function test_empty_configuration_process(): void { $this->expectException(\Exception::class); $this->assertProcessedConfigurationEquals([ @@ -26,7 +26,7 @@ public function test_empty_configuration_process() ]); } - public function test_uri_configuration_process() + public function test_uri_configuration_process(): void { $expectedConfiguration = [ 'clients' => [ @@ -55,7 +55,7 @@ public function test_uri_configuration_process() ]); } - public function test_full_configuration_process() + public function test_full_configuration_process(): void { $expectedConfiguration = [ 'clients' => [ @@ -86,7 +86,7 @@ public function test_full_configuration_process() ]); } - public function test_options_configuration_process() + public function test_options_configuration_process(): void { $expectedConfiguration = [ 'clients' => [ @@ -117,7 +117,7 @@ public function test_options_configuration_process() ]); } - public function test_data_collection_disabled_configuration_process() + public function test_data_collection_disabled_configuration_process(): void { $expectedConfiguration = [ 'clients' => [ @@ -148,7 +148,7 @@ public function test_data_collection_disabled_configuration_process() ]); } - public function test_multiple_connections_configuration_process() + public function test_multiple_connections_configuration_process(): void { $expectedConfiguration = [ 'clients' => [ @@ -201,7 +201,7 @@ public function test_multiple_connections_configuration_process() ]); } - public function test_configuration_blocks_invalid_read_preference_options() + public function test_configuration_blocks_invalid_read_preference_options(): void { $extensionConfigurationBuilder = new ExtensionConfigurationBuilder(new LoaderFactory()); $extensionConfiguration = $extensionConfigurationBuilder diff --git a/tests/Unit/Event/Listener/DataCollectorListenerTest.php b/tests/Unit/Event/Listener/DataCollectorListenerTest.php index e0873850..1b4d346e 100644 --- a/tests/Unit/Event/Listener/DataCollectorListenerTest.php +++ b/tests/Unit/Event/Listener/DataCollectorListenerTest.php @@ -13,7 +13,7 @@ class DataCollectorListenerTest extends TestCase { - public function test_onConnectionClientCreated() + public function test_onConnectionClientCreated(): void { $event = new ConnectionEvent('test_client'); @@ -29,7 +29,7 @@ public function test_onConnectionClientCreated() self::assertFalse($logger->hasLoggedEvents()); } - public function test_onQueryExecuted() + public function test_onQueryExecuted(): void { $query = new Query(); diff --git a/tests/Unit/Fixtures/FixtureSorterTest.php b/tests/Unit/Fixtures/FixtureSorterTest.php index 469f75c0..3ddd2957 100644 --- a/tests/Unit/Fixtures/FixtureSorterTest.php +++ b/tests/Unit/Fixtures/FixtureSorterTest.php @@ -9,7 +9,7 @@ class FixtureSorterTest extends TestCase { - public function testSort() + public function testSort(): void { $toLoad = [ $this->mockOrdered(2, 'a'), @@ -22,9 +22,7 @@ public function testSort() $collectionsSorted = implode( '', array_map( - static function (MongoFixtureInterface $fixture): string { - return $fixture->collection(); - }, + static fn(MongoFixtureInterface $fixture): string => $fixture->collection(), FixtureSorter::sort($toLoad) ) ); @@ -40,11 +38,11 @@ static function (MongoFixtureInterface $fixture): string { $this->assertIsAfter($collectionsSorted, 'd', ['c', 'e']); } - private function assertIsAfter(string $collectionsSorted, string $collection, array $others) + private function assertIsAfter(string $collectionsSorted, string $collection, array $others): void { foreach ($others as $other) { $this->assertGreaterThan( - strpos($collectionsSorted, $other), + strpos($collectionsSorted, (string) $other), strpos($collectionsSorted, $collection) ); } @@ -53,17 +51,16 @@ private function assertIsAfter(string $collectionsSorted, string $collection, ar private function mockUnordered(string $collectionName): MongoFixtureInterface { return new class ($collectionName) implements MongoFixtureInterface { - /** @var string */ - private $collectionName; + private string $collectionName; public function __construct(string $collectionName) { $this->collectionName = $collectionName; } - public function loadData() {} + public function loadData(): void {} - public function loadIndexes() {} + public function loadIndexes(): void {} public function collection(): string { @@ -75,11 +72,9 @@ public function collection(): string private function mockOrdered(int $order, string $collectionName): OrderedFixtureInterface { return new class ($order, $collectionName) implements MongoFixtureInterface, OrderedFixtureInterface { - /** @var int */ - private $order; + private int $order; - /** @var string */ - private $collectionName; + private string $collectionName; public function __construct(int $order, string $collectionName) { @@ -87,9 +82,9 @@ public function __construct(int $order, string $collectionName) $this->collectionName = $collectionName; } - public function loadData() {} + public function loadData(): void {} - public function loadIndexes() {} + public function loadIndexes(): void {} public function collection(): string { diff --git a/tests/Unit/Models/ClientConfigurationTest.php b/tests/Unit/Models/ClientConfigurationTest.php index b43a0cf8..65779277 100644 --- a/tests/Unit/Models/ClientConfigurationTest.php +++ b/tests/Unit/Models/ClientConfigurationTest.php @@ -12,7 +12,7 @@ */ class ClientConfigurationTest extends TestCase { - public function test_construction() + public function test_construction(): void { $conf = new ClientConfiguration( 'localhost:27017', @@ -32,7 +32,7 @@ public function test_construction() ); } - public function test_construction_empty_credentials() + public function test_construction_empty_credentials(): void { $conf = new ClientConfiguration( 'localhost:27017', @@ -52,7 +52,7 @@ public function test_construction_empty_credentials() /** * @dataProvider optionsDataProvider */ - public function test_construction_with_options(array $options, array $expectedOptions) + public function test_construction_with_options(array $options, array $expectedOptions): void { $conf = new ClientConfiguration( 'localhost:27017', @@ -71,7 +71,7 @@ public function test_construction_with_options(array $options, array $expectedOp ); } - public function optionsDataProvider() + public function optionsDataProvider(): array { return [ [ // set 1 diff --git a/tests/Unit/MongoBundleTest.php b/tests/Unit/MongoBundleTest.php index 3805d133..f8e1e396 100644 --- a/tests/Unit/MongoBundleTest.php +++ b/tests/Unit/MongoBundleTest.php @@ -10,7 +10,7 @@ class MongoBundleTest extends TestCase { - public function test_bundle() + public function test_bundle(): void { $bundle = new FacileMongoDbBundle(); $this->assertInstanceOf(MongoDbBundleExtension::class, $bundle->getContainerExtension()); diff --git a/tests/Unit/Services/ClientRegistryTest.php b/tests/Unit/Services/ClientRegistryTest.php index 1dfe2f40..74f9424c 100644 --- a/tests/Unit/Services/ClientRegistryTest.php +++ b/tests/Unit/Services/ClientRegistryTest.php @@ -4,6 +4,7 @@ namespace Facile\MongoDbBundle\Tests\Unit\Services; +use Prophecy\PhpUnit\ProphecyTrait; use Facile\MongoDbBundle\Event\ConnectionEvent; use Facile\MongoDbBundle\Services\ClientRegistry; use PHPUnit\Framework\TestCase; @@ -12,9 +13,9 @@ class ClientRegistryTest extends TestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; - public function test_client_connection_url_provided_manually() + public function test_client_connection_url_provided_manually(): void { $registry = new ClientRegistry($this->createEventDispatcherMock(), false, null); @@ -40,7 +41,7 @@ public function test_client_connection_url_provided_manually() $this->assertEquals(['test_client.testdb'], $registry->getClientNames()); } - public function test_client_connection_url_generation_singlehost() + public function test_client_connection_url_generation_singlehost(): void { $registry = new ClientRegistry($this->createEventDispatcherMock(), false, null); @@ -68,7 +69,7 @@ public function test_client_connection_url_generation_singlehost() $this->assertEquals(['test_client.testdb'], $registry->getClientNames()); } - public function test_client_connection_url_generation_multihost() + public function test_client_connection_url_generation_multihost(): void { $registry = new ClientRegistry($this->createEventDispatcherMock(), false, null); diff --git a/tests/Unit/Services/Explain/ExplainCommandBuilderTest.php b/tests/Unit/Services/Explain/ExplainCommandBuilderTest.php index 772eba6f..8b0bad75 100644 --- a/tests/Unit/Services/Explain/ExplainCommandBuilderTest.php +++ b/tests/Unit/Services/Explain/ExplainCommandBuilderTest.php @@ -11,7 +11,7 @@ class ExplainCommandBuilderTest extends TestCase { - public function test_count() + public function test_count(): void { $query = new Query(); $query->setCollection('test_collection'); @@ -32,7 +32,7 @@ public function test_count() ); } - public function test_distinct() + public function test_distinct(): void { $query = new Query(); $query->setCollection('test_collection'); @@ -55,7 +55,7 @@ public function test_distinct() ); } - public function test_aggregate() + public function test_aggregate(): void { $query = new Query(); $query->setCollection('test_collection'); @@ -77,7 +77,7 @@ public function test_aggregate() /** * @dataProvider findsProvider */ - public function test_finds(string $method, bool $projection = false) + public function test_finds(string $method, bool $projection = false): void { $query = new Query(); $query->setCollection('test_collection'); @@ -106,7 +106,7 @@ public function test_finds(string $method, bool $projection = false) $this->assertEquals($expected, $args); } - public function findsProvider() + public function findsProvider(): array { return [ ['find', true], @@ -119,13 +119,13 @@ public function findsProvider() /** * @dataProvider deletedsProvider */ - public function test_deletes(string $method, int $limit = 0) + public function test_deletes(string $method, int $limit = 0): void { $query = new Query(); $query->setCollection('test_collection'); $query->setMethod($method); $query->setFilters(['id' => 1]); - if ($limit) { + if ($limit !== 0) { $query->setOptions([ 'limit' => $limit, ]); @@ -146,7 +146,7 @@ public function test_deletes(string $method, int $limit = 0) $this->assertEquals($expected, $args); } - public function deletedsProvider() + public function deletedsProvider(): array { return [ ['deleteOne', 0], diff --git a/tests/Unit/Services/Loggers/Model/LogEventTest.php b/tests/Unit/Services/Loggers/Model/LogEventTest.php index 324efd7a..76e2e9dd 100644 --- a/tests/Unit/Services/Loggers/Model/LogEventTest.php +++ b/tests/Unit/Services/Loggers/Model/LogEventTest.php @@ -9,7 +9,7 @@ class LogEventTest extends TestCase { - public function test_construction() + public function test_construction(): void { $query = new Query(); $query->setCollection('test_collection'); diff --git a/tests/Unit/Services/Loggers/MongoLoggerTest.php b/tests/Unit/Services/Loggers/MongoLoggerTest.php index f43cd551..eb1dc1d0 100644 --- a/tests/Unit/Services/Loggers/MongoLoggerTest.php +++ b/tests/Unit/Services/Loggers/MongoLoggerTest.php @@ -13,7 +13,7 @@ */ class MongoLoggerTest extends TestCase { - public function test_logger_connections() + public function test_logger_connections(): void { $logger = new MongoQueryLogger(); @@ -23,7 +23,7 @@ public function test_logger_connections() self::assertEquals(['test_connection', 'test_connection2'], $logger->getConnections()); } - public function test_logger_queries() + public function test_logger_queries(): void { $event1 = new Query(); $event1->setCollection('coll1'); diff --git a/tests/Unit/Twig/FacileMongoDbBundleExtensionTest.php b/tests/Unit/Twig/FacileMongoDbBundleExtensionTest.php index bf9b40fc..9a616def 100644 --- a/tests/Unit/Twig/FacileMongoDbBundleExtensionTest.php +++ b/tests/Unit/Twig/FacileMongoDbBundleExtensionTest.php @@ -12,7 +12,7 @@ class FacileMongoDbBundleExtensionTest extends TestCase /** * @dataProvider labelMethodProvider */ - public function test_queryDataTranslate(string $label, string $methodname, string $expected) + public function test_queryDataTranslate(string $label, string $methodname, string $expected): void { $ext = new FacileMongoDbBundleExtension(); $this->assertEquals($expected, $ext->queryDataTranslate($label, $methodname)); @@ -21,13 +21,13 @@ public function test_queryDataTranslate(string $label, string $methodname, strin /** * @dataProvider explainMethodsProvider */ - public function test_isQueryExplainable(string $methodname, bool $expected) + public function test_isQueryExplainable(string $methodname, bool $expected): void { $ext = new FacileMongoDbBundleExtension(); $this->assertEquals($expected, $ext->isQueryExplainable($methodname)); } - public function test_get_name() + public function test_get_name(): void { $ext = new FacileMongoDbBundleExtension(); $this->assertEquals('facile_mongo_db_extesion', $ext->getName());