Skip to content

Commit

Permalink
Merge pull request #694 from franmomu/add_type_hints_tests
Browse files Browse the repository at this point in the history
Enforce typehints in tests
  • Loading branch information
malarzm authored Aug 16, 2021
2 parents cfa2ec4 + a24e5f8 commit 25a21af
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 48 deletions.
2 changes: 2 additions & 0 deletions Tests/CacheWarmer/PersistentCollectionCacheWarmerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionGenerator;
use Doctrine\Persistence\ManagerRegistry;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand All @@ -19,6 +20,7 @@ class PersistentCollectionCacheWarmerTest extends TestCase
/** @var ContainerInterface */
private $container;

/** @var PersistentCollectionGenerator&MockObject */
private $generatorMock;

/** @var PersistentCollectionCacheWarmer */
Expand Down
25 changes: 21 additions & 4 deletions Tests/Fixtures/Cache/Collections.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,37 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use MongoDB\BSON\ObjectId;

/** @ODM\Document */
class Collections
{
/** @ODM\Id */
/**
* @ODM\Id
*
* @var ObjectId|null
*/
public $id;

/** @ODM\EmbedMany(collectionClass=SomeCollection::class) */
/**
* @ODM\EmbedMany(collectionClass=SomeCollection::class)
*
* @var SomeCollection
*/
public $coll;

/** @ODM\ReferenceMany(collectionClass=SomeCollection::class) */
/**
* @ODM\ReferenceMany(collectionClass=SomeCollection::class)
*
* @var SomeCollection
*/
public $refs;

/** @ODM\EmbedMany(collectionClass=AnotherCollection::class) */
/**
* @ODM\EmbedMany(collectionClass=AnotherCollection::class)
*
* @var AnotherCollection
*/
public $another;
}

Expand Down
13 changes: 11 additions & 2 deletions Tests/Fixtures/DataCollector/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@
namespace Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\DataCollector;

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use MongoDB\BSON\ObjectId;

/** @ODM\Document */
class Category
{
/** @ODM\Id */
/**
* @ODM\Id
*
* @var ObjectId|null
*/
protected $id;

/** @ODM\Field(type="string") */
/**
* @ODM\Field(type="string")
*
* @var string
*/
public $name;

public function __construct(string $name)
Expand Down
18 changes: 15 additions & 3 deletions Tests/Fixtures/Form/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,34 @@
namespace Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form;

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

/** @ODM\Document */
class Category
{
/** @ODM\Id */
/**
* @ODM\Id
*
* @var ObjectId|null
*/
protected $id;

/** @ODM\Field(type="string") */
/**
* @ODM\Field(type="string")
*
* @var string
*/
public $name;

/**
* @ODM\ReferenceMany(
* targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form\Document",
* mappedBy="categories"
* )
*
* @var Collection<int, Document>
*/
public $documents;

Expand All @@ -37,6 +49,6 @@ public function __construct(string $name)
**/
public function __toString()
{
return (string) $this->name;
return $this->name;
}
}
23 changes: 15 additions & 8 deletions Tests/Fixtures/Form/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,25 @@
namespace Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form;

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

/** @ODM\Document */
class Document
{
/** @ODM\Id(strategy="none") */
/**
* @ODM\Id(strategy="none")
*
* @var ObjectId
*/
protected $id;

/** @ODM\Field(type="string") */
/**
* @ODM\Field(type="string")
*
* @var string
*/
public $name;

/**
Expand All @@ -23,14 +32,12 @@ class Document
* inversedBy="documents",
* strategy="atomicSetArray"
* )
*
* @var Collection<int, Category>
*/
public $categories;

/**
* @param ObjectId $id
* @param string $name
*/
public function __construct($id, $name)
public function __construct(ObjectId $id, string $name)
{
$this->id = $id;
$this->name = $name;
Expand All @@ -44,6 +51,6 @@ public function __construct($id, $name)
**/
public function __toString()
{
return (string) $this->name;
return $this->name;
}
}
54 changes: 46 additions & 8 deletions Tests/Fixtures/Form/Guesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,42 @@

namespace Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form;

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

/**
* @ODM\Document
*/
class Guesser
{
/** @ODM\Id(strategy="none") */
/**
* @ODM\Id(strategy="none")
*
* @var ObjectId|null
*/
protected $id;

/** @ODM\Field() */
/**
* @ODM\Field()
*
* @var string|null
*/
public $name;

/** @ODM\Field(type="date") */
/**
* @ODM\Field(type="date")
*
* @var DateTime|null
*/
public $date;

/** @ODM\Field(type="timestamp") */
/**
* @ODM\Field(type="timestamp")
*
* @var DateTime
*/
public $ts;

/**
Expand All @@ -29,20 +48,39 @@ class Guesser
* inversedBy="documents",
* strategy="atomicSetArray"
* )
*
* @var Collection<int, Category>
*/
public $categories;

/** @ODM\Field(type="bool") */
/**
* @ODM\Field(type="bool")
*
* @var bool|null
*/
public $boolField;

/** @ODM\Field(type="float") */
/**
* @ODM\Field(type="float")
*
* @var float|null
*/
public $floatField;

/** @ODM\Field(type="int") */
/**
* @ODM\Field(type="int")
*
* @var int|null
*/
public $intField;

/** @ODM\Field(type="collection") */
/**
* @ODM\Field(type="collection")
*
* @var array
*/
public $collectionField;

/** @var mixed */
public $nonMappedField;
}
18 changes: 11 additions & 7 deletions Tests/Fixtures/Security/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,21 @@
/** @ODM\Document */
class User implements UserInterface
{
/** @ODM\Id(strategy="none") */
/**
* @ODM\Id(strategy="none")
*
* @var ObjectId
*/
protected $id;

/** @ODM\Field(type="string") */
public $name;

/**
* @param ObjectId $id
* @param string $name
* @ODM\Field(type="string")
*
* @var string
*/
public function __construct($id, $name)
public $name;

public function __construct(ObjectId $id, string $name)
{
$this->id = $id;
$this->name = $name;
Expand Down
53 changes: 41 additions & 12 deletions Tests/Fixtures/Validator/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,56 @@
/** @ODM\Document(collection="DoctrineMongoDBBundle_Tests_Validator_Document") */
class Document
{
/** @ODM\Id(strategy="none") */
/**
* @ODM\Id(strategy="none")
*
* @var ObjectId
*/
protected $id;

/** @ODM\Field(type="string") */
/**
* @ODM\Field(type="string")
*
* @var string
*/
public $name;

/** @ODM\Field(type="hash") */
/**
* @ODM\Field(type="hash")
*
* @var array
*/
public $hash;

/** @ODM\Field(type="collection") */
/**
* @ODM\Field(type="collection")
*
* @var array
*/
public $collection;

/** @ODM\ReferenceOne(targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Validator\Document") */
/**
* @ODM\ReferenceOne(targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Validator\Document")
*
* @var Document|null
*/
public $referenceOne;

/** @ODM\EmbedOne(targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Validator\EmbeddedDocument") */
/**
* @ODM\EmbedOne(targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Validator\EmbeddedDocument")
*
* @var EmbeddedDocument|null
*/
public $embedOne;

/** @ODM\EmbedMany(targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Validator\EmbeddedDocument") */
public $embedMany = [];

/**
* @param ObjectId $id
* @ODM\EmbedMany(targetDocument="Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Validator\EmbeddedDocument")
*
* @var EmbeddedDocument[]
*/
public function __construct($id)
public $embedMany = [];

public function __construct(ObjectId $id)
{
$this->id = $id;
}
Expand All @@ -43,6 +68,10 @@ public function __construct($id)
/** @ODM\EmbeddedDocument */
class EmbeddedDocument
{
/** @ODM\Field(type="string") */
/**
* @ODM\Field(type="string")
*
* @var string
*/
public $name;
}
4 changes: 0 additions & 4 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,4 @@
<rule ref="Squiz.Classes.ClassFileName.NoMatch">
<exclude-pattern>Tests/*</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingAnyTypeHint">
<exclude-pattern>Tests/*</exclude-pattern>
</rule>
</ruleset>

0 comments on commit 25a21af

Please sign in to comment.