Skip to content

Commit 01491eb

Browse files
authored
Merge pull request doctrine#1670 from gabriel-caruso/phpunit
Use PSR-1 for PHPUnit TestCase
2 parents 9876897 + ab584a9 commit 01491eb

33 files changed

+144
-154
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"doctrine/mongodb": "^1.6.1"
2626
},
2727
"require-dev": {
28-
"phpunit/phpunit": "~5.4",
28+
"phpunit/phpunit": "^5.7.21|^6.4",
2929
"symfony/yaml": "~2.3|~3.0|^4.0"
3030
},
3131
"suggest": {

tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/GraphLookupTest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313

1414
class GraphLookupTest extends \Doctrine\ODM\MongoDB\Tests\BaseTest
1515
{
16-
/**
17-
* @before
18-
*/
19-
public function prepareTest()
16+
public function setUp()
2017
{
18+
parent::setUp();
2119
$this->requireMongoDB34('$graphLookup tests require at least MongoDB 3.4.0');
2220
}
2321

tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/LookupTest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88

99
class LookupTest extends \Doctrine\ODM\MongoDB\Tests\BaseTest
1010
{
11-
/**
12-
* @before
13-
*/
14-
public function prepareTest()
11+
public function setUp()
1512
{
13+
parent::setUp();
1614
$this->requireMongoDB32('$lookup tests require at least MongoDB 3.2.0');
1715
$this->insertTestData();
1816
}

tests/Doctrine/ODM/MongoDB/Tests/BaseTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
88
use Doctrine\MongoDB\Connection;
99
use Doctrine\ODM\MongoDB\UnitOfWork;
10+
use PHPUnit\Framework\TestCase;
1011

11-
abstract class BaseTest extends \PHPUnit_Framework_TestCase
12+
abstract class BaseTest extends TestCase
1213
{
1314
/** @var DocumentManager */
1415
protected $dm;

tests/Doctrine/ODM/MongoDB/Tests/DocumentManagerTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public function testCreateAggregationBuilder()
7272
public function testGetFilterCollection()
7373
{
7474
$this->assertInstanceOf('\Doctrine\ODM\MongoDB\Query\FilterCollection', $this->dm->getFilterCollection());
75-
}
76-
75+
}
76+
7777
public function testGetPartialReference()
7878
{
7979
$id = new \MongoId();
@@ -128,7 +128,8 @@ public function dataAffectedByErrorIfClosedException()
128128
*/
129129
public function testAffectedByErrorIfClosedException($methodName)
130130
{
131-
$this->setExpectedException('Doctrine\ODM\MongoDB\MongoDBException', 'closed');
131+
$this->expectException(\Doctrine\ODM\MongoDB\MongoDBException::class);
132+
$this->expectExceptionMessage('closed');
132133

133134
$this->dm->close();
134135
if ($methodName === 'flush') {

tests/Doctrine/ODM/MongoDB/Tests/Functional/DateTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function testDateInstanceValueChangeDoesCauseUpdateIfValueIsTheSame()
7878
public function testOldDate()
7979
{
8080
if (PHP_INT_SIZE === 4) {
81-
$this->setExpectedException("InvalidArgumentException");
81+
$this->expectException(\InvalidArgumentException::class);
8282
}
8383

8484
$user = new User();

tests/Doctrine/ODM/MongoDB/Tests/Functional/DocumentPersisterTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ public function testExecuteInsertsRespectsWriteConcern($class, $writeConcern)
458458
$documentPersister = $this->uow->getDocumentPersister($class);
459459

460460
$collection = $this->createMock('\MongoCollection');
461-
$collection->expects($this->any())
461+
$collection->expects($this->once())
462462
->method('batchInsert')
463463
->with($this->isType('array'), $this->logicalAnd($this->arrayHasKey('w'), $this->contains($writeConcern)));
464464

@@ -482,7 +482,7 @@ public function testExecuteUpsertsRespectsWriteConcern($class, $writeConcern)
482482
$documentPersister = $this->uow->getDocumentPersister($class);
483483

484484
$collection = $this->createMock('\MongoCollection');
485-
$collection->expects($this->any())
485+
$collection->expects($this->once())
486486
->method('update')
487487
->with($this->isType('array'), $this->isType('array'), $this->logicalAnd($this->arrayHasKey('w'), $this->contains($writeConcern)));
488488

@@ -529,7 +529,7 @@ public function testDefaultWriteConcernIsRespected()
529529
$documentPersister = $this->uow->getDocumentPersister($class);
530530

531531
$collection = $this->createMock('\MongoCollection');
532-
$collection->expects($this->any())
532+
$collection->expects($this->once())
533533
->method('batchInsert')
534534
->with($this->isType('array'), $this->equalTo(array('w' => 0)));
535535

@@ -585,7 +585,7 @@ public function testNoVersionIncrementOnUpdateFailure()
585585
$testDocument = new $class();
586586
$testDocument->id = 12345;
587587
$this->uow->registerManaged($testDocument, 12345, array('id' => 12345));
588-
$this->setExpectedException(\Doctrine\ODM\MongoDB\LockException::class);
588+
$this->expectException(\Doctrine\ODM\MongoDB\LockException::class);
589589
$testDocument->name = 'test';
590590
$this->dm->persist($testDocument);
591591
$this->dm->flush();

tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php

-8
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,6 @@ public function testRemoveOption()
8080
$this->assertEquals(2, count($product->getOptions()));
8181
}
8282

83-
public function testDoesNotSaveTransientFields()
84-
{
85-
$product = $this->getProduct();
86-
87-
$product->selectOption('small');
88-
$this->dm->flush();
89-
}
90-
9183
protected function getProduct()
9284
{
9385
$products = $this->dm->getRepository('Documents\Ecommerce\ConfigurableProduct')

tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,19 @@ public function testEmbeddedDocumentWithDifferentFieldNameAnnotation()
603603
$test1->embedTwo = $secondEmbedded;
604604

605605
$this->dm->persist($test1);
606+
607+
$this->dm->flush();
608+
609+
$test1Data = $this->dm->createQueryBuilder(ChangeEmbeddedWithNameAnnotationTest::class)
610+
->hydrate(false)
611+
->field('id')
612+
->equals($test1->id)
613+
->getQuery()
614+
->getSingleResult();
615+
616+
$this->assertInternalType('array', $test1Data);
617+
618+
$this->assertArrayHasKey('m_id', $test1Data['embedOne']);
606619
}
607620
}
608621

tests/Doctrine/ODM/MongoDB/Tests/Functional/FlushOptionsTest.php

-19
This file was deleted.

tests/Doctrine/ODM/MongoDB/Tests/Functional/FlushTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ public function testFlushSingleUnmanagedDocument()
9595
$user->username = 'domnikl';
9696
$user->status = 'developer';
9797

98-
$this->setExpectedException('InvalidArgumentException', 'Document has to be managed or scheduled for removal for single computation');
98+
$this->expectException(\InvalidArgumentException::class);
99+
$this->expectExceptionMessage('Document has to be managed or scheduled for removal for single computation');
99100
$this->dm->flush($user);
100101
}
101102

tests/Doctrine/ODM/MongoDB/Tests/Functional/LockTest.php

+19-12
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function testOptimisticLockingIntThrowsException()
5454
// Now lets change a property and try and save it again
5555
$article->title = 'ok';
5656

57-
$this->setExpectedException('Doctrine\ODM\MongoDB\LockException');
57+
$this->expectException(\Doctrine\ODM\MongoDB\LockException::class);
5858

5959
$this->dm->flush();
6060
}
@@ -133,11 +133,14 @@ public function testLockTimestampThrowsException()
133133
// Now lets change a property and try and save it again
134134
$article->title = 'ok';
135135

136-
$this->setExpectedException('Doctrine\ODM\MongoDB\LockException');
136+
$this->expectException(\Doctrine\ODM\MongoDB\LockException::class);
137137

138138
$this->dm->flush();
139139
}
140140

141+
/**
142+
* @doesNotPerformAssertions
143+
*/
141144
public function testLockVersionedDocument()
142145
{
143146
$article = new LockInt();
@@ -157,7 +160,7 @@ public function testLockVersionedDocumentMissmatchThrowsException()
157160
$this->dm->persist($article);
158161
$this->dm->flush();
159162

160-
$this->setExpectedException('Doctrine\ODM\MongoDB\LockException');
163+
$this->expectException(\Doctrine\ODM\MongoDB\LockException::class);
161164

162165
$this->dm->lock($article, LockMode::OPTIMISTIC, $article->version + 1);
163166
}
@@ -170,7 +173,8 @@ public function testLockUnversionedDocumentThrowsException()
170173
$this->dm->persist($user);
171174
$this->dm->flush();
172175

173-
$this->setExpectedException('Doctrine\ODM\MongoDB\LockException', 'Document Documents\User is not versioned.');
176+
$this->expectException(\Doctrine\ODM\MongoDB\LockException::class);
177+
$this->expectExceptionMessage('Document Documents\User is not versioned.');
174178

175179
$this->dm->lock($user, LockMode::OPTIMISTIC);
176180
}
@@ -179,7 +183,8 @@ public function testLockUnmanagedDocumentThrowsException()
179183
{
180184
$article = new LockInt();
181185

182-
$this->setExpectedException('InvalidArgumentException', 'Document is not MANAGED.');
186+
$this->expectException(\InvalidArgumentException::class);
187+
$this->expectExceptionMessage('Document is not MANAGED.');
183188

184189
$this->dm->lock($article, LockMode::OPTIMISTIC, $article->version + 1);
185190
}
@@ -244,7 +249,7 @@ public function testPessimisticReadLockThrowsExceptionOnRemove()
244249
$coll = $this->dm->getDocumentCollection(__NAMESPACE__.'\LockInt');
245250
$coll->update(array('_id' => new \MongoId($article->id)), array('locked' => LockMode::PESSIMISTIC_READ));
246251

247-
$this->setExpectedException('Doctrine\ODM\MongoDB\LockException');
252+
$this->expectException(\Doctrine\ODM\MongoDB\LockException::class);
248253

249254
$this->dm->remove($article);
250255
$this->dm->flush();
@@ -261,7 +266,7 @@ public function testPessimisticReadLockThrowsExceptionOnUpdate()
261266
$coll = $this->dm->getDocumentCollection(__NAMESPACE__.'\LockInt');
262267
$coll->update(array('_id' => new \MongoId($article->id)), array('locked' => LockMode::PESSIMISTIC_READ));
263268

264-
$this->setExpectedException('Doctrine\ODM\MongoDB\LockException');
269+
$this->expectException(\Doctrine\ODM\MongoDB\LockException::class);
265270

266271
$article->title = 'changed';
267272
$this->dm->flush();
@@ -278,7 +283,7 @@ public function testPessimisticWriteLockThrowExceptionOnRemove()
278283
$coll = $this->dm->getDocumentCollection(__NAMESPACE__.'\LockInt');
279284
$coll->update(array('_id' => new \MongoId($article->id)), array('locked' => LockMode::PESSIMISTIC_WRITE));
280285

281-
$this->setExpectedException('Doctrine\ODM\MongoDB\LockException');
286+
$this->expectException(\Doctrine\ODM\MongoDB\LockException::class);
282287

283288
$this->dm->remove($article);
284289
$this->dm->flush();
@@ -295,7 +300,7 @@ public function testPessimisticWriteLockThrowExceptionOnUpdate()
295300
$coll = $this->dm->getDocumentCollection(__NAMESPACE__.'\LockInt');
296301
$coll->update(array('_id' => new \MongoId($article->id)), array('locked' => LockMode::PESSIMISTIC_WRITE));
297302

298-
$this->setExpectedException('Doctrine\ODM\MongoDB\LockException');
303+
$this->expectException(\Doctrine\ODM\MongoDB\LockException::class);
299304

300305
$article->title = 'changed';
301306
$this->dm->flush();
@@ -312,7 +317,7 @@ public function testPessimisticWriteLockThrowExceptionOnRead()
312317
$coll = $this->dm->getDocumentCollection(__NAMESPACE__.'\LockInt');
313318
$coll->update(array('_id' => new \MongoId($article->id)), array('locked' => LockMode::PESSIMISTIC_WRITE));
314319

315-
$this->setExpectedException('Doctrine\ODM\MongoDB\LockException');
320+
$this->expectException(\Doctrine\ODM\MongoDB\LockException::class);
316321

317322
$this->dm->clear();
318323
$article = $this->dm->find(__NAMESPACE__.'\LockInt', $article->id);
@@ -358,13 +363,15 @@ public function testPessimisticWriteLockFunctional()
358363

359364
public function testInvalidLockDocument()
360365
{
361-
$this->setExpectedException('Doctrine\ODM\MongoDB\MongoDBException', 'Invalid lock field type string. Lock field must be int.');
366+
$this->expectException(\Doctrine\ODM\MongoDB\MongoDBException::class);
367+
$this->expectExceptionMessage('Invalid lock field type string. Lock field must be int.');
362368
$this->dm->getClassMetadata(__NAMESPACE__.'\InvalidLockDocument');
363369
}
364370

365371
public function testInvalidVersionDocument()
366372
{
367-
$this->setExpectedException('Doctrine\ODM\MongoDB\MongoDBException', 'Invalid version field type string. Version field must be int or date.');
373+
$this->expectException(\Doctrine\ODM\MongoDB\MongoDBException::class);
374+
$this->expectExceptionMessage('Invalid version field type string. Version field must be int or date.');
368375
$this->dm->getClassMetadata(__NAMESPACE__.'\InvalidVersionDocument');
369376
}
370377

tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencePrimerTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ public function testPrimeForbidsLazyCursor()
8787
->eagerCursor(false);
8888
}
8989

90+
/**
91+
* @doesNotPerformAssertions
92+
*/
9093
public function testFieldPrimingCanBeToggled()
9194
{
9295
$this->dm->createQueryBuilder(User::class)

tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ public function testOneReference()
155155
$this->dm->persist($user);
156156
$this->dm->flush();
157157

158-
$this->dm->flush();
159158
$this->dm->clear();
160159

161-
$accountId = $user->getAccount()->getId();
160+
$this->assertNotNull($user->getAccount()->getId());
162161

163-
$qb = $this->dm->createQueryBuilder('Documents\User')
162+
$qb = $this->dm->createQueryBuilder(User::class)
164163
->field('id')->equals($user->getId());
165164
$query = $qb->getQuery();
166165
$user2 = $query->getSingleResult();
166+
$this->assertInstanceOf(User::class, $user2);
167167
}
168168

169169
public function testManyReference()

tests/Doctrine/ODM/MongoDB/Tests/Functional/RequireIndexesTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ public function testForceEnableRequireIndexes()
209209
$query->execute();
210210
}
211211

212+
/**
213+
* @doesNotPerformAssertions
214+
*/
212215
public function testForceDisableRequireIndexes()
213216
{
214217
$qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument')
@@ -219,6 +222,9 @@ public function testForceDisableRequireIndexes()
219222
}
220223

221224

225+
/**
226+
* @doesNotPerformAssertions
227+
*/
222228
public function testRequireIndexesFalse()
223229
{
224230
$qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\DoesNotRequireIndexesDocument')
@@ -227,6 +233,9 @@ public function testRequireIndexesFalse()
227233
$query->execute();
228234
}
229235

236+
/**
237+
* @doesNotPerformAssertions
238+
*/
230239
public function testRequireIndexesOnEmbeddedDocument()
231240
{
232241
$qb = $this->dm->createQueryBuilder('Doctrine\ODM\MongoDB\Tests\Functional\RequireIndexesDocument')

0 commit comments

Comments
 (0)