Skip to content

Commit 8fc6fb4

Browse files
authored
Merge pull request #263 from alcaeus/php-7.4-support
Fix errors on PHP 7.4
2 parents 15ba371 + 9df482f commit 8fc6fb4

File tree

6 files changed

+63
-88
lines changed

6 files changed

+63
-88
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@ language: php
55
services:
66
- mongodb
77

8-
# Note: latest PHP version is tested with coverage
98
php:
109
- 7.0
1110
- 7.1
1211
- 7.2
12+
- 7.3
13+
- 7.4snapshot
1314

1415
env:
1516
global:
1617
- DRIVER_VERSION="stable"
17-
matrix:
18-
- DRIVER_VERSION="stable"
19-
- DRIVER_VERSION="1.3.4"
2018

2119
addons:
2220
apt:

tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ public function testCreateRecord()
4747
$object = $newCollection->findOne();
4848

4949
$this->assertNotNull($object);
50-
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', '_id', $object);
50+
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $object->_id);
5151
$this->assertSame($id, (string) $object->_id);
52-
$this->assertObjectHasAttribute('foo', $object);
53-
$this->assertAttributeSame('bar', 'foo', $object);
52+
$this->assertNotNull($object->foo);
53+
$this->assertSame('bar', $object->foo);
5454
}
5555

5656
public function testInsertInvalidData()
@@ -1072,10 +1072,9 @@ public function testSaveInsert()
10721072
$object = $newCollection->findOne();
10731073

10741074
$this->assertNotNull($object);
1075-
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', '_id', $object);
1075+
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $object->_id);
10761076
$this->assertSame($id, (string) $object->_id);
1077-
$this->assertObjectHasAttribute('foo', $object);
1078-
$this->assertAttributeSame('bar', 'foo', $object);
1077+
$this->assertSame('bar', $object->foo);
10791078
}
10801079

10811080
public function testRemoveOne()
@@ -1115,10 +1114,9 @@ public function testSaveUpdate()
11151114
$object = $newCollection->findOne();
11161115

11171116
$this->assertNotNull($object);
1118-
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', '_id', $object);
1117+
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $object->_id);
11191118
$this->assertSame($id, (string) $object->_id);
1120-
$this->assertObjectHasAttribute('foo', $object);
1121-
$this->assertAttributeSame('foo', 'foo', $object);
1119+
$this->assertSame('foo', $object->foo);
11221120
}
11231121

11241122
public function testSavingShouldReplaceTheWholeDocument()
@@ -1137,7 +1135,7 @@ public function testSavingShouldReplaceTheWholeDocument()
11371135
$object = $newCollection->findOne();
11381136

11391137
$this->assertNotNull($object);
1140-
$this->assertObjectNotHasAttribute('foo', $object);
1138+
$this->assertArrayNotHasKey('bar', $object);
11411139
}
11421140

11431141
public function testSaveDuplicate()
@@ -1612,7 +1610,7 @@ public function testFindAndModifyUpdate()
16121610
$object = $newCollection->findOne();
16131611

16141612
$this->assertNotNull($object);
1615-
$this->assertAttributeSame('foo', 'foo', $object);
1613+
$this->assertSame('foo', $object->foo);
16161614
}
16171615

16181616
public function testFindAndModifyUpdateWithUpdateOptions()
@@ -1637,8 +1635,8 @@ public function testFindAndModifyUpdateWithUpdateOptions()
16371635
$object = $newCollection->findOne();
16381636

16391637
$this->assertNotNull($object);
1640-
$this->assertAttributeSame('foo', 'bar', $object);
1641-
$this->assertObjectNotHasAttribute('foo', $object);
1638+
$this->assertSame('foo', $object->bar);
1639+
$this->assertArrayNotHasKey('foo', $object);
16421640
}
16431641

16441642
public function testFindAndModifyWithUpdateParamAndOption()
@@ -1666,8 +1664,8 @@ public function testFindAndModifyWithUpdateParamAndOption()
16661664
$object = $newCollection->findOne();
16671665

16681666
$this->assertNotNull($object);
1669-
$this->assertAttributeSame('foobar', 'foo', $object);
1670-
$this->assertObjectNotHasAttribute('bar', $object);
1667+
$this->assertSame('foobar', $object->foo);
1668+
$this->assertArrayNotHasKey('bar', $object);
16711669
}
16721670

16731671
public function testFindAndModifyUpdateReplace()
@@ -1688,8 +1686,8 @@ public function testFindAndModifyUpdateReplace()
16881686
$object = $newCollection->findOne();
16891687

16901688
$this->assertNotNull($object);
1691-
$this->assertAttributeSame('boo', 'foo', $object);
1692-
$this->assertObjectNotHasAttribute('bar', $object);
1689+
$this->assertSame('boo', $object->foo);
1690+
$this->assertArrayNotHasKey('bar', $object);
16931691
}
16941692

16951693
public function testFindAndModifyUpdateReturnNew()

tests/Alcaeus/MongoDbAdapter/Mongo/MongoDBTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ public function testForceError()
240240

241241
public function testExecute()
242242
{
243+
$this->skipTestIf(version_compare($this->getServerVersion(), '4.2.0', '>='), 'Eval no longer works on MongoDB 4.2.0 and newer');
244+
243245
$db = $this->getDatabase();
244246
$document = ['foo' => 'bar'];
245247
$this->getCollection()->insert($document);
@@ -384,11 +386,13 @@ public function testDropCollection()
384386
'nIndexesWas' => 1,
385387
'ok' => 1.0
386388
];
387-
$this->assertSame($expected, $this->getDatabase()->dropCollection('test'));
389+
$this->assertEquals($expected, $this->getDatabase()->dropCollection('test'));
388390
}
389391

390392
public function testRepair()
391393
{
394+
$this->skipTestIf(version_compare($this->getServerVersion(), '4.2.0', '>='), 'The "repairDatabase" has been removed in MongoDB 4.2.0');
395+
392396
$this->assertSame(['ok' => 1.0], $this->getDatabase()->repair());
393397
}
394398
}

tests/Alcaeus/MongoDbAdapter/Mongo/MongoGridFSTest.php

Lines changed: 35 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -70,33 +70,29 @@ public function testStoringData()
7070

7171
$record = $newCollection->findOne();
7272
$this->assertNotNull($record);
73-
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', '_id', $record);
73+
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $record->_id);
7474
$this->assertSame((string) $id, (string) $record->_id);
75-
$this->assertObjectHasAttribute('foo', $record);
76-
$this->assertAttributeSame('bar', 'foo', $record);
77-
$this->assertObjectHasAttribute('length', $record);
78-
$this->assertAttributeSame(4, 'length', $record);
79-
$this->assertObjectHasAttribute('chunkSize', $record);
80-
$this->assertAttributeSame(2, 'chunkSize', $record);
81-
$this->assertObjectHasAttribute('md5', $record);
82-
$this->assertAttributeSame('e2fc714c4727ee9395f324cd2e7f331f', 'md5', $record);
75+
$this->assertSame('bar', $record->foo);
76+
$this->assertSame(4, $record->length);
77+
$this->assertSame(2, $record->chunkSize);
78+
$this->assertSame('e2fc714c4727ee9395f324cd2e7f331f', $record->md5);
8379

8480
$chunksCursor = $newChunksCollection->find([], ['sort' => ['n' => 1]]);
8581
$chunks = iterator_to_array($chunksCursor);
8682
$firstChunk = $chunks[0];
8783
$this->assertNotNull($firstChunk);
88-
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', 'files_id', $firstChunk);
84+
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $firstChunk->files_id);
8985
$this->assertSame((string) $id, (string) $firstChunk->files_id);
90-
$this->assertAttributeSame(0, 'n', $firstChunk);
91-
$this->assertAttributeInstanceOf('MongoDB\BSON\Binary', 'data', $firstChunk);
86+
$this->assertSame(0, $firstChunk->n);
87+
$this->assertInstanceOf('MongoDB\BSON\Binary', $firstChunk->data);
9288
$this->assertSame('ab', (string) $firstChunk->data->getData());
9389

9490
$secondChunck = $chunks[1];
9591
$this->assertNotNull($secondChunck);
96-
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', 'files_id', $secondChunck);
92+
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $secondChunck->files_id);
9793
$this->assertSame((string) $id, (string) $secondChunck->files_id);
98-
$this->assertAttributeSame(1, 'n', $secondChunck);
99-
$this->assertAttributeInstanceOf('MongoDB\BSON\Binary', 'data', $secondChunck);
94+
$this->assertSame(1, $secondChunck->n);
95+
$this->assertInstanceOf('MongoDB\BSON\Binary', $secondChunck->data);
10096
$this->assertSame('cd', (string) $secondChunck->data->getData());
10197
}
10298

@@ -164,29 +160,24 @@ public function testStoreFile()
164160
$size = filesize($filename);
165161
$record = $newCollection->findOne();
166162
$this->assertNotNull($record);
167-
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', '_id', $record);
163+
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $record->_id);
168164
$this->assertSame((string) $id, (string) $record->_id);
169-
$this->assertObjectHasAttribute('foo', $record);
170-
$this->assertAttributeSame('bar', 'foo', $record);
171-
$this->assertObjectHasAttribute('length', $record);
172-
$this->assertAttributeSame($size, 'length', $record);
173-
$this->assertObjectHasAttribute('chunkSize', $record);
174-
$this->assertAttributeSame(100, 'chunkSize', $record);
175-
$this->assertObjectHasAttribute('md5', $record);
176-
$this->assertAttributeSame($md5, 'md5', $record);
177-
$this->assertObjectHasAttribute('filename', $record);
178-
$this->assertAttributeSame($filename, 'filename', $record);
165+
$this->assertSame('bar', $record->foo);
166+
$this->assertSame($size, $record->length);
167+
$this->assertSame(100, $record->chunkSize);
168+
$this->assertSame($md5, $record->md5);
169+
$this->assertSame($filename, $record->filename);
179170

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

184175
$firstChunk = $newChunksCollection->findOne([], ['sort' => ['n' => 1]]);
185176
$this->assertNotNull($firstChunk);
186-
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', 'files_id', $firstChunk);
177+
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $firstChunk->files_id);
187178
$this->assertSame((string) $id, (string) $firstChunk->files_id);
188-
$this->assertAttributeSame(0, 'n', $firstChunk);
189-
$this->assertAttributeInstanceOf('MongoDB\BSON\Binary', 'data', $firstChunk);
179+
$this->assertSame(0, $firstChunk->n);
180+
$this->assertInstanceOf('MongoDB\BSON\Binary', $firstChunk->data);
190181
$this->assertSame($expectedContent, (string) $firstChunk->data->getData());
191182
}
192183

@@ -209,29 +200,24 @@ public function testStoreFileResource()
209200
$filename = basename(__FILE__);
210201
$record = $newCollection->findOne();
211202
$this->assertNotNull($record);
212-
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', '_id', $record);
203+
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $record->_id);
213204
$this->assertSame((string) $id, (string) $record->_id);
214-
$this->assertObjectHasAttribute('foo', $record);
215-
$this->assertAttributeSame('bar', 'foo', $record);
216-
$this->assertObjectHasAttribute('length', $record);
217-
$this->assertAttributeSame($size, 'length', $record);
218-
$this->assertObjectHasAttribute('chunkSize', $record);
219-
$this->assertAttributeSame(100, 'chunkSize', $record);
220-
$this->assertObjectHasAttribute('md5', $record);
221-
$this->assertAttributeSame($md5, 'md5', $record);
222-
$this->assertObjectHasAttribute('filename', $record);
223-
$this->assertAttributeSame('test.php', 'filename', $record);
205+
$this->assertSame('bar', $record->foo);
206+
$this->assertSame($size, $record->length);
207+
$this->assertSame(100, $record->chunkSize);
208+
$this->assertSame($md5, $record->md5);
209+
$this->assertSame('test.php', $record->filename);
224210

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

229215
$firstChunk = $newChunksCollection->findOne([], ['sort' => ['n' => 1]]);
230216
$this->assertNotNull($firstChunk);
231-
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', 'files_id', $firstChunk);
217+
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $firstChunk->files_id);
232218
$this->assertSame((string) $id, (string) $firstChunk->files_id);
233-
$this->assertAttributeSame(0, 'n', $firstChunk);
234-
$this->assertAttributeInstanceOf('MongoDB\BSON\Binary', 'data', $firstChunk);
219+
$this->assertSame(0, $firstChunk->n);
220+
$this->assertInstanceOf('MongoDB\BSON\Binary', $firstChunk->data);
235221
$this->assertSame($expectedContent, (string) $firstChunk->data->getData());
236222
}
237223

@@ -260,18 +246,13 @@ public function testStoreUpload()
260246
$size = filesize(__FILE__);
261247
$record = $newCollection->findOne();
262248
$this->assertNotNull($record);
263-
$this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', '_id', $record);
249+
$this->assertInstanceOf('MongoDB\BSON\ObjectID', $record->_id);
264250
$this->assertSame((string) $id, (string) $record->_id);
265-
$this->assertObjectHasAttribute('foo', $record);
266-
$this->assertAttributeSame('bar', 'foo', $record);
267-
$this->assertObjectHasAttribute('length', $record);
268-
$this->assertAttributeSame($size, 'length', $record);
269-
$this->assertObjectHasAttribute('chunkSize', $record);
270-
$this->assertAttributeSame(100, 'chunkSize', $record);
271-
$this->assertObjectHasAttribute('md5', $record);
272-
$this->assertAttributeSame($md5, 'md5', $record);
273-
$this->assertObjectHasAttribute('filename', $record);
274-
$this->assertAttributeSame('test.php', 'filename', $record);
251+
$this->assertSame('bar', $record->foo);
252+
$this->assertSame($size, $record->length);
253+
$this->assertSame(100, $record->chunkSize);
254+
$this->assertSame($md5, $record->md5);
255+
$this->assertSame('test.php', $record->filename);
275256

276257
$numberOfChunks = (int) ceil($size / 100);
277258
$this->assertSame($numberOfChunks, $newChunksCollection->count());

tests/Alcaeus/MongoDbAdapter/Mongo/MongoInsertBatchTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public function testInsertBatch()
3030
$this->assertSame(2, $newCollection->count());
3131
$record = $newCollection->findOne();
3232
$this->assertNotNull($record);
33-
$this->assertObjectHasAttribute('foo', $record);
34-
$this->assertAttributeSame('bar', 'foo', $record);
33+
$this->assertSame('bar', $record->foo);
3534
}
3635

3736
public function testInsertBatchWithoutAck()
@@ -52,8 +51,7 @@ public function testInsertBatchWithoutAck()
5251
$this->assertSame(2, $newCollection->count());
5352
$record = $newCollection->findOne();
5453
$this->assertNotNull($record);
55-
$this->assertObjectHasAttribute('foo', $record);
56-
$this->assertAttributeSame('bar', 'foo', $record);
54+
$this->assertSame('bar', $record->foo);
5755
}
5856

5957
public function testInsertBatchError()

tests/Alcaeus/MongoDbAdapter/Mongo/MongoUpdateBatchTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public function testUpdateOne()
3535
$this->assertSame(1, $newCollection->count());
3636
$record = $newCollection->findOne();
3737
$this->assertNotNull($record);
38-
$this->assertObjectHasAttribute('foo', $record);
39-
$this->assertAttributeSame('foo', 'foo', $record);
38+
$this->assertSame('foo', $record->foo);
4039
}
4140

4241
public function testUpdateOneException()
@@ -100,8 +99,7 @@ public function testUpdateMany()
10099
$this->assertSame(2, $newCollection->count());
101100
$record = $newCollection->findOne();
102101
$this->assertNotNull($record);
103-
$this->assertObjectHasAttribute('foo', $record);
104-
$this->assertAttributeSame('foo', 'foo', $record);
102+
$this->assertSame('foo', $record->foo);
105103
}
106104

107105
public function testUpdateManyWithoutAck()
@@ -129,8 +127,7 @@ public function testUpdateManyWithoutAck()
129127
$this->assertSame(2, $newCollection->count());
130128
$record = $newCollection->findOne();
131129
$this->assertNotNull($record);
132-
$this->assertObjectHasAttribute('foo', $record);
133-
$this->assertAttributeSame('foo', 'foo', $record);
130+
$this->assertSame('foo', $record->foo);
134131
}
135132

136133
public function testUpdateManyException()
@@ -200,8 +197,7 @@ public function testUpsert()
200197
$this->assertSame(2, $newCollection->count());
201198
$record = $newCollection->findOne();
202199
$this->assertNotNull($record);
203-
$this->assertObjectHasAttribute('foo', $record);
204-
$this->assertAttributeSame('bar', 'foo', $record);
200+
$this->assertSame('bar', $record->foo);
205201
}
206202

207203
public function testValidateItem()

0 commit comments

Comments
 (0)