8000 Fix errors on PHP 7.4 by alcaeus · Pull Request #263 · alcaeus/mongo-php-adapter · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix errors on PHP 7.4 #263

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

8000 Merged
merged 4 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ language: php
services:
- mongodb

# Note: latest PHP version is tested with coverage
php:
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4snapshot

env:
global:
- DRIVER_VERSION="stable"
matrix:
- DRIVER_VERSION="stable"
- DRIVER_VERSION="1.3.4"

addons:
apt:
Expand Down
32 changes: 15 additions & 17 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public function testCreateRecord()
$object = $newCollection->findOne();

$this->assertNotNull($object);
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', '_id', $object);
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $object->_id);
$this->assertSame($id, (string) $object->_id);
$this->assertObjectHasAttribute('foo', $object);
$this->assertAttributeSame('bar', 'foo', $object);
$this->assertNotNull($object->foo);
$this->assertSame('bar', $object->foo);
}

public function testInsertInvalidData()
Expand Down Expand Up @@ -1072,10 +1072,9 @@ public function testSaveInsert()
$object = $newCollection->findOne();

$this->assertNotNull($object);
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', '_id', $object);
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $object->_id);
$this->assertSame($id, (string) $object->_id);
$this->assertObjectHasAttribute('foo', $object);
$this->assertAttributeSame('bar', 'foo', $object);
$this->assertSame('bar', $object->foo);
}

public function testRemoveOne()
Expand Down Expand Up @@ -1115,10 +1114,9 @@ public function testSaveUpdate()
$object = $newCollection->findOne();

$this->assertNotNull($object);
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', '_id', $object);
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $object->_id);
$this->assertSame($id, (string) $object->_id);
$this->assertObjectHasAttribute('foo', $object);
$this->assertAttributeSame('foo', 'foo', $object);
$this->assertSame('foo', $object->foo);
}

public function testSavingShouldReplaceTheWholeDocument()
Expand All @@ -1137,7 +1135,7 @@ public function testSavingShouldReplaceTheWholeDocument()
$object = $newCollection->findOne();

$this->assertNotNull($object);
$this->assertObjectNotHasAttribute('foo', $object);
$this->assertArrayNotHasKey('bar', $object);
}

public function testSaveDuplicate()
Expand Down Expand Up @@ -1612,7 +1610,7 @@ public function testFindAndModifyUpdate()
$object = $newCollection->findOne();

$this->assertNotNull($object);
$this->assertAttributeSame('foo', 'foo', $object);
$this->assertSame('foo', $object->foo);
}

public function testFindAndModifyUpdateWithUpdateOptions()
Expand All @@ -1637,8 +1635,8 @@ public function testFindAndModifyUpdateWithUpdateOptions()
$object = $newCollection->findOne();

$this->assertNotNull($object);
$this->assertAttributeSame('foo', 'bar', $object);
$this->assertObjectNotHasAttribute('foo', $object);
$this->assertSame('foo', $object->bar);
$this->assertArrayNotHasKey('foo', $object);
}

public function testFindAndModifyWithUpdateParamAndOption()
Expand Down Expand Up @@ -1666,8 +1664,8 @@ public function testFindAndModifyWithUpdateParamAndOption()
$object = $newCollection->findOne();

$this->assertNotNull($object);
$this->assertAttributeSame('foobar', 'foo', $object);
$this->assertObjectNotHasAttribute('bar', $object);
$this->assertSame('foobar', $object->foo);
$this->assertArrayNotHasKey('bar', $object);
}

public function testFindAndModifyUpdateReplace()
Expand All @@ -1688,8 +1686,8 @@ public function testFindAndModifyUpdateReplace()
$object = $newCollection->findOne();

$this->assertNotNull($object);
$this->assertAttributeSame('boo', 'foo', $object);
$this->assertObjectNotHasAttribute('bar', $object);
$this->assertSame('boo', $object->foo);
$this->assertArrayNotHasKey('bar', $object);
}

public function testFindAndModifyUpdateReturnNew()
Expand Down
6 changes: 5 additions & 1 deletion tests/Alcaeus/MongoDbAdapter/Mongo/MongoDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ public function testForceError()

public function testExecute()
{
$this->skipTestIf(version_compare($this->getServerVersion(), '4.2.0', '>='), 'Eval no longer works on MongoDB 4.2.0 and newer');

$db = $this->getDatabase();
$document = ['foo' => 'bar'];
$this->getCollection()->insert($document);
Expand Down Expand Up @@ -384,11 +386,13 @@ public function testDropCollection()
'nIndexesWas' => 1,
'ok' => 1.0
];
$this->assertSame($expected, $this->getDatabase()->dropCollection('test'));
$this->assertEquals($expected, $this->getDatabase()->dropCollection('test'));
}

public function testRepair()
{
$this->skipTestIf(version_compare($this->getServerVersion(), '4.2.0', '>='), 'The "repairDatabase" has been removed in MongoDB 4.2.0');

$this->assertSame(['ok' => 1.0], $this->getDatabase()->repair());
}
}
89 changes: 35 additions & 54 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoGridFSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,29 @@ public function testStoringData()

$record = $newCollection->findOne();
$this->assertNotNull($record);
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', '_id', $record);
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $record->_id);
$this->assertSame((string) $id, (string) $record->_id);
$this->assertObjectHasAttribute('foo', $record);
$this->assertAttributeSame('bar', 'foo', $record);
$this->assertObjectHasAttribute('length', $record);
$this->assertAttributeSame(4, 'length', $record);
$this->assertObjectHasAttribute('chunkSize', $record);
$this->assertAttributeSame(2, 'chunkSize', $record);
$this->assertObjectHasAttribute('md5', $record);
$this->assertAttributeSame('e2fc714c4727ee9395f324cd2e7f331f', 'md5', $record);
$this->assertSame('bar', $record->foo);
$this->assertSame(4, $record->length);
$this->assertSame(2, $record->chunkSize);
$this->assertSame('e2fc714c4727ee9395f324cd2e7f331f', $record->md5);

$chunksCursor = $newChunksCollection->find([], ['sort' => ['n' => 1]]);
$chunks = iterator_to_array($chunksCursor);
$firstChunk = $chunks[0];
$this->assertNotNull($firstChunk);
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', 'files_id', $firstChunk);
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $firstChunk->files_id);
$this->assertSame((string) $id, (string) $firstChunk->files_id);
$this->assertAttributeSame(0, 'n', $firstChunk);
$this->assertAttributeInstanceOf('MongoDB\BSON\Binary', 'data', $firstChunk);
$this->assertSame(0, $firstChunk->n);
$this->assertInstanceOf('MongoDB\BSON\Binary', $firstChunk->data);
$this->assertSame('ab', (string) $firstChunk->data->getData());

$secondChunck = $chunks[1];
$this->assertNotNull($secondChunck);
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', 'files_id', $secondChunck);
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $secondChunck->files_id);
$this->assertSame((string) $id, (string) $secondChunck->files_id);
$this->assertAttributeSame(1, 'n', $secondChunck);
$this->assertAttributeInstanceOf('MongoDB\BSON\Binary', 'data', $secondChunck);
$this->assertSame(1, $secondChunck->n);
$this->assertInstanceOf('MongoDB\BSON\Binary', $secondChunck->data);
$this->assertSame('cd', (string) $secondChunck->data->getData());
}

Expand Down Expand Up @@ -164,29 +160,24 @@ public function testStoreFile()
$size = filesize($filename);
$record = $newCollection->findOne();
$this->assertNotNull($record);
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', '_id', $record);
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $record->_id);
$this->assertSame((string) $id, (string) $record->_id);
$this->assertObjectHasAttribute('foo', $record);
$this->assertAttributeSame('bar', 'foo', $record);
$this->assertObjectHasAttribute('length', $record);
$this->assertAttributeSame($size, 'length', $record);
$this->assertObjectHasAttribute('chunkSize', $record);
$this->assertAttributeSame(100, 'chunkSize', $record);
$this->assertObjectHasAttribute('md5', $record);
$this->assertAttributeSame($md5, 'md5', $record);
$this->assertObjectHasAttribute('filename', $record);
$this->assertAttributeSame($filename, 'filename', $record);
$this->assertSame('bar', $record->foo);
$this->assertSame($size, $record->length);
$this->assertSame(100, $record->chunkSize);
$this->assertSame($md5, $record->md5);
$this->assertSame($filename, $record->filename);

$numberOfChunks = (int) ceil($size / 100);
$this->assertSame($numberOfChunks, $newChunksCollection->count());
$expectedContent = substr(file_get_contents(__FILE__), 0, 100);

$firstChunk = $newChunksCollection->findOne([], ['sort' => ['n' => 1]]);
$this->assertNotNull($firstChunk);
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', 'files_id', $firstChunk);
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $firstChunk->files_id);
$this->assertSame((string) $id, (string) $firstChunk->files_id);
$this->assertAttributeSame(0, 'n', $firstChunk);
$this->assertAttributeInstanceOf('MongoDB\BSON\Binary', 'data', $firstChunk);
$this->assertSame(0, $firstChunk->n);
$this->assertInstanceOf('MongoDB\BSON\Binary', $firstChunk->data);
$this->assertSame($expectedContent, (string) $firstChunk->data->getData());
}

Expand All @@ -209,29 +200,24 @@ public function testStoreFileResource()
$filename = basename(__FILE__);
$record = $newCollection->findOne();
$this->assertNotNull($record);
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', '_id', $record);
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $record->_id);
$this->assertSame((string) $id, (string) $record->_id);
$this->assertObjectHasAttribute('foo', $record);
$this->assertAttributeSame('bar', 'foo', $record);
$this->assertObjectHasAttribute('length', $record);
$this->assertAttributeSame($size, 'length', $record);
$this->assertObjectHasAttribute('chunkSize', $record);
$this->assertAttributeSame(100, 'chunkSize', $record);
$this->assertObjectHasAttribute('md5', $record);
$this->assertAttributeSame($md5, 'md5', $record);
$this->assertObjectHasAttribute('filename', $record);
$this->assertAttributeSame('test.php', 'filename', $record);
$this->assertSame('bar', $record->foo);
$this->assertSame($size, $record->length);
$this->assertSame(100, $record->chunkSize);
$this->assertSame($md5, $record->md5);
$this->assertSame('test.php', $record->filename);

$numberOfChunks = (int) ceil($size / 100);
$this->assertSame($numberOfChunks, $newChunksCollection->count());
$expectedContent = substr(file_get_contents(__FILE__), 0, 100);

$firstChunk = $newChunksCollection->findOne([], ['sort' => ['n' => 1]]);
$this->assertNotNull($firstChunk);
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', 'files_id', $firstChunk);
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $firstChunk->files_id);
$this->assertSame((string) $id, (string) $firstChunk->files_id);
$this->assertAttributeSame(0, 'n', $firstChunk);
$this->assertAttributeInstanceOf('MongoDB\BSON\Binary', 'data', $firstChunk);
$this->assertSame(0, $firstChunk->n);
$this->assertInstanceOf('MongoDB\BSON\Binary', $firstChunk->data);
$this->assertSame($expectedContent, (string) $firstChunk->data->getData());
}

Expand Down Expand Up @@ -260,18 +246,13 @@ public function testStoreUpload()
$size = filesize(__FILE__);
$record = $newCollection->findOne();
$this->assertNotNull($record);
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', '_id', $record);
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $record->_id);
$this->assertSame((string) $id, (string) $record->_id);
$this->assertObjectHasAttribute('foo', $record);
$this->assertAttributeSame('bar', 'foo', $record);
$this->assertObjectHasAttribute('length', $record);
$this->assertAttributeSame($size, 'length', $record);
$this->assertObjectHasAttribute('chunkSize', $record);
$this->assertAttributeSame(100, 'chunkSize', $record);
$this->assertObjectHasAttribute('md5', $record);
$this->assertAttributeSame($md5, 'md5', $record);
$this->assertObjectHasAttribute('filename', $record);
$this->assertAttributeSame('test.php', 'filename', $record);
$this->assertSame('bar', $record->foo);
$this->assertSame($size, $record->length);
$this->assertSame(100, $record->chunkSize);
$this->assertSame($md5, $record->md5);
$this->assertSame('test.php', $record->filename);

$numberOfChunks = (int) ceil($size / 100);
$this->assertSame($numberOfChunks, $newChunksCollection->count());
Expand Down
6 changes: 2 additions & 4 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoInsertBatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public function testInsertBatch()
$this->assertSame(2, $newCollection->count());
$record = $newCollection->findOne();
$this->assertNotNull($record);
$this->assertObjectHasAttribute('foo', $record);
$this->assertAttributeSame('bar', 'foo', $record);
$this->assertSame('bar', $record->foo);
}

public function testInsertBatchWithoutAck()
Expand All @@ -52,8 +51,7 @@ public function testInsertBatchWithoutAck()
$this->assertSame(2, $newCollection->count());
$record = $newCollection->findOne();
$this->assertNotNull($record);
$this->assertObjectHasAttribute('foo', $record);
$this->assertAttributeSame('bar', 'foo', $record);
$this->assertSame('bar', $record->foo);
}

public function testInsertBatchError()
Expand Down
12 changes: 4 additions & 8 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoUpdateBatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public function testUpdateOne()
$this->assertSame(1, $newCollection->count());
$record = $newCollection->findOne();
$this->assertNotNull($record);
$this->assertObjectHasAttribute('foo', $record);
$this->assertAttributeSame('foo', 'foo', $record);
$this->assertSame('foo', $record->foo);
}

public function testUpdateOneException()
Expand Down Expand Up @@ -100,8 +99,7 @@ public function testUpdateMany()
$this->assertSame(2, $newCollection->count());
$record = $newCollection->findOne();
$this->assertNotNull($record);
$this->assertObjectHasAttribute('foo', $record);
$this->assertAttributeSame('foo', 'foo', $record);
$this->assertSame('foo', $record->foo);
}

public function testUpdateManyWithoutAck()
Expand Down Expand Up @@ -129,8 +127,7 @@ public function testUpdateManyWithoutAck()
$this->assertSame(2, $newCollection->count());
$record = $newCollection->findOne();
$this->assertNotNull($record);
$this->assertObjectHasAttribute('foo', $record);
$this->assertAttributeSame('foo', 'foo', $record);
$this->assertSame('foo', $record->foo);
}

public function testUpdateManyException()
Expand Down Expand Up @@ -200,8 +197,7 @@ public function testUpsert()
$this->assertSame(2, $newCollection->count());
$record = $newCollection->findOne();
$this->assertNotNull($record);
$this->assertObjectHasAttribute('foo', $record);
$this->assertAttributeSame('bar', 'foo', $record);
$this->assertSame('bar', $record->foo);
}

public function testValidateItem()
Expand Down
0