Skip to content

Commit 745aeb7

Browse files
authored
Merge pull request #1557 from scyzoryck/fix-doctrine-odm-tests
Doctrine ODM: fix tests for 2.0
2 parents 3c18cb8 + 51f6a49 commit 745aeb7

6 files changed

Lines changed: 44 additions & 8 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ jobs:
4343
if: ${{ matrix.composer-stability }}
4444
run: composer config minimum-stability ${{ matrix.composer-stability }}
4545

46-
- name: Uninstall Doctrine ODM
47-
run: composer remove doctrine/phpcr-odm jackalope/jackalope-doctrine-dbal --no-update --dev
48-
4946
- name: "Install dependencies with Composer"
5047
uses: "ramsey/composer-install@v1"
5148
with:

phpstan/no-attributes.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
parameters:
22
ignoreErrors:
33
- '~Call to an undefined method Reflection.*::getAttributes\(\)~'
4+
- '~Instantiated class Doctrine\\ODM\\PHPCR\\Mapping\\Driver\\AttributeDriver not found~'

tests/Fixtures/DoctrinePHPCR/Author.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@
55
namespace JMS\Serializer\Tests\Fixtures\DoctrinePHPCR;
66

77
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
8+
use Doctrine\ODM\PHPCR\Mapping\Attributes\Document;
9+
use Doctrine\ODM\PHPCR\Mapping\Attributes\Field;
10+
use Doctrine\ODM\PHPCR\Mapping\Attributes\Id;
811
use JMS\Serializer\Annotation\SerializedName;
912

1013
/** @PHPCRODM\Document */
14+
#[Document]
1115
class Author
1216
{
1317
/**
1418
* @PHPCRODM\Id()
1519
*/
20+
#[Id]
1621
protected $id;
1722

1823
/**
1924
* @PHPCRODM\Field(type="string")
2025
* @SerializedName("full_name")
2126
*/
2227
#[SerializedName(name: 'full_name')]
28+
#[Field(type: 'string')]
2329
private $name;
2430

2531
public function __construct($name)

tests/Fixtures/DoctrinePHPCR/BlogPost.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
use Doctrine\Common\Collections\ArrayCollection;
88
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
9+
use Doctrine\ODM\PHPCR\Mapping\Attributes\Document;
10+
use Doctrine\ODM\PHPCR\Mapping\Attributes\Field;
11+
use Doctrine\ODM\PHPCR\Mapping\Attributes\Id;
12+
use Doctrine\ODM\PHPCR\Mapping\Attributes\ReferenceMany;
13+
use Doctrine\ODM\PHPCR\Mapping\Attributes\ReferenceOne;
914
use JMS\Serializer\Annotation\Groups;
1015
use JMS\Serializer\Annotation\SerializedName;
1116
use JMS\Serializer\Annotation\Type;
@@ -18,30 +23,35 @@
1823
* @XmlRoot("blog-post")
1924
*/
2025
#[XmlRoot(name: 'blog-post')]
26+
#[Document]
2127
class BlogPost
2228
{
2329
/**
2430
* @PHPCRODM\Id()
2531
*/
32+
#[Id]
2633
protected $id;
2734

2835
/**
2936
* @PHPCRODM\Field(type="string")
3037
* @Groups({"comments","post"})
3138
*/
3239
#[Groups(groups: ['comments', 'post'])]
40+
#[Field(type: 'string')]
3341
private $title;
3442

3543
/**
3644
* @PHPCRODM\Field(type="string")
3745
*/
46+
#[Field(type: 'string')]
3847
protected $slug;
3948

4049
/**
4150
* @PHPCRODM\Field(type="date")
4251
* @XmlAttribute
4352
*/
4453
#[XmlAttribute]
54+
#[Field(type: 'date')]
4555
private $createdAt;
4656

4757
/**
@@ -54,6 +64,7 @@ class BlogPost
5464
* @Groups({"post"})
5565
* @XmlAttribute
5666
*/
67+
#[Field(type: 'boolean')]
5768
#[Type(name: 'integer')]
5869
#[SerializedName(name: 'is_published')]
5970
#[Groups(groups: ['post'])]
@@ -67,13 +78,15 @@ class BlogPost
6778
*/
6879
#[XmlList(entry: 'comment', inline: true)]
6980
#[Groups(groups: ['comments'])]
81+
#[ReferenceMany(targetDocument:'Comment', property:'blogPost')]
7082
private $comments;
7183

7284
/**
7385
* @PHPCRODM\ReferenceOne(targetDocument="Author")
7486
* @Groups({"post"})
7587
*/
7688
#[Groups(groups: ['post'])]
89+
#[ReferenceOne(targetDocument:'Author')]
7790
private $author;
7891

7992
public function __construct($title, Author $author, \DateTime $createdAt)

tests/Fixtures/DoctrinePHPCR/Comment.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,25 @@
66

77
use Doctrine\Common\Collections\ArrayCollection;
88
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
9+
use Doctrine\ODM\PHPCR\Mapping\Attributes\Document;
10+
use Doctrine\ODM\PHPCR\Mapping\Attributes\Field;
11+
use Doctrine\ODM\PHPCR\Mapping\Attributes\Id;
12+
use Doctrine\ODM\PHPCR\Mapping\Attributes\ReferenceOne;
913

1014
/** @PHPCRODM\Document */
15+
#[Document]
1116
class Comment
1217
{
1318
/**
1419
* @PHPCRODM\Id()
1520
*/
21+
#[Id]
1622
protected $id;
1723

1824
/**
1925
* @PHPCRODM\ReferenceOne(targetDocument="Author")
2026
*/
27+
#[ReferenceOne(targetDocument:'Author')]
2128
private $author;
2229

2330
/** @PHPCRODM\ReferenceOne(targetDocument="BlogPost") */
@@ -26,6 +33,7 @@ class Comment
2633
/**
2734
* @PHPCRODM\Field(type="string")
2835
*/
36+
#[Field(type: 'string')]
2937
private $text;
3038

3139
public function __construct(Author $author, $text)

tests/Metadata/Driver/DoctrinePHPCRDriverTest.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
use Doctrine\ODM\PHPCR\Configuration;
99
use Doctrine\ODM\PHPCR\DocumentManager;
1010
use Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver as DoctrinePHPCRDriver;
11+
use Doctrine\ODM\PHPCR\Mapping\Driver\AttributeDriver as AttributeDoctrinePHPCRDriver;
1112
use Doctrine\Persistence\ManagerRegistry;
1213
use JMS\Serializer\Metadata\Driver\AnnotationDriver;
14+
use JMS\Serializer\Metadata\Driver\AnnotationOrAttributeDriver;
1315
use JMS\Serializer\Metadata\Driver\DoctrinePHPCRTypeDriver;
1416
use JMS\Serializer\Naming\IdenticalPropertyNamingStrategy;
1517
use JMS\Serializer\Tests\Fixtures\BlogPost;
@@ -101,10 +103,15 @@ protected function getDocumentManager()
101103
$config = new Configuration();
102104
$config->setProxyDir(sys_get_temp_dir() . '/JMSDoctrineTestProxies');
103105
$config->setProxyNamespace('JMS\Tests\Proxies');
104-
assert(class_exists(DoctrinePHPCRDriver::class));
105-
$config->setMetadataDriverImpl(
106-
new DoctrinePHPCRDriver(new AnnotationReader(), __DIR__ . '/../../Fixtures/DoctrinePHPCR'),
107-
);
106+
if (class_exists(DoctrinePHPCRDriver::class)) {
107+
$config->setMetadataDriverImpl(
108+
new DoctrinePHPCRDriver(new AnnotationReader(), __DIR__ . '/../../Fixtures/DoctrinePHPCR'),
109+
);
110+
} else {
111+
$config->setMetadataDriverImpl(
112+
new AttributeDoctrinePHPCRDriver([__DIR__ . '/../../Fixtures/DoctrinePHPCR']),
113+
);
114+
}
108115

109116
$session = $this->getMockBuilder(SessionInterface::class)->getMock();
110117

@@ -113,7 +120,11 @@ protected function getDocumentManager()
113120

114121
public function getAnnotationDriver()
115122
{
116-
return new AnnotationDriver(new AnnotationReader(), new IdenticalPropertyNamingStrategy());
123+
if (class_exists(DoctrinePHPCRDriver::class)) {
124+
return new AnnotationDriver(new AnnotationReader(), new IdenticalPropertyNamingStrategy());
125+
} else {
126+
return new AnnotationOrAttributeDriver(new IdenticalPropertyNamingStrategy());
127+
}
117128
}
118129

119130
protected function getDoctrinePHPCRDriver()

0 commit comments

Comments
 (0)