Просмотр исходного кода

Fix assertions that no longer work

Andreas Braun 6 лет назад
Родитель
Сommit
6a5bee27d2

+ 15 - 17
tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php

@@ -47,10 +47,10 @@ class MongoCollectionTest extends TestCase
         $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()
@@ -1072,10 +1072,9 @@ class MongoCollectionTest extends TestCase
         $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()
@@ -1115,10 +1114,9 @@ class MongoCollectionTest extends TestCase
         $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()
@@ -1137,7 +1135,7 @@ class MongoCollectionTest extends TestCase
         $object = $newCollection->findOne();
 
         $this->assertNotNull($object);
-        $this->assertObjectNotHasAttribute('foo', $object);
+        $this->assertArrayNotHasKey('bar', $object);
     }
 
     public function testSaveDuplicate()
@@ -1612,7 +1610,7 @@ class MongoCollectionTest extends TestCase
         $object = $newCollection->findOne();
 
         $this->assertNotNull($object);
-        $this->assertAttributeSame('foo', 'foo', $object);
+        $this->assertSame('foo', $object->foo);
     }
 
     public function testFindAndModifyUpdateWithUpdateOptions()
@@ -1637,8 +1635,8 @@ class MongoCollectionTest extends TestCase
         $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()
@@ -1666,8 +1664,8 @@ class MongoCollectionTest extends TestCase
         $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()
@@ -1688,8 +1686,8 @@ class MongoCollectionTest extends TestCase
         $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()

+ 35 - 54
tests/Alcaeus/MongoDbAdapter/Mongo/MongoGridFSTest.php

@@ -70,33 +70,29 @@ class MongoGridFSTest extends TestCase
 
         $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());
     }
 
@@ -164,18 +160,13 @@ class MongoGridFSTest extends TestCase
         $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());
@@ -183,10 +174,10 @@ class MongoGridFSTest extends TestCase
 
         $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());
     }
 
@@ -209,18 +200,13 @@ class MongoGridFSTest extends TestCase
         $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());
@@ -228,10 +214,10 @@ class MongoGridFSTest extends TestCase
 
         $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());
     }
 
@@ -260,18 +246,13 @@ class MongoGridFSTest extends TestCase
         $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());

+ 2 - 4
tests/Alcaeus/MongoDbAdapter/Mongo/MongoInsertBatchTest.php

@@ -30,8 +30,7 @@ class MongoInsertBatchTest extends TestCase
         $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()
@@ -52,8 +51,7 @@ class MongoInsertBatchTest extends TestCase
         $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()

+ 4 - 8
tests/Alcaeus/MongoDbAdapter/Mongo/MongoUpdateBatchTest.php

@@ -35,8 +35,7 @@ class MongoUpdateBatchTest extends TestCase
         $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()
@@ -100,8 +99,7 @@ class MongoUpdateBatchTest extends TestCase
         $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()
@@ -129,8 +127,7 @@ class MongoUpdateBatchTest extends TestCase
         $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()
@@ -200,8 +197,7 @@ class MongoUpdateBatchTest extends TestCase
         $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()