Skip to content

Commit 3971d32

Browse files
committed
Use attributes for test extension
1 parent 96b2cb6 commit 3971d32

File tree

6 files changed

+38
-26
lines changed

6 files changed

+38
-26
lines changed

tests/Gedmo/Mapping/Fixture/Document/User.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class User
3434
*
3535
* @ODM\Field(type="string")
3636
*/
37+
#[Ext\Encode(type: 'sha1', secret: 'xxx')]
3738
#[ODM\Field(type: Type::STRING)]
3839
private ?string $name = null;
3940

@@ -42,6 +43,7 @@ class User
4243
*
4344
* @ODM\Field(type="string")
4445
*/
46+
#[Ext\Encode(type: 'md5')]
4547
#[ODM\Field(type: Type::STRING)]
4648
private ?string $password = null;
4749

tests/Gedmo/Mapping/Fixture/MappedSuperClass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class MappedSuperClass
3838
*
3939
* @Ext\Encode(type="md5")
4040
*/
41+
#[Ext\Encode(type: 'md5')]
4142
#[ORM\Column(length: 32)]
4243
private ?string $content = null;
4344

tests/Gedmo/Mapping/Fixture/User.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class User
4040
*
4141
* @ORM\Column(length=64)
4242
*/
43+
#[Ext\Encode(type: 'sha1', secret: 'xxx')]
4344
#[ORM\Column(length: 64)]
4445
private ?string $name = null;
4546

@@ -48,6 +49,7 @@ class User
4849
*
4950
* @ORM\Column(length=32)
5051
*/
52+
#[Ext\Encode(type: 'md5')]
5153
#[ORM\Column(length: 32)]
5254
private ?string $password = null;
5355

tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Driver/Annotation.php

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,13 @@
1111

1212
namespace Gedmo\Tests\Mapping\Mock\Extension\Encoder\Mapping\Driver;
1313

14-
use Doctrine\Common\Annotations\AnnotationReader;
15-
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
16-
use Gedmo\Mapping\Driver;
14+
use Gedmo\Mapping\Driver\AbstractAnnotationDriver;
1715
use Gedmo\Tests\Mapping\Mock\Extension\Encoder\Mapping\Encode;
1816

19-
class Annotation implements Driver
17+
class Annotation extends AbstractAnnotationDriver
2018
{
21-
/**
22-
* original driver if it is available
23-
*
24-
* @var MappingDriver
25-
*/
26-
protected $_originalDriver;
27-
2819
public function readExtendedMetadata($meta, array &$config)
2920
{
30-
$reader = new AnnotationReader();
31-
// set annotation namespace and alias
32-
// $reader->setAnnotationNamespaceAlias('Gedmo\Tests\Mapping\Mock\Extension\Encoder\Mapping\\', 'ext');
33-
3421
$class = $meta->getReflectionClass();
3522
// check only property annotations
3623
foreach ($class->getProperties() as $property) {
@@ -41,8 +28,9 @@ public function readExtendedMetadata($meta, array &$config)
4128
) {
4229
continue;
4330
}
31+
4432
// now lets check if property has our annotation
45-
if ($encode = $reader->getPropertyAnnotation($property, Encode::class)) {
33+
if ($encode = $this->reader->getPropertyAnnotation($property, Encode::class)) {
4634
$field = $property->getName();
4735
// check if field is mapped
4836
if (!$meta->hasField($field)) {
@@ -67,12 +55,4 @@ public function readExtendedMetadata($meta, array &$config)
6755

6856
return $config;
6957
}
70-
71-
/**
72-
* Passes in the mapping read by original driver
73-
*/
74-
public function setOriginalDriver($driver): void
75-
{
76-
$this->_originalDriver = $driver;
77-
}
7858
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Doctrine Behavioral Extensions package.
7+
* (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Gedmo\Tests\Mapping\Mock\Extension\Encoder\Mapping\Driver;
13+
14+
use Gedmo\Mapping\Driver\AttributeDriverInterface;
15+
16+
class Attribute extends Annotation implements AttributeDriverInterface
17+
{
18+
}

tests/Gedmo/Mapping/Mock/Extension/Encoder/Mapping/Encode.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111

1212
namespace Gedmo\Tests\Mapping\Mock\Extension\Encoder\Mapping;
1313

14-
use Doctrine\Common\Annotations\Annotation;
14+
use Gedmo\Mapping\Annotation\Annotation as GedmoAnnotation;
1515

1616
/**
1717
* @Annotation
18+
*
19+
* @NamedArgumentConstructor
1820
*/
19-
final class Encode extends Annotation
21+
#[\Attribute(\Attribute::TARGET_PROPERTY)]
22+
final class Encode implements GedmoAnnotation
2023
{
2124
/**
2225
* @var string
@@ -27,4 +30,10 @@ final class Encode extends Annotation
2730
* @var string|null
2831
*/
2932
public $secret;
33+
34+
public function __construct(string $type = 'md5', ?string $secret = null)
35+
{
36+
$this->type = $type;
37+
$this->secret = $secret;
38+
}
3039
}

0 commit comments

Comments
 (0)