Skip to content

Commit

Permalink
Merge pull request #857 from doctrine/more-attributes
Browse files Browse the repository at this point in the history
fix test setup
  • Loading branch information
dbu authored Dec 4, 2023
2 parents 9213f3a + 4ce52b9 commit 05664fa
Show file tree
Hide file tree
Showing 62 changed files with 325 additions and 481 deletions.
12 changes: 6 additions & 6 deletions lib/Doctrine/ODM/PHPCR/Mapping/Attributes/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public function __construct(
string $repositoryClass = null,
string $translator = null,
array $mixins = null,
bool $inheritMixins = true,
bool|null $inheritMixins = null,
string $versionable = null,
bool $referenceable = false,
bool $uniqueNodeType = false,
array $childClasses = [],
bool $isLeaf = false,
bool|null $referenceable = null,
bool|null $uniqueNodeType = null,
string|array|null $childClasses = null,
bool|null $isLeaf = null,
) {
$this->nodeType = $nodeType;
$this->repositoryClass = $repositoryClass;
Expand All @@ -29,7 +29,7 @@ public function __construct(
$this->versionable = $versionable;
$this->referenceable = $referenceable;
$this->uniqueNodeType = $uniqueNodeType;
$this->childClasses = $childClasses;
$this->childClasses = $childClasses ? (array) $childClasses : null;
$this->isLeaf = $isLeaf;
}
}
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/PHPCR/Mapping/Driver/AttributeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function loadMetadataForClass($className, PersistenceClassMetadata $metad
$metadata->setTranslator($documentAttribute->translator);
}

if ([] !== $documentAttribute->childClasses) {
if ($documentAttribute->childClasses) {
$metadata->setChildClasses($documentAttribute->childClasses);
}

Expand Down
9 changes: 4 additions & 5 deletions tests/Doctrine/Tests/Models/Blog/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@

namespace Doctrine\Tests\Models\Blog;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR;

/**
* Comment will be a child of the Post in the test scenario
*
* Used for Join tests
*
* @PHPCRODM\Document()
*/
#[PHPCR\Document]
class Comment
{
/** @PHPCRODM\Id() */
#[PHPCR\Id]
public $id;

/** @PHPCRODM\Field(type="string") */
#[PHPCR\Field(type: 'string')]
public $title;
}
12 changes: 5 additions & 7 deletions tests/Doctrine/Tests/Models/Blog/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@

namespace Doctrine\Tests\Models\Blog;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR;

/**
* @PHPCRODM\Document()
*/
#[PHPCR\Document]
class Post
{
/** @PHPCRODM\Id() */
#[PHPCR\Id]
public $id;

/** @PHPCRODM\Field(type="string") */
#[PHPCR\Field(type: 'string')]
public $title;

/** @PHPCRODM\Field(type="string") */
#[PHPCR\Field(type: 'string')]
public $username;
}
16 changes: 7 additions & 9 deletions tests/Doctrine/Tests/Models/Blog/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@

namespace Doctrine\Tests\Models\Blog;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR;

/**
* @PHPCRODM\Document()
*/
#[PHPCR\Document]
class User
{
/** @PHPCRODM\Id() */
#[PHPCR\Id]
public $id;

/** @PHPCRODM\Field(type="string") */
#[PHPCR\Field(type: 'string')]
public $username;

/** @PHPCRODM\Field(type="string") */
#[PHPCR\Field(type: 'string')]
public $name;

/** @PHPCRODM\Field(type="string") */
#[PHPCR\Field(type: 'string')]
public $status;

/** @PHPCRODM\Field(type="long", nullable=true) */
#[PHPCR\Field(type: 'long', nullable: true)]
public $age;
}
20 changes: 8 additions & 12 deletions tests/Doctrine/Tests/Models/CMS/CmsAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,27 @@

use Doctrine\ODM\PHPCR\DocumentRepository;
use Doctrine\ODM\PHPCR\Id\RepositoryIdInterface;
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR;

/**
* @PHPCRODM\Document(repositoryClass="Doctrine\Tests\Models\CMS\CmsAddressRepository", referenceable=true)
*/
#[PHPCR\Document(repositoryClass: CmsAddressRepository::class, referenceable: true)]
class CmsAddress
{
/** @PHPCRODM\Id(strategy="repository") */
#[PHPCR\Id(strategy: 'repository')]
public $id;

/** @PHPCRODM\Field(type="string") */
#[PHPCR\Field(type: 'string')]
public $country;

/** @PHPCRODM\Field(type="string") */
#[PHPCR\Field(type: 'string')]
public $zip;

/** @PHPCRODM\Field(type="string") */
#[PHPCR\Field(type: 'string')]
public $city;

/** @PHPCRODM\ReferenceOne(targetDocument="CmsUser") */
#[PHPCR\ReferenceOne(targetDocument: CmsUser::class)]
public $user;

/**
* @PHPCRODM\Uuid
*/
#[PHPCR\Uuid]
public $uuid;

public function getId()
Expand Down
19 changes: 9 additions & 10 deletions tests/Doctrine/Tests/Models/CMS/CmsArticle.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,30 @@
namespace Doctrine\Tests\Models\CMS;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR;
use mysql_xdevapi\CrudOperationBindable;

/**
* @PHPCRODM\Document
*/
#[PHPCR\Document]
class CmsArticle
{
/** @PHPCRODM\Id */
#[PHPCR\Id]
public $id;

/** @PHPCRODM\Field(type="string") */
#[PHPCR\Field(type: 'string')]
public $topic;

/** @PHPCRODM\Field(type="string") */
#[PHPCR\Field(type: 'string')]
public $text;

/** @PHPCRODM\ReferenceOne(targetDocument="CmsUser") */
#[PHPCR\ReferenceOne(targetDocument: CmsUser::class)]
public $user;

public $comments;

/** @PHPCRODM\ReferenceMany(targetDocument="CmsArticlePerson") */
#[PHPCR\ReferenceMany(targetDocument: CmsArticlePerson::class)]
public $persons;

/** @PHPCRODM\Field(type="binary", nullable=true) */
#[PHPCR\Field(type: 'binary', nullable: true)]
public $attachments;

public function __construct()
Expand Down
14 changes: 4 additions & 10 deletions tests/Doctrine/Tests/Models/CMS/CmsArticleFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@

namespace Doctrine\Tests\Models\CMS;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR;

/**
* @PHPCRODM\Document(childClasses={"Doctrine\Tests\Models\CMS\CmsArticle"})
*/
#[PHPCR\Document(childClasses: CmsArticle::class)]
class CmsArticleFolder
{
/**
* @PHPCRODM\Id
*/
#[PHPCR\Id]
public $id;

/**
* @PHPCRODM\Children()
*/
#[PHPCR\Children]
public $articles;
}
12 changes: 5 additions & 7 deletions tests/Doctrine/Tests/Models/CMS/CmsArticlePerson.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\PHPCR\DocumentRepository;
use Doctrine\ODM\PHPCR\Id\RepositoryIdInterface;
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR;

/**
* @PHPCRODM\Document(repositoryClass="Doctrine\Tests\Models\CMS\CmsArticlePersonRepository", referenceable=true)
*/
#[PHPCR\Document(repositoryClass: CmsArticlePersonRepository::class, referenceable: true)]
class CmsArticlePerson
{
/** @PHPCRODM\Id(strategy="repository") */
#[PHPCR\Id(strategy: 'repository')]
public $id;

/** @PHPCRODM\Field(type="string", nullable=true) */
#[PHPCR\Field(type: 'string', nullable: true)]
public $name;

/** @PHPCRODM\Referrers(referencedBy="persons", referringDocument="Doctrine\Tests\Models\CMS\CmsArticle", cascade="persist") */
#[PHPCR\Referrers(referencedBy: 'persons', referringDocument: CmsArticle::class, cascade: 'persist')]
public $articlesReferrers;

public function __construct()
Expand Down
12 changes: 5 additions & 7 deletions tests/Doctrine/Tests/Models/CMS/CmsAuditItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

namespace Doctrine\Tests\Models\CMS;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR;

/**
* @PHPCRODM\Document
*/
#[PHPCR\Document]
class CmsAuditItem
{
/** @PHPCRODM\Id */
#[PHPCR\Id]
public $id;

/** @PHPCRODM\Field(type="string") */
#[PHPCR\Field(type: 'string')]
public $message;

/** @PHPCRODM\Field(type="string", nullable=true) */
#[PHPCR\Field(type: 'string', nullable: true)]
public $username;
}
18 changes: 4 additions & 14 deletions tests/Doctrine/Tests/Models/CMS/CmsBlogFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@

namespace Doctrine\Tests\Models\CMS;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR;

/**
* @PHPCRODM\Document(
* childClasses={
* "Doctrine\Tests\Models\CMS\CmsBlogPost"
* }
* )
*/
#[PHPCR\Document(childClasses: CmsBlogPost::class)]
class CmsBlogFolder
{
/**
* @PHPCRODM\Id()
*/
#[PHPCR\Id]
public $id;

/**
* @PHPCRODM\Children()
*/
#[PHPCR\Children]
public $posts;
}
12 changes: 5 additions & 7 deletions tests/Doctrine/Tests/Models/CMS/CmsBlogInvalidChild.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@

namespace Doctrine\Tests\Models\CMS;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR;

/**
* @PHPCRODM\Document()
*/
#[PHPCR\Document]
class CmsBlogInvalidChild
{
/** @PHPCRODM\Id(strategy="parent") */
#[PHPCR\Id(strategy: 'parent')]
public $id;

/** @PHPCRODM\NodeName() */
#[PHPCR\Nodename]
public $name;

/** @PHPCRODM\ParentDocument() */
#[PHPCR\ParentDocument]
public $parent;
}
12 changes: 5 additions & 7 deletions tests/Doctrine/Tests/Models/CMS/CmsBlogPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@

namespace Doctrine\Tests\Models\CMS;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR;

/**
* @PHPCRODM\Document(isLeaf=true)
*/
#[PHPCR\Document(isLeaf: true)]
class CmsBlogPost
{
/** @PHPCRODM\Id(strategy="parent") */
#[PHPCR\Id(strategy: 'parent')]
public $id;

/** @PHPCRODM\NodeName() */
#[PHPCR\Nodename]
public $name;

/** @PHPCRODM\ParentDocument() */
#[PHPCR\ParentDocument]
public $parent;
}
12 changes: 5 additions & 7 deletions tests/Doctrine/Tests/Models/CMS/CmsGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@

namespace Doctrine\Tests\Models\CMS;

use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR;

/**
* @PHPCRODM\Document(referenceable=true)
*/
#[PHPCR\Document(referenceable: true)]
class CmsGroup
{
/** @PHPCRODM\Id */
#[PHPCR\Id]
public $id;

/** @PHPCRODM\Field(type="string") */
#[PHPCR\Field(type: 'string')]
public $name;

/** @PHPCRODM\ReferenceMany(targetDocument="CmsUser", cascade="persist") */
#[PHPCR\ReferenceMany(targetDocument: CmsUser::class, cascade: 'persist')]
public $users;

public function setName($name)
Expand Down
Loading

0 comments on commit 05664fa

Please sign in to comment.