Skip to content

Commit 8c7fa3f

Browse files
authored
Use attributes in tests (#2596)
* Use attributes for tests * Use attributes for benchmark * Use attributes in tools/sandbox/Documents * Change more annotations to attributes * Ignore known SA errors
1 parent ac2f60b commit 8c7fa3f

File tree

278 files changed

+3318
-7375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

278 files changed

+3318
-7375
lines changed

benchmark/BaseBench.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Doctrine\ODM\MongoDB\Configuration;
88
use Doctrine\ODM\MongoDB\DocumentManager;
9-
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
9+
use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver;
1010
use MongoDB\Client;
1111
use MongoDB\Model\DatabaseInfo;
1212
use PhpBench\Benchmark\Metadata\Annotations\BeforeMethods;
@@ -80,8 +80,8 @@ public function clearDatabase(): void
8080
}
8181
}
8282

83-
protected static function createMetadataDriverImpl(): AnnotationDriver
83+
protected static function createMetadataDriverImpl(): AttributeDriver
8484
{
85-
return AnnotationDriver::create(__DIR__ . '/../tests/Documents');
85+
return AttributeDriver::create(__DIR__ . '/../tests/Documents');
8686
}
8787
}

phpstan-baseline.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,16 @@ parameters:
790790
count: 1
791791
path: tests/Doctrine/ODM/MongoDB/Tests/Functional/NestedDocumentsTest.php
792792

793+
-
794+
message: "#^Parameter \\$discriminatorMap of attribute class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\Annotations\\\\ReferenceOne constructor expects array\\<string, class\\-string\\>\\|null, array\\<string, string\\> given\\.$#"
795+
count: 1
796+
path: tests/Doctrine/ODM/MongoDB/Tests/Functional/TargetDocumentTest.php
797+
798+
-
799+
message: "#^Parameter \\$targetDocument of attribute class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\Annotations\\\\ReferenceOne constructor expects class\\-string\\|null, string given\\.$#"
800+
count: 1
801+
path: tests/Doctrine/ODM/MongoDB/Tests/Functional/TargetDocumentTest.php
802+
793803
-
794804
message: "#^Property Doctrine\\\\ODM\\\\MongoDB\\\\Tests\\\\Functional\\\\Ticket\\\\GH1058PersistDocument\\:\\:\\$id is never written, only read\\.$#"
795805
count: 1

psalm-baseline.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@
391391
<code><![CDATA[['upsert' => true]]]></code>
392392
</InvalidArgument>
393393
</file>
394+
<file src="tests/Doctrine/ODM/MongoDB/Tests/Functional/TargetDocumentTest.php">
395+
<UndefinedClass>
396+
<code><![CDATA[['Foo' => 'Doctrine\ODM\MongoDB\Tests\Functional\SomeInvalidClass']]]></code>
397+
</UndefinedClass>
398+
</file>
394399
<file src="tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1011Test.php">
395400
<InvalidArgument>
396401
<code><![CDATA[$doc->embeds]]></code>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Doctrine\ODM\MongoDB\Configuration;
88
use Doctrine\ODM\MongoDB\DocumentManager;
9-
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
9+
use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver;
1010
use Doctrine\ODM\MongoDB\Tests\Query\Filter\Filter;
1111
use Doctrine\ODM\MongoDB\UnitOfWork;
1212
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
@@ -116,7 +116,7 @@ public static function assertArraySubset(array $subset, array $array, bool $chec
116116

117117
protected static function createMetadataDriverImpl(): MappingDriver
118118
{
119-
return AnnotationDriver::create(__DIR__ . '/../../../../Documents');
119+
return AttributeDriver::create(__DIR__ . '/../../../../Documents');
120120
}
121121

122122
protected static function createTestDocumentManager(): DocumentManager

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

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -231,59 +231,38 @@ public function testDifferentStoreAsDbReferences(): void
231231
}
232232
}
233233

234-
/** @ODM\Document */
234+
#[ODM\Document]
235235
class WrongSimpleRefDocument
236236
{
237-
/**
238-
* @ODM\Id
239-
*
240-
* @var string|null
241-
*/
237+
/** @var string|null */
238+
#[ODM\Id]
242239
public $id;
243240

244-
/**
245-
* @ODM\ReferenceOne(targetDocument=Documents\Tournament\Participant::class, storeAs="id")
246-
*
247-
* @var Participant|null
248-
*/
241+
/** @var Participant|null */
242+
#[ODM\ReferenceOne(targetDocument: Participant::class, storeAs: 'id')]
249243
public $ref;
250244
}
251245

252-
/** @ODM\Document */
246+
#[ODM\Document]
253247
class ReferenceStoreAsDocument
254248
{
255-
/**
256-
* @ODM\Id
257-
*
258-
* @var string|null
259-
*/
249+
/** @var string|null */
250+
#[ODM\Id]
260251
public $id;
261252

262-
/**
263-
* @ODM\ReferenceOne(targetDocument=User::class, storeAs="id")
264-
*
265-
* @var User|null
266-
*/
253+
/** @var User|null */
254+
#[ODM\ReferenceOne(targetDocument: User::class, storeAs: 'id')]
267255
public $ref1;
268256

269-
/**
270-
* @ODM\ReferenceOne(targetDocument=User::class, storeAs="dbRef")
271-
*
272-
* @var Collection<int, User>
273-
*/
257+
/** @var Collection<int, User> */
258+
#[ODM\ReferenceOne(targetDocument: User::class, storeAs: 'dbRef')]
274259
public $ref2;
275260

276-
/**
277-
* @ODM\ReferenceOne(targetDocument=User::class, storeAs="dbRefWithDb")
278-
*
279-
* @var Collection<int, User>
280-
*/
261+
/** @var Collection<int, User> */
262+
#[ODM\ReferenceOne(targetDocument: User::class, storeAs: 'dbRefWithDb')]
281263
public $ref3;
282264

283-
/**
284-
* @ODM\ReferenceOne(targetDocument=User::class, storeAs="ref")
285-
*
286-
* @var Collection<int, User>
287-
*/
265+
/** @var Collection<int, User> */
266+
#[ODM\ReferenceOne(targetDocument: User::class, storeAs: 'ref')]
288267
public $ref4;
289268
}

tests/Doctrine/ODM/MongoDB/Tests/Events/LifecycleCallbacksTest.php

Lines changed: 39 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -246,110 +246,72 @@ public function testEventsNotFiredForInverseSide(): void
246246
}
247247
}
248248

249-
/** @ODM\Document */
249+
#[ODM\Document]
250250
class User extends BaseDocument
251251
{
252-
/**
253-
* @ODM\Id
254-
*
255-
* @var string|null
256-
*/
252+
/** @var string|null */
253+
#[ODM\Id]
257254
public $id;
258255

259-
/**
260-
* @ODM\EmbedOne(targetDocument=Profile::class)
261-
*
262-
* @var Profile|null
263-
*/
256+
/** @var Profile|null */
257+
#[ODM\EmbedOne(targetDocument: Profile::class)]
264258
public $profile;
265259

266-
/**
267-
* @ODM\EmbedMany(targetDocument=Profile::class)
268-
*
269-
* @var Collection<int, Profile>|array<Profile>
270-
*/
260+
/** @var Collection<int, Profile>|array<Profile> */
261+
#[ODM\EmbedMany(targetDocument: Profile::class)]
271262
public $profiles = [];
272263

273-
/**
274-
* @ODM\ReferenceMany(targetDocument=User::class)
275-
*
276-
* @var Collection<int, User>|array<User>
277-
*/
264+
/** @var Collection<int, User>|array<User> */
265+
#[ODM\ReferenceMany(targetDocument: self::class)]
278266
public $friends = [];
279267
}
280268

281-
/** @ODM\Document */
269+
#[ODM\Document]
282270
class Cart extends BaseDocument
283271
{
284-
/**
285-
* @ODM\Id
286-
*
287-
* @var string|null
288-
*/
272+
/** @var string|null */
273+
#[ODM\Id]
289274
public $id;
290275

291-
/**
292-
* @ODM\ReferenceOne(targetDocument=Customer::class, inversedBy="cart")
293-
*
294-
* @var Customer|null
295-
*/
276+
/** @var Customer|null */
277+
#[ODM\ReferenceOne(targetDocument: Customer::class, inversedBy: 'cart')]
296278
public $customer;
297279
}
298280

299-
/** @ODM\Document */
281+
#[ODM\Document]
300282
class Customer extends BaseDocument
301283
{
302-
/**
303-
* @ODM\Id
304-
*
305-
* @var string|null
306-
*/
284+
/** @var string|null */
285+
#[ODM\Id]
307286
public $id;
308287

309-
/**
310-
* @ODM\ReferenceOne(targetDocument=Cart::class, mappedBy="customer")
311-
*
312-
* @var Cart|null
313-
*/
288+
/** @var Cart|null */
289+
#[ODM\ReferenceOne(targetDocument: Cart::class, mappedBy: 'customer')]
314290
public $cart;
315291
}
316292

317-
/** @ODM\EmbeddedDocument */
293+
#[ODM\EmbeddedDocument]
318294
class Profile extends BaseDocument
319295
{
320-
/**
321-
* @ODM\EmbedOne(targetDocument=Profile::class)
322-
*
323-
* @var Profile|null
324-
*/
296+
/** @var Profile|null */
297+
#[ODM\EmbedOne(targetDocument: self::class)]
325298
public $profile;
326299
}
327300

328-
/**
329-
* @ODM\MappedSuperclass
330-
* @ODM\HasLifecycleCallbacks
331-
*/
301+
#[ODM\MappedSuperclass]
302+
#[ODM\HasLifecycleCallbacks]
332303
abstract class BaseDocument
333304
{
334-
/**
335-
* @ODM\Field(type="string")
336-
*
337-
* @var string|null
338-
*/
305+
/** @var string|null */
306+
#[ODM\Field(type: 'string')]
339307
public $name;
340308

341-
/**
342-
* @ODM\Field(type="date")
343-
*
344-
* @var DateTime
345-
*/
309+
/** @var DateTime */
310+
#[ODM\Field(type: 'date')]
346311
public $createdAt;
347312

348-
/**
349-
* @ODM\Field(type="date")
350-
*
351-
* @var DateTime|null
352-
*/
313+
/** @var DateTime|null */
314+
#[ODM\Field(type: 'date')]
353315
public $updatedAt;
354316

355317
/** @var bool */
@@ -379,57 +341,57 @@ abstract class BaseDocument
379341
/** @var bool */
380342
public $preFlush = false;
381343

382-
/** @ODM\PrePersist */
344+
#[ODM\PrePersist]
383345
public function prePersist(Event\LifecycleEventArgs $e): void
384346
{
385347
$this->prePersist = true;
386348
$this->createdAt = new DateTime();
387349
}
388350

389-
/** @ODM\PostPersist */
351+
#[ODM\PostPersist]
390352
public function postPersist(Event\LifecycleEventArgs $e): void
391353
{
392354
$this->postPersist = true;
393355
}
394356

395-
/** @ODM\PreUpdate */
357+
#[ODM\PreUpdate]
396358
public function preUpdate(Event\PreUpdateEventArgs $e): void
397359
{
398360
$this->preUpdate = true;
399361
$this->updatedAt = new DateTime();
400362
}
401363

402-
/** @ODM\PostUpdate */
364+
#[ODM\PostUpdate]
403365
public function postUpdate(Event\LifecycleEventArgs $e): void
404366
{
405367
$this->postUpdate = true;
406368
}
407369

408-
/** @ODM\PreRemove */
370+
#[ODM\PreRemove]
409371
public function preRemove(Event\LifecycleEventArgs $e): void
410372
{
411373
$this->preRemove = true;
412374
}
413375

414-
/** @ODM\PostRemove */
376+
#[ODM\PostRemove]
415377
public function postRemove(Event\LifecycleEventArgs $e): void
416378
{
417379
$this->postRemove = true;
418380
}
419381

420-
/** @ODM\PreLoad */
382+
#[ODM\PreLoad]
421383
public function preLoad(Event\PreLoadEventArgs $e): void
422384
{
423385
$this->preLoad = true;
424386
}
425387

426-
/** @ODM\PostLoad */
388+
#[ODM\PostLoad]
427389
public function postLoad(Event\LifecycleEventArgs $e): void
428390
{
429391
$this->postLoad = true;
430392
}
431393

432-
/** @ODM\PreFlush */
394+
#[ODM\PreFlush]
433395
public function preFlush(Event\PreFlushEventArgs $e): void
434396
{
435397
$this->preFlush = true;

0 commit comments

Comments
 (0)