Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Symfony 7 #144

Merged
merged 13 commits into from
Jan 25, 2024
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"php": "^7.4 || ^8.0",
"ext-mongodb": "^1.6",
"mongodb/mongodb": "^1.5",
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0"
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0"
},
"require-dev": {
"matthiasnoback/symfony-dependency-injection-test": "^4",
"symfony/web-profiler-bundle": "^4.4 || ^5.0 || ^6.0",
"symfony/console": "^4.4 || ^5.0 || ^6.0",
"symfony/web-profiler-bundle": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"symfony/console": "^4.4 || ^5.0 || ^6.0 || ^7.0",
"phpunit/phpunit": "^9.6.13",
"symfony/phpunit-bridge": "^7.0",
"facile-it/facile-coding-standard": "1.2.0",
Expand Down
8 changes: 1 addition & 7 deletions src/Capsule/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadPreference;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Kernel;

/**
* @internal
Expand Down Expand Up @@ -230,12 +229,7 @@ private function notifyQueryExecution(Query $queryLog)
{
$queryLog->setExecutionTime(microtime(true) - $queryLog->getStart());

$event = new QueryEvent($queryLog);
if (Kernel::VERSION_ID >= 40_300) {
$this->eventDispatcher->dispatch($event, QueryEvent::QUERY_EXECUTED);
} else {
$this->eventDispatcher->dispatch($event, QueryEvent::QUERY_EXECUTED);
}
$this->eventDispatcher->dispatch(new QueryEvent($queryLog), QueryEvent::QUERY_EXECUTED);
}

public function getClientName(): string
Expand Down
4 changes: 2 additions & 2 deletions src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function getContainer(): ContainerInterface
/**
* @inheritDoc
*/
protected function configure()
protected function configure(): void
{
parent::configure();
$this
Expand All @@ -53,7 +53,7 @@ protected function configure()
/**
* @inheritDoc
*/
protected function initialize(InputInterface $input, OutputInterface $output)
protected function initialize(InputInterface $input, OutputInterface $output): void
{
parent::initialize($input, $output);
$this->io = new SymfonyStyle($input, $output);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/DropCollectionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DropCollectionCommand extends AbstractCommand
/**
* @inheritDoc
*/
protected function configure()
protected function configure(): void
{
parent::configure();
$this
Expand Down
2 changes: 1 addition & 1 deletion src/Command/DropDatabaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DropDatabaseCommand extends AbstractCommand
/**
* @inheritDoc
*/
protected function configure()
protected function configure(): void
{
parent::configure();
$this
Expand Down
8 changes: 4 additions & 4 deletions src/Command/LoadFixturesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LoadFixturesCommand extends AbstractCommand
/**
* @inheritDoc
*/
protected function configure()
protected function configure(): void
{
parent::configure();
$this
Expand All @@ -33,7 +33,7 @@ protected function configure()
->setDescription('Load fixtures and applies them');
}

protected function initialize(InputInterface $input, OutputInterface $output)
protected function initialize(InputInterface $input, OutputInterface $output): void
{
parent::initialize($input, $output);
$this->loader = new MongoFixturesLoader($this->getContainer());
Expand Down Expand Up @@ -68,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

private function loadFixture(MongoFixtureInterface $indexList)
private function loadFixture(MongoFixtureInterface $indexList): void
{
$indexList->loadData();
$indexList->loadIndexes();
Expand All @@ -90,7 +90,7 @@ private function prepareSearchPaths(InputInterface $input, KernelInterface $kern
return $paths;
}

private function loadPaths(array $paths)
private function loadPaths(array $paths): void
{
foreach ($paths as $path) {
if (is_dir($path)) {
Expand Down
11 changes: 4 additions & 7 deletions src/DataCollector/MongoDbDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ class MongoDbDataCollector extends DataCollector
/** @var DataCollectorLoggerInterface */
private $logger;

/** @var array */
protected $data;

public function __construct()
{
$this->reset();
}

public function reset()
public function reset(): void
{
$this->data = [
self::QUERY_KEYWORD => [],
Expand All @@ -43,12 +40,12 @@ public function reset()
];
}

public function setLogger(DataCollectorLoggerInterface $logger)
public function setLogger(DataCollectorLoggerInterface $logger): void
{
$this->logger = $logger;
}

public function collect(Request $request, Response $response, $exception = null)
public function collect(Request $request, Response $response, $exception = null): void
{
if ($exception && ! $exception instanceof \Throwable) {
throw new \InvalidArgumentException('Expecting \Throwable, got ' . get_debug_type($exception));
Expand Down Expand Up @@ -101,7 +98,7 @@ public function getConnections(): array
/**
* @inheritDoc
*/
public function getName()
public function getName(): string
{
return 'mongodb';
}
Expand Down
4 changes: 1 addition & 3 deletions src/DependencyInjection/MongoDbBundleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class MongoDbBundleExtension extends Extension
/** @var ContainerBuilder */
private $containerBuilder;

public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$this->containerBuilder = $container;
$config = $this->processConfiguration(new Configuration(), $configs);
Expand All @@ -42,8 +42,6 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('profiler.xml');
$this->attachDataCollectionListenerToEventManager();
}

return $config;
}

private function mustCollectData(array $config): bool
Expand Down
10 changes: 2 additions & 8 deletions tests/Functional/Capsule/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use MongoDB\Driver\Manager;
use Prophecy\Argument;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Kernel;

class CollectionTest extends AppTestCase
{
Expand Down Expand Up @@ -190,12 +189,7 @@ public function test_distinct()

protected function assertEventsDispatching($ev)
{
if (Kernel::VERSION_ID >= 40_300) {
$ev->dispatch(Argument::type(QueryEvent::class), QueryEvent::QUERY_PREPARED)->shouldBeCalled();
$ev->dispatch(Argument::type(QueryEvent::class), QueryEvent::QUERY_EXECUTED)->shouldBeCalled();
} else {
$ev->dispatch(QueryEvent::QUERY_PREPARED, Argument::type(QueryEvent::class))->shouldBeCalled();
$ev->dispatch(QueryEvent::QUERY_EXECUTED, Argument::type(QueryEvent::class))->shouldBeCalled();
}
$ev->dispatch(Argument::type(QueryEvent::class), QueryEvent::QUERY_PREPARED)->shouldBeCalled();
$ev->dispatch(Argument::type(QueryEvent::class), QueryEvent::QUERY_EXECUTED)->shouldBeCalled();
}
}
2 changes: 1 addition & 1 deletion tests/Functional/Command/AbstractCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private function addCommandToApplication()

class FakeCommand extends AbstractCommand
{
protected function configure()
protected function configure(): void
{
parent::configure();
$this
Expand Down
13 changes: 3 additions & 10 deletions tests/Unit/Services/ClientRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\Kernel;

class ClientRegistryTest extends TestCase
{
Expand Down Expand Up @@ -107,15 +106,9 @@ private function createEventDispatcherMock(): EventDispatcherInterface
return true;
});

if (Kernel::VERSION_ID >= 40_300) {
$eventDispatcher->dispatch($event, ConnectionEvent::CLIENT_CREATED)
->shouldBeCalledOnce()
->willReturnArgument(0);
} else {
$eventDispatcher->dispatch(ConnectionEvent::CLIENT_CREATED, $event)
->shouldBeCalledOnce()
->willReturnArgument(1);
}
$eventDispatcher->dispatch($event, ConnectionEvent::CLIENT_CREATED)
->shouldBeCalledOnce()
->willReturnArgument(0);

return $eventDispatcher->reveal();
}
Expand Down
Loading