Skip to content

Commit

Permalink
switch to attributes in test fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Jan 8, 2024
1 parent a159897 commit f876aa3
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 120 deletions.
26 changes: 0 additions & 26 deletions src/DependencyInjection/Compiler/DoctrinePhpcrMappingsPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler;

use Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver;
use Doctrine\ODM\PHPCR\Mapping\Driver\AttributeDriver;
use Doctrine\ODM\PHPCR\Mapping\Driver\XmlDriver;
use Doctrine\ODM\PHPCR\Mapping\Driver\YamlDriver;
Expand Down Expand Up @@ -122,31 +121,6 @@ public static function createPhpMappingDriver(
return new self($driver, $mappings, $managerParameters, $enabledParameter, $aliasMap);
}

/**
* @param array $namespaces List of namespaces that are handled with annotation mapping
* @param array $directories List of directories to look for annotated classes
* @param string[] $managerParameters List of parameters that could which object manager name
* your bundle uses. This compiler pass will automatically
* append the parameter name for the default entity manager
* to this list.
* @param string|bool $enabledParameter Service container parameter that must be present to
* enable the mapping. Set to false to not do any check,
* optional.
* @param string[] $aliasMap map of alias to namespace
*/
public static function createAnnotationMappingDriver(
array $namespaces,
array $directories,
array $managerParameters = [],
$enabledParameter = false,
array $aliasMap = []
): self {
$reader = new Reference('doctrine_phpcr.odm.metadata.annotation_reader');
$driver = new Definition(AnnotationDriver::class, [$reader, $directories]);

return new self($driver, $namespaces, $managerParameters, $enabledParameter, $aliasMap);
}

/**
* @param string[] $namespaces List of namespaces that are handled with annotation mapping
* @param string[] $directories List of directories to look for annotated classes
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/DoctrinePHPCRExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ private function loadOdmDocumentManagerMappingInformation(array $documentManager

$documentManager['mappings']['__PHPCRODM__'] = [
'dir' => \dirname($class->getFileName()),
'type' => 'annotation',
'type' => 'attribute',
'prefix' => 'Doctrine\ODM\PHPCR\Document',
'is_bundle' => false,
'mapping' => true,
Expand Down
2 changes: 0 additions & 2 deletions src/Resources/config/odm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<parameter key="doctrine_phpcr.odm.metadata.yml.class">Doctrine\Bundle\PHPCRBundle\Mapping\Driver\YamlDriver</parameter>
<parameter key="doctrine_phpcr.odm.metadata.php.class">Doctrine\Persistence\Mapping\Driver\StaticPHPDriver</parameter>
<parameter key="doctrine_phpcr.odm.metadata.driver_chain.class">Doctrine\Persistence\Mapping\Driver\MappingDriverChain</parameter>
<parameter key="doctrine_phpcr.odm.metadata.annotation.class">Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver</parameter>
<parameter key="doctrine_phpcr.odm.metadata.attribute.class">Doctrine\ODM\PHPCR\Mapping\Driver\AttributeDriver</parameter>
</parameters>
<services>
Expand All @@ -42,7 +41,6 @@
<argument type="service" id="doctrine_phpcr"/>
</service>

<service id="doctrine_phpcr.odm.metadata.annotation_reader" alias="annotation_reader" public="false" />
<service id="doctrine_phpcr.odm.metadata.attribute_reader" alias="attribute_reader" public="false" />

<service
Expand Down
26 changes: 7 additions & 19 deletions tests/Fixtures/App/Document/ReferrerDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,24 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR;

/**
* @PHPCR\Document()
*/
#[PHPCR\Document]
class ReferrerDocument
{
/**
* @PHPCR\Id(strategy="assigned")
*/
#[PHPCR\Id(strategy: 'assigned')]
public string $id;

/**
* @PHPCR\ReferenceOne()
*/
#[PHPCR\ReferenceOne]
protected $single;

/**
* @PHPCR\ReferenceMany()
*/
#[PHPCR\ReferenceMany]
protected Collection $documents;

/**
* @PHPCR\ReferenceOne(targetDocument="Doctrine\Bundle\PHPCRBundle\Tests\Fixtures\App\Document\TestDocument")
*/
#[PHPCR\ReferenceOne(targetDocument: TestDocument::class)]
protected $testDocument;

/**
* @PHPCR\ReferenceMany(targetDocument="Doctrine\Bundle\PHPCRBundle\Tests\Fixtures\App\Document\TestDocument")
*/
#[PHPCR\ReferenceMany(targetDocument: TestDocument::class)]
protected Collection $testDocuments;

public function __construct()
Expand Down
98 changes: 28 additions & 70 deletions tests/Fixtures/App/Document/TestDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,115 +4,73 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;
use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR;

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

/**
* @PHPCR\ParentDocument()
*/
#[PHPCR\ParentDocument]
public $parent;

/**
* @PHPCR\Nodename()
*/
#[PHPCR\Nodename]
public string $nodename;

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

/**
* @PHPCR\Child()
*/
#[PHPCR\Child]
public $child;

/**
* @PHPCR\Children()
*/
#[PHPCR\Children]
protected Collection $children;

/**
* @PHPCR\Referrers(
* referringDocument="Doctrine\Bundle\PHPCRBundle\Tests\Fixtures\App\Document\ReferrerDocument",
* referencedBy="documents"
* )
*/
#[PHPCR\Referrers(referencedBy: 'documents', referringDocument: ReferrerDocument::class)]
protected Collection $referrers;

/**
* @PHPCR\MixedReferrers()
*/
#[PHPCR\MixedReferrers]
protected Collection $mixedReferrers;

/**
* @PHPCR\Field(type="boolean")
*/
#[PHPCR\Field(type: 'boolean')]
public bool $bool;

/**
* @PHPCR\Field(type="date")
*/
#[PHPCR\Field(type: 'date')]
public \DateTimeInterface $date;

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

/**
* @PHPCR\Field(type="double")
*/
#[PHPCR\Field(type: 'double')]
public float $number;

/**
* @PHPCR\Field(type="long")
*/
#[PHPCR\Field(type: 'long')]
public int $long;

/**
* @PHPCR\Field(type="int")
*/
#[PHPCR\Field(type: 'int')]
public int $integer;

/**
* @PHPCR\Field(type="boolean", multivalue=true, nullable=true)
*/
public array $mbool;
#[PHPCR\Field(type: 'boolean', multivalue: true, nullable: true)]
public ?array $mbool;

/**
* @PHPCR\Field(type="date", multivalue=true, nullable=true)
*/
public array $mdate;
#[PHPCR\Field(type: 'date', multivalue: true, nullable: true)]
public ?array $mdate;

/**
* @PHPCR\Field(type="string", multivalue=true, nullable=true)
*/
public array $mtext;
#[PHPCR\Field(type: 'string', multivalue: true, nullable: true)]
public ?array $mtext;

/**
* @PHPCR\Field(type="double", multivalue=true, nullable=true)
*/
public array $mnumber;
#[PHPCR\Field(type: 'double', multivalue: true, nullable: true)]
public ?array $mnumber;

/**
* @PHPCR\Field(type="long", multivalue=true, nullable=true)
*/
public array $mlong;
#[PHPCR\Field(type: 'long', multivalue: true, nullable: true)]
public ?array $mlong;

/**
* @PHPCR\Field(type="int", multivalue=true, nullable=true)
*/
public array $minteger;
#[PHPCR\Field(type: 'int', multivalue: true, nullable: true)]
public ?array $minteger;

public function __construct()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/App/config/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ doctrine_phpcr:
fr: [en, de]
mappings:
test_additional:
type: annotation
type: attribute
prefix: Doctrine\Bundle\PHPCRBundle\Tests\Fixtures\App\Document
dir: "%kernel.project_dir%/Document"
is_bundle: false
1 change: 0 additions & 1 deletion tests/Fixtures/App/config/framework.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
framework:
secret: test
annotations: ~
property_access: ~
test: ~
form: ~
Expand Down

0 comments on commit f876aa3

Please sign in to comment.