Skip to content

Commit

Permalink
Allow php 8 (#114) by @Jean85
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean85 authored Mar 3, 2021
1 parent 9209d4a commit 6c7f4c0
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 90 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ jobs:
- php: 7.4
mongo-ext: 1.9.0
mongo-img: 4.4
- php: 8.0
mongo-ext: 1.9.0
mongo-img: 4.4

steps:
- name: Checkout
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
### Added
* PHP 8 support (#114) by [@Jean85](https://github.com/Jean85).

## 1.3.0 (2021-02-28)
### Added
* This changelog with (#109) by [@Jean85](https://github.com/Jean85).
Expand Down
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Bundle service integration of official [mongodb/mongo-php-library](https://github.com/mongodb/mongo-php-library) driver library, ([mongodb/mongodb](https://packagist.org/packages/mongodb/mongodb) on packagist)

[![PHP](https://img.shields.io/badge/php-%5E7.2-blue.svg)](https://img.shields.io/badge/php-%5E7.0-blue.svg)
[![PHP](https://img.shields.io/badge/php-%5E7.2%7C%5E8.0-blue.svg)](https://img.shields.io/badge/php-%5E7.0-blue.svg)
[![MongoDB](https://img.shields.io/badge/MongoDB-%5E3.0-lightgrey.svg)](https://img.shields.io/badge/MongoDB-%5E3.0-lightgrey.svg)
[![ext-mongodb](https://img.shields.io/badge/ext_mongodb-%5E1.1.5-orange.svg)](https://img.shields.io/badge/ext_mongodb-%5E1.1.5-orange.svg)

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2 || ^8.0",
"ext-mongodb": "^1.1.5",
"mongodb/mongodb": "^1.0",
"symfony/framework-bundle": "^3.4 || ^4.3 || ^5.0"
Expand All @@ -28,7 +28,7 @@
"matthiasnoback/symfony-dependency-injection-test": "^4",
"symfony/web-profiler-bundle": "^3.4 || ^4.3 || ^5.0",
"symfony/console": "^3.4 || ^4.3 || ^5.0",
"phpunit/phpunit": "^8.0",
"phpunit/phpunit": "^8.5.14",
"symfony/phpunit-bridge": "^5.2",
"facile-it/facile-coding-standard": "^0.4.0",
"phpstan/phpstan": "^0.12",
Expand Down
35 changes: 0 additions & 35 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -900,11 +900,6 @@ parameters:
count: 1
path: tests/Functional/Capsule/CollectionTest.php

-
message: "#^Parameter \\#6 \\$eventDispatcher of class Facile\\\\MongoDbBundle\\\\Capsule\\\\Collection constructor expects Symfony\\\\Component\\\\EventDispatcher\\\\EventDispatcherInterface, object given\\.$#"
count: 13
path: tests/Functional/Capsule/CollectionTest.php

-
message: "#^Method Facile\\\\MongoDbBundle\\\\Tests\\\\Functional\\\\Capsule\\\\CollectionTest\\:\\:test_insertOne\\(\\) has no return typehint specified\\.$#"
count: 1
Expand Down Expand Up @@ -1140,41 +1135,11 @@ parameters:
count: 1
path: tests/Unit/Capsule/ClientTest.php

-
message: "#^Method Facile\\\\MongoDbBundle\\\\Tests\\\\Unit\\\\Capsule\\\\DatabaseTest\\:\\:test_selectCollection\\(\\) has no return typehint specified\\.$#"
count: 1
path: tests/Unit/Capsule/DatabaseTest.php

-
message: "#^Parameter \\#5 \\$eventDispatcher of class Facile\\\\MongoDbBundle\\\\Capsule\\\\Database constructor expects Symfony\\\\Component\\\\EventDispatcher\\\\EventDispatcherInterface, object given\\.$#"
count: 2
path: tests/Unit/Capsule/DatabaseTest.php

-
message: "#^Method Facile\\\\MongoDbBundle\\\\Tests\\\\Unit\\\\Capsule\\\\DatabaseTest\\:\\:test_withOptions\\(\\) has no return typehint specified\\.$#"
count: 1
path: tests/Unit/Capsule/DatabaseTest.php

-
message: "#^Method Facile\\\\MongoDbBundle\\\\Tests\\\\unit\\\\DataCollector\\\\MongoDbDataCollectorTest\\:\\:test_construction_logger\\(\\) has no return typehint specified\\.$#"
count: 1
path: tests/Unit/DataCollector/MongoDbDataCollectorTest.php

-
message: "#^Method Facile\\\\MongoDbBundle\\\\Tests\\\\unit\\\\DataCollector\\\\MongoDbDataCollectorTest\\:\\:getUtcDateTime\\(\\) has no return typehint specified\\.$#"
count: 1
path: tests/Unit/DataCollector/MongoDbDataCollectorTest.php

-
message: "#^Parameter \\#1 \\$milliseconds of class MongoDB\\\\BSON\\\\UTCDateTime constructor expects DateTimeInterface\\|int, string given\\.$#"
count: 1
path: tests/Unit/DataCollector/MongoDbDataCollectorTest.php

-
message: "#^Parameter \\#1 \\$version1 of function version_compare expects string, string\\|false given\\.$#"
count: 1
path: tests/Unit/DataCollector/MongoDbDataCollectorTest.php

-
message: "#^Method Facile\\\\MongoDbBundle\\\\Tests\\\\Unit\\\\DataCollector\\\\MongoQuerySerializerTest\\:\\:test_serializer\\(\\) has no return typehint specified\\.$#"
count: 1
Expand Down
22 changes: 8 additions & 14 deletions src/Capsule/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
use Symfony\Component\HttpKernel\Kernel;

/**
* Class Collection.
*
* @internal
*/
final class Collection extends MongoCollection
Expand All @@ -29,16 +27,12 @@ final class Collection extends MongoCollection
private $databaseName;

/**
* Collection constructor.
*
* @param Manager $manager
* @param string $clientName
* @param string $databaseName
* @param string $collectionName
* @param array $options
* @param EventDispatcherInterface $eventDispatcher
*
* @internal param DataCollectorLoggerInterface $logger
*/
public function __construct(
Manager $manager,
Expand All @@ -59,7 +53,7 @@ public function __construct(
*/
public function aggregate(array $pipeline, array $options = [])
{
$query = $this->prepareQuery(__FUNCTION__, null, $pipeline, $options);
$query = $this->prepareQuery(__FUNCTION__, [], $pipeline, $options);
$result = parent::aggregate($query->getData(), $query->getOptions());
$this->notifyQueryExecution($query);

Expand All @@ -71,7 +65,7 @@ public function aggregate(array $pipeline, array $options = [])
*/
public function count($filter = [], array $options = [])
{
$query = $this->prepareQuery(__FUNCTION__, $filter, null, $options);
$query = $this->prepareQuery(__FUNCTION__, $filter, [], $options);
$result = parent::count($query->getFilters(), $query->getOptions());
$this->notifyQueryExecution($query);

Expand All @@ -83,7 +77,7 @@ public function count($filter = [], array $options = [])
*/
public function find($filter = [], array $options = [])
{
$query = $this->prepareQuery(__FUNCTION__, $filter, null, $options);
$query = $this->prepareQuery(__FUNCTION__, $filter, [], $options);
$result = parent::find($query->getFilters(), $query->getOptions());
$this->notifyQueryExecution($query);

Expand All @@ -95,7 +89,7 @@ public function find($filter = [], array $options = [])
*/
public function findOne($filter = [], array $options = [])
{
$query = $this->prepareQuery(__FUNCTION__, $filter, null, $options);
$query = $this->prepareQuery(__FUNCTION__, $filter, [], $options);
$result = parent::findOne($query->getFilters(), $query->getOptions());
$this->notifyQueryExecution($query);

Expand All @@ -119,7 +113,7 @@ public function findOneAndUpdate($filter, $update, array $options = [])
*/
public function findOneAndDelete($filter, array $options = [])
{
$query = $this->prepareQuery(__FUNCTION__, $filter, null, $options);
$query = $this->prepareQuery(__FUNCTION__, $filter, [], $options);
$result = parent::findOneAndDelete($query->getFilters(), $query->getOptions());
$this->notifyQueryExecution($query);

Expand All @@ -131,7 +125,7 @@ public function findOneAndDelete($filter, array $options = [])
*/
public function deleteMany($filter, array $options = [])
{
$query = $this->prepareQuery(__FUNCTION__, $filter, null, $options);
$query = $this->prepareQuery(__FUNCTION__, $filter, [], $options);
$result = parent::deleteMany($query->getFilters(), $query->getOptions());
$this->notifyQueryExecution($query);

Expand All @@ -143,7 +137,7 @@ public function deleteMany($filter, array $options = [])
*/
public function deleteOne($filter, array $options = [])
{
$query = $this->prepareQuery(__FUNCTION__, $filter, null, $options);
$query = $this->prepareQuery(__FUNCTION__, $filter, [], $options);
$result = parent::deleteOne($query->getFilters(), $query->getOptions());
$this->notifyQueryExecution($query);

Expand Down Expand Up @@ -206,7 +200,7 @@ public function distinct($fieldName, $filter = [], array $options = [])
*
* @return Query
*/
private function prepareQuery(string $method, $filters = null, $data = null, array $options): Query
private function prepareQuery(string $method, $filters, $data, array $options): Query
{
$query = new Query();
$query->setFilters($filters ?? []);
Expand Down
26 changes: 13 additions & 13 deletions src/DataCollector/MongoQuerySerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,23 @@ public static function prepareItemData($item)
return self::prepareUnserializableData((array) $item);
}

if (method_exists($item, 'getArrayCopy')) {
return self::prepareUnserializableData($item->getArrayCopy());
}
if (\is_object($item)) {
if (method_exists($item, 'getArrayCopy')) {
return self::prepareUnserializableData($item->getArrayCopy());
}

if (method_exists($item, 'toDateTime')) {
return 'ISODate("' . $item->toDateTime()->format('c') . '")';
}
if (method_exists($item, 'toDateTime')) {
return 'ISODate("' . $item->toDateTime()->format('c') . '")';
}

if (method_exists($item, '__toString')) {
return $item->__toString();
}
if (method_exists($item, '__toString')) {
return $item->__toString();
}

if ($item instanceof Serializable) {
return $item->bsonSerialize();
}
if ($item instanceof Serializable) {
return $item->bsonSerialize();
}

if (\is_object($item)) {
return self::prepareUnserializableData((array) $item);
}

Expand Down
26 changes: 13 additions & 13 deletions tests/Functional/Capsule/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private function getManager(): Manager
public function test_construction()
{
$manager = $this->getManager();
$ev = self::prophesize(EventDispatcherInterface::class);
$ev = $this->prophesize(EventDispatcherInterface::class);

$coll = new Collection($manager, 'test_client', 'testdb', 'test_collection', [], $ev->reveal());

Expand All @@ -37,7 +37,7 @@ public function test_construction()
public function test_insertOne()
{
$manager = $this->getManager();
$ev = self::prophesize(EventDispatcherInterface::class);
$ev = $this->prophesize(EventDispatcherInterface::class);
$this->assertEventsDispatching($ev);

$coll = new Collection($manager, 'test_client', 'testdb', 'test_collection', [], $ev->reveal());
Expand All @@ -48,7 +48,7 @@ public function test_insertOne()
public function test_updateOne()
{
$manager = $this->getManager();
$ev = self::prophesize(EventDispatcherInterface::class);
$ev = $this->prophesize(EventDispatcherInterface::class);
$this->assertEventsDispatching($ev);

$coll = new Collection($manager, 'test_client', 'testdb', 'test_collection', [], $ev->reveal());
Expand All @@ -59,7 +59,7 @@ public function test_updateOne()
public function test_count()
{
$manager = $this->getManager();
$ev = self::prophesize(EventDispatcherInterface::class);
$ev = $this->prophesize(EventDispatcherInterface::class);
$this->assertEventsDispatching($ev);

$coll = new Collection($manager, 'test_client', 'testdb', 'test_collection', [], $ev->reveal());
Expand All @@ -70,7 +70,7 @@ public function test_count()
public function test_find()
{
$manager = $this->getManager();
$ev = self::prophesize(EventDispatcherInterface::class);
$ev = $this->prophesize(EventDispatcherInterface::class);
$this->assertEventsDispatching($ev);

$coll = new Collection($manager, 'test_client', 'testdb', 'test_collection', [], $ev->reveal());
Expand All @@ -81,7 +81,7 @@ public function test_find()
public function test_findOne()
{
$manager = $this->getManager();
$ev = self::prophesize(EventDispatcherInterface::class);
$ev = $this->prophesize(EventDispatcherInterface::class);
$this->assertEventsDispatching($ev);

$coll = new Collection($manager, 'test_client', 'testdb', 'test_collection', [], $ev->reveal());
Expand All @@ -92,7 +92,7 @@ public function test_findOne()
public function test_findOneAndUpdate()
{
$manager = $this->getManager();
$ev = self::prophesize(EventDispatcherInterface::class);
$ev = $this->prophesize(EventDispatcherInterface::class);
$this->assertEventsDispatching($ev);

$coll = new Collection($manager, 'test_client', 'testdb', 'test_collection', [], $ev->reveal());
Expand All @@ -103,7 +103,7 @@ public function test_findOneAndUpdate()
public function test_findOneAndDelete()
{
$manager = $this->getManager();
$ev = self::prophesize(EventDispatcherInterface::class);
$ev = $this->prophesize(EventDispatcherInterface::class);
$this->assertEventsDispatching($ev);

$coll = new Collection($manager, 'test_client', 'testdb', 'test_collection', [], $ev->reveal());
Expand All @@ -114,7 +114,7 @@ public function test_findOneAndDelete()
public function test_deleteOne()
{
$manager = $this->getManager();
$ev = self::prophesize(EventDispatcherInterface::class);
$ev = $this->prophesize(EventDispatcherInterface::class);
$this->assertEventsDispatching($ev);

$coll = new Collection($manager, 'test_client', 'testdb', 'test_collection', [], $ev->reveal());
Expand All @@ -125,7 +125,7 @@ public function test_deleteOne()
public function test_replaceOne()
{
$manager = $this->getManager();
$ev = self::prophesize(EventDispatcherInterface::class);
$ev = $this->prophesize(EventDispatcherInterface::class);
$this->assertEventsDispatching($ev);

$coll = new Collection($manager, 'test_client', 'testdb', 'test_collection', [], $ev->reveal());
Expand All @@ -136,7 +136,7 @@ public function test_replaceOne()
public function test_aggregate()
{
$manager = $this->getManager();
$ev = self::prophesize(EventDispatcherInterface::class);
$ev = $this->prophesize(EventDispatcherInterface::class);
$this->assertEventsDispatching($ev);

$coll = new Collection($manager, 'test_client', 'testdb', 'test_collection', [], $ev->reveal());
Expand Down Expand Up @@ -167,7 +167,7 @@ public function test_aggregate()
public function test_deleteMany()
{
$manager = $this->getManager();
$ev = self::prophesize(EventDispatcherInterface::class);
$ev = $this->prophesize(EventDispatcherInterface::class);
$this->assertEventsDispatching($ev);

$coll = new Collection($manager, 'test_client', 'testdb', 'test_collection', [], $ev->reveal());
Expand All @@ -178,7 +178,7 @@ public function test_deleteMany()
public function test_distinct()
{
$manager = $this->getManager();
$ev = self::prophesize(EventDispatcherInterface::class);
$ev = $this->prophesize(EventDispatcherInterface::class);
$this->assertEventsDispatching($ev);

$coll = new Collection($manager, 'test_client', 'testdb', 'test_collection', [], $ev->reveal());
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Capsule/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

class DatabaseTest extends TestCase
{
public function test_selectCollection()
public function test_selectCollection(): void
{
$manager = new Manager('mongodb://localhost');
$logger = self::prophesize(EventDispatcherInterface::class);
$logger = $this->prophesize(EventDispatcherInterface::class);

$db = new Database($manager, 'client_name', 'testdb', [], $logger->reveal());
self::assertInstanceOf(\MongoDB\Database::class, $db);
Expand All @@ -30,10 +30,10 @@ public function test_selectCollection()
self::assertEquals('testdb', $debugInfo['databaseName']);
}

public function test_withOptions()
public function test_withOptions(): void
{
$manager = new Manager('mongodb://localhost');
$logger = self::prophesize(EventDispatcherInterface::class);
$logger = $this->prophesize(EventDispatcherInterface::class);

$db = new Database($manager, 'client_name', 'testdb', [], $logger->reveal());
self::assertInstanceOf(\MongoDB\Database::class, $db);
Expand Down
Loading

0 comments on commit 6c7f4c0

Please sign in to comment.