Skip to content

Commit

Permalink
Fix some SA issues in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Jun 21, 2021
1 parent 4f44b48 commit 60eaa3b
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 40 deletions.
20 changes: 0 additions & 20 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,6 @@ parameters:
count: 1
path: tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php

-
message: "#^Parameter \\#1 \\$object of method Doctrine\\\\ODM\\\\MongoDB\\\\DocumentManager\\:\\:detach\\(\\) expects object, float\\|int given\\.$#"
count: 1
path: tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php

-
message: "#^Parameter \\#2 \\$currency of class Documents\\\\Ecommerce\\\\Money constructor expects Documents\\\\Ecommerce\\\\Currency, int given\\.$#"
count: 6
path: tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php

-
message: "#^Cannot call method getCount\\(\\) on array\\|int\\|object\\.$#"
count: 1
Expand Down Expand Up @@ -154,11 +144,6 @@ parameters:
count: 2
path: tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php

-
message: "#^Parameter \\#1 \\$coll of method Doctrine\\\\ODM\\\\MongoDB\\\\UnitOfWork\\:\\:isCollectionScheduledForUpdate\\(\\) expects Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\PersistentCollectionInterface, Doctrine\\\\Common\\\\Collections\\\\ArrayCollection\\<mixed, mixed\\> given\\.$#"
count: 1
path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1011Test.php

-
message: "#^Comparison operation \"\\<\" between \\(array\\|float\\|int\\) and 0 results in an error\\.$#"
count: 1
Expand Down Expand Up @@ -229,11 +214,6 @@ parameters:
count: 1
path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php

-
message: "#^Access to an undefined property Documents\\\\CmsArticle\\:\\:\\$title\\.$#"
count: 4
path: tests/Doctrine/ODM/MongoDB/Tests/Persisters/PersistenceBuilderTest.php

-
message: "#^Parameter \\#1 \\$primer of method Doctrine\\\\ODM\\\\MongoDB\\\\Query\\\\Builder\\:\\:prime\\(\\) expects bool\\|\\(callable\\(\\)\\: mixed\\), 1 given\\.$#"
count: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Doctrine\ODM\MongoDB\Tests\BaseTest;
use Documents\File;
use Documents\ProfileNotify;
use stdClass;

use function assert;
use function get_class;
Expand Down Expand Up @@ -47,7 +48,7 @@ public function testCollectionClassHasToImplementCommonInterface()
'fieldName' => 'assoc',
'reference' => true,
'type' => 'many',
'collectionClass' => 'stdClass',
'collectionClass' => stdClass::class,
]);
}

Expand Down
11 changes: 7 additions & 4 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/EcommerceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ public function setUp(): void
{
parent::setUp();

$currencies = ['USD' => 1, 'EURO' => 1.7, 'JPN' => 0.0125];
$currencies = [];
$multipliers = ['USD' => 1, 'EURO' => 1.7, 'JPN' => 0.0125];

foreach ($currencies as $name => &$multiplier) {
$multiplier = new Currency($name, $multiplier);
$this->dm->persist($multiplier);
foreach ($multipliers as $currencyName => $multiplier) {
$currency = new Currency($currencyName, $multiplier);
$this->dm->persist($currency);

$currencies[$currencyName] = $currency;
}

$product = new ConfigurableProduct('T-Shirt');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionInterface;
use Doctrine\ODM\MongoDB\Tests\BaseTest;

class GH1011Test extends BaseTest
Expand Down Expand Up @@ -33,7 +34,9 @@ public function testReplaceCollection()
$doc->embeds = new ArrayCollection();
$doc->embeds->add(new GH1011Embedded('test2'));
$this->uow->computeChangeSets();
$this->assertInstanceOf(PersistentCollectionInterface::class, $doc->embeds);
$this->assertTrue($this->uow->isCollectionScheduledForUpdate($doc->embeds));
$this->assertInstanceOf(PersistentCollectionInterface::class, $oldCollection);
$this->assertFalse($this->uow->isCollectionScheduledForDeletion($oldCollection));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testShortNameLossOnReplacingMiddleEmbeddedDocOfNestedEmbedding()
$this->dm->flush();
$this->assertTrue(true);
} catch (Notice $ex) {
$this->fail($ex);
$this->fail($ex->getMessage());
}
}
}
Expand Down
26 changes: 14 additions & 12 deletions tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Doctrine\ODM\MongoDB\Tests\BaseTest;
use Doctrine\ODM\MongoDB\Types\Type;
use Doctrine\ODM\MongoDB\Utility\CollectionHelper;
use DoctrineGlobal_Article;
use DoctrineGlobal_User;
use Documents\Account;
use Documents\Address;
use Documents\Album;
Expand Down Expand Up @@ -139,13 +141,13 @@ public function testMapAssocationInGlobalNamespace()
{
require_once __DIR__ . '/Documents/GlobalNamespaceDocument.php';

$cm = new ClassMetadata('DoctrineGlobal_Article');
$cm = new ClassMetadata(DoctrineGlobal_Article::class);
$cm->mapManyEmbedded([
'fieldName' => 'author',
'targetDocument' => 'DoctrineGlobal_User',
'targetDocument' => DoctrineGlobal_User::class,
]);

$this->assertEquals('DoctrineGlobal_User', $cm->fieldMappings['author']['targetDocument']);
$this->assertEquals(DoctrineGlobal_User::class, $cm->fieldMappings['author']['targetDocument']);
}

public function testMapManyToManyJoinTableDefaults()
Expand Down Expand Up @@ -182,11 +184,11 @@ public function testSetDiscriminatorMapInGlobalNamespace()
{
require_once __DIR__ . '/Documents/GlobalNamespaceDocument.php';

$cm = new ClassMetadata('DoctrineGlobal_User');
$cm->setDiscriminatorMap(['descr' => 'DoctrineGlobal_Article', 'foo' => 'DoctrineGlobal_User']);
$cm = new ClassMetadata(DoctrineGlobal_User::class);
$cm->setDiscriminatorMap(['descr' => DoctrineGlobal_Article::class, 'foo' => DoctrineGlobal_User::class]);

$this->assertEquals('DoctrineGlobal_Article', $cm->discriminatorMap['descr']);
$this->assertEquals('DoctrineGlobal_User', $cm->discriminatorMap['foo']);
$this->assertEquals(DoctrineGlobal_Article::class, $cm->discriminatorMap['descr']);
$this->assertEquals(DoctrineGlobal_User::class, $cm->discriminatorMap['foo']);
}

/**
Expand All @@ -196,16 +198,16 @@ public function testSetSubClassesInGlobalNamespace()
{
require_once __DIR__ . '/Documents/GlobalNamespaceDocument.php';

$cm = new ClassMetadata('DoctrineGlobal_User');
$cm->setSubclasses(['DoctrineGlobal_Article']);
$cm = new ClassMetadata(DoctrineGlobal_User::class);
$cm->setSubclasses([DoctrineGlobal_Article::class]);

$this->assertEquals('DoctrineGlobal_Article', $cm->subClasses[0]);
$this->assertEquals(DoctrineGlobal_Article::class, $cm->subClasses[0]);
}

public function testDuplicateFieldMapping()
{
$cm = new ClassMetadata(CmsUser::class);
$a1 = ['reference' => true, 'type' => 'many', 'fieldName' => 'name', 'targetDocument' => 'stdClass'];
$a1 = ['reference' => true, 'type' => 'many', 'fieldName' => 'name', 'targetDocument' => stdClass::class];
$a2 = ['type' => 'string', 'fieldName' => 'name'];

$cm->mapField($a1);
Expand Down Expand Up @@ -309,7 +311,7 @@ public function testDefaultDiscriminatorField()
'fieldName' => 'assocWithTargetDocument',
'reference' => true,
'type' => 'one',
'targetDocument' => 'stdClass',
'targetDocument' => stdClass::class,
]);

$cm->mapField([
Expand Down
2 changes: 2 additions & 0 deletions tests/Documents/CmsArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class CmsArticle
/** @ODM\Field(type="string") */
public $topic;
/** @ODM\Field(type="string") */
public $title;
/** @ODM\Field(type="string") */
public $text;
/** @ODM\ReferenceOne(targetDocument=CmsUser::class) */
public $user;
Expand Down
16 changes: 14 additions & 2 deletions tests/Documents/Functional/Ticket/GH683/ParentDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,29 @@

namespace Documents\Functional\Ticket\GH683;

use Doctrine\Common\Collections\Collection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/** @ODM\Document(collection="gh683_test") */
class ParentDocument
{
/** @ODM\Id */
public $id;

/** @ODM\Field(type="string") */
public $name;
/** @ODM\EmbedOne(targetDocument=AbstractEmbedded::class) */

/**
* @ODM\EmbedOne(targetDocument=AbstractEmbedded::class)
*
* @var AbstractEmbedded|null
*/
public $embedOne;
/** @ODM\EmbedMany(targetDocument=AbstractEmbedded::class) */

/**
* @ODM\EmbedMany(targetDocument=AbstractEmbedded::class)
*
* @var Collection<int, AbstractEmbedded>
*/
public $embedMany;
}

0 comments on commit 60eaa3b

Please sign in to comment.