Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1038,24 +1038,6 @@ parameters:
count: 2
path: tests/Gedmo/DoctrineExtensionsTest.php

-
message: '#^Property Gedmo\\Tests\\Mapping\\Fixture\\Attribute\\TranslatableModel\:\:\$title \(string\|null\) is never assigned string so it can be removed from the property type\.$#'
identifier: property.unusedType
count: 1
path: tests/Gedmo/Mapping/Fixture/Attribute/TranslatableModel.php

-
message: '#^Property Gedmo\\Tests\\Mapping\\Fixture\\Attribute\\TranslatableModel\:\:\$titleFallbackFalse \(string\|null\) is never assigned string so it can be removed from the property type\.$#'
identifier: property.unusedType
count: 1
path: tests/Gedmo/Mapping/Fixture/Attribute/TranslatableModel.php

-
message: '#^Property Gedmo\\Tests\\Mapping\\Fixture\\Attribute\\TranslatableModel\:\:\$titleFallbackTrue \(string\|null\) is never assigned string so it can be removed from the property type\.$#'
identifier: property.unusedType
count: 1
path: tests/Gedmo/Mapping/Fixture/Attribute/TranslatableModel.php

-
message: '#^Class Gedmo\\Tests\\Translatable\\Fixture\\CategoryTranslation not found\.$#'
identifier: class.notFound
Expand Down Expand Up @@ -1116,12 +1098,6 @@ parameters:
count: 1
path: tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php

-
message: '#^Call to an undefined method Doctrine\\Persistence\\Mapping\\ClassMetadata\<object\>\:\:getReflectionProperty\(\)\.$#'
identifier: method.notFound
count: 2
path: tests/Gedmo/Mapping/Mock/Extension/Encoder/EncoderListener.php

-
message: '#^Call to an undefined method Doctrine\\Persistence\\ObjectManager\:\:getUnitOfWork\(\)\.$#'
identifier: method.notFound
Expand Down
3 changes: 1 addition & 2 deletions tests/Gedmo/Mapping/MetadataFactory/CustomDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ public function testShouldWork(): void

$id = $this->em
->getClassMetadata(Timestampable::class)
->getReflectionProperty('id')
->getValue($test)
->getFieldValue($test, 'id')
;
static::assertNotEmpty($id);
}
Expand Down
3 changes: 1 addition & 2 deletions tests/Gedmo/Mapping/MetadataFactory/ForcedMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ public function testShouldWork(): void

$id = $this->em
->getClassMetadata(Timestampable::class)
->getReflectionProperty('id')
->getValue($test)
->getFieldValue($test, 'id')
;
static::assertNotEmpty($id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,16 @@ private function encode(EventAdapterInterface $ea, object $object, array $config
$om = $ea->getObjectManager();
$meta = $om->getClassMetadata(get_class($object));
$uow = $om->getUnitOfWork();

if (!method_exists($meta, 'getFieldValue') || !method_exists($meta, 'setFieldValue')) {
throw new \RuntimeException('ClassMetadata does not have (get|set)FieldValue() methods: '.get_class($meta));
}

foreach ($config['encode'] as $field => $options) {
$value = $meta->getReflectionProperty($field)->getValue($object);
$value = $meta->getFieldValue($object, $field);
$method = $options['type'];
$encoded = $method($options['secret'].$value);
$meta->getReflectionProperty($field)->setValue($object, $encoded);
$meta->setFieldValue($object, $field, $encoded);
}
// recalculate changeset
$ea->recomputeSingleObjectChangeSet($uow, $meta, $object);
Expand Down
10 changes: 5 additions & 5 deletions tests/Gedmo/Sluggable/SluggablePositionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testPositionedSlugOrder(): void
$repo = $this->em->getRepository(Position::class);

$object = $repo->find(1);
$slug = $meta->getReflectionProperty('slug')->getValue($object);
$slug = $meta->getFieldValue($object, 'slug');
static::assertSame('code-other-title-prop', $slug);
}

Expand All @@ -55,10 +55,10 @@ private function populate(): void
{
$meta = $this->em->getClassMetadata(Position::class);
$object = new Position();
$meta->getReflectionProperty('title')->setValue($object, 'title');
$meta->getReflectionProperty('prop')->setValue($object, 'prop');
$meta->getReflectionProperty('code')->setValue($object, 'code');
$meta->getReflectionProperty('other')->setValue($object, 'other');
$meta->setFieldValue($object, 'title', 'title');
$meta->setFieldValue($object, 'prop', 'prop');
$meta->setFieldValue($object, 'code', 'code');
$meta->setFieldValue($object, 'other', 'other');

$this->em->persist($object);
$this->em->flush();
Expand Down
17 changes: 12 additions & 5 deletions tests/Gedmo/Timestampable/TimestampableDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Gedmo\Tests\Timestampable\Fixture\Document\Type;
use Gedmo\Tests\Tool\BaseTestCaseMongoODM;
use Gedmo\Timestampable\TimestampableListener;
use MongoDB\BSON\Timestamp;

/**
* These are tests for Timestampable behavior ODM implementation
Expand All @@ -41,7 +42,11 @@ public function testTimestampable(): void

$date = new \DateTime();
$now = time();
$created = $article->getCreated()->getTimestamp();
$created = $article->getCreated();
if ($created instanceof Timestamp) {
$created = $created->getTimestamp();
}

static::assertTrue($created > $now - 5 && $created < $now + 5); // 5 seconds interval if lag
static::assertSame(
$date->format('Y-m-d H:i'),
Expand Down Expand Up @@ -80,10 +85,12 @@ public function testForcedValues(): void

$repo = $this->dm->getRepository(Article::class);
$sport = $repo->findOneBy(['title' => 'sport forced']);
static::assertSame(
$created,
$sport->getCreated()->getTimestamp()
);
$createdField = $sport->getCreated();
if ($createdField instanceof Timestamp) {
$createdField = $createdField->getTimestamp();
}

static::assertSame($created, $createdField);
static::assertSame(
'2000-01-01 12:00:00',
$sport->getUpdated()->format('Y-m-d H:i:s')
Expand Down
8 changes: 4 additions & 4 deletions tests/Gedmo/Tree/ConcurrencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ public function testConcurrentEntitiesInOneFlush(): void

$meta = $this->em->getClassMetadata(Category::class);
$sport = $repo->findOneBy(['title' => 'Sport']);
$left = $meta->getReflectionProperty('lft')->getValue($sport);
$right = $meta->getReflectionProperty('rgt')->getValue($sport);
$left = $meta->getFieldValue($sport, 'lft');
$right = $meta->getFieldValue($sport, 'rgt');

static::assertSame(9, $left);
static::assertSame(16, $right);

$skiing = $repo->findOneBy(['title' => 'Skiing']);
$left = $meta->getReflectionProperty('lft')->getValue($skiing);
$right = $meta->getReflectionProperty('rgt')->getValue($skiing);
$left = $meta->getFieldValue($skiing, 'lft');
$right = $meta->getFieldValue($skiing, 'rgt');

static::assertSame(10, $left);
static::assertSame(13, $right);
Expand Down
18 changes: 9 additions & 9 deletions tests/Gedmo/Tree/InMemoryUpdatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,29 @@ public function testInMemoryTreeInserts(): void
$this->em->clear();

$node = $repo->find(2);
$left = $meta->getReflectionProperty('lft')->getValue($node);
$right = $meta->getReflectionProperty('rgt')->getValue($node);
$left = $meta->getFieldValue($node, 'lft');
$right = $meta->getFieldValue($node, 'rgt');
static::assertSame(2, $left);
static::assertSame(5, $right);

$node = $repo->find(3);
$left = $meta->getReflectionProperty('lft')->getValue($node);
$right = $meta->getReflectionProperty('rgt')->getValue($node);
$left = $meta->getFieldValue($node, 'lft');
$right = $meta->getFieldValue($node, 'rgt');
static::assertSame(6, $left);
static::assertSame(7, $right);

$node = $repo->find(4);
$left = $meta->getReflectionProperty('lft')->getValue($node);
$right = $meta->getReflectionProperty('rgt')->getValue($node);
$left = $meta->getFieldValue($node, 'lft');
$right = $meta->getFieldValue($node, 'rgt');
static::assertSame(3, $left);
static::assertSame(4, $right);

/*print "Tree:\n";
for ($i=1; $i < 5; $i++) {
$node = $this->em->getRepository(Category::class)->find($i);
$left = $meta->getReflectionProperty('lft')->getValue($node);
$right = $meta->getReflectionProperty('rgt')->getValue($node);
$level = $meta->getReflectionProperty('level')->getValue($node);
$left = $meta->getFieldValue($node, 'lft');
$right = $meta->getFieldValue($node, 'rgt');
$level = $meta->getFieldValue($node, 'level');
print $node->getTitle()." - $left - $right - $level\n";
}
print "\n\n";*/
Expand Down
2 changes: 1 addition & 1 deletion tests/Gedmo/Tree/MultiInheritanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testInheritance(): void
$repo = $this->em->getRepository(Node::class);

$food = $repo->findOneBy(['identifier' => 'food']);
$left = $meta->getReflectionProperty('lft')->getValue($food);
$left = $meta->getFieldValue($food, 'lft');

static::assertSame(1, $left);
static::assertNotNull($food->getCreated());
Expand Down
52 changes: 26 additions & 26 deletions tests/Gedmo/Tree/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ public function testAdvancedFunctions(): void
$repo = $this->em->getRepository(Category::class);
$meta = $this->em->getClassMetadata(Category::class);

$left = $meta->getReflectionProperty('lft')->getValue($onions);
$right = $meta->getReflectionProperty('rgt')->getValue($onions);
$left = $meta->getFieldValue($onions, 'lft');
$right = $meta->getFieldValue($onions, 'rgt');

static::assertSame(11, $left);
static::assertSame(12, $right);
Expand All @@ -187,17 +187,17 @@ public function testAdvancedFunctions(): void

$repo->moveUp($onions, 1);

$left = $meta->getReflectionProperty('lft')->getValue($onions);
$right = $meta->getReflectionProperty('rgt')->getValue($onions);
$left = $meta->getFieldValue($onions, 'lft');
$right = $meta->getFieldValue($onions, 'rgt');

static::assertSame(9, $left);
static::assertSame(10, $right);

// move down onions by one position
$repo->moveDown($onions, 1);

$left = $meta->getReflectionProperty('lft')->getValue($onions);
$right = $meta->getReflectionProperty('rgt')->getValue($onions);
$left = $meta->getFieldValue($onions, 'lft');
$right = $meta->getFieldValue($onions, 'rgt');

static::assertSame(11, $left);
static::assertSame(12, $right);
Expand All @@ -206,8 +206,8 @@ public function testAdvancedFunctions(): void

$repo->moveUp($onions, true);

$left = $meta->getReflectionProperty('lft')->getValue($onions);
$right = $meta->getReflectionProperty('rgt')->getValue($onions);
$left = $meta->getFieldValue($onions, 'lft');
$right = $meta->getFieldValue($onions, 'rgt');

static::assertSame(5, $left);
static::assertSame(6, $right);
Expand All @@ -220,32 +220,32 @@ public function testAdvancedFunctions(): void

$node = $this->em->getRepository(Category::class)
->findOneBy(['title' => 'Cabbages']);
$left = $meta->getReflectionProperty('lft')->getValue($node);
$right = $meta->getReflectionProperty('rgt')->getValue($node);
$left = $meta->getFieldValue($node, 'lft');
$right = $meta->getFieldValue($node, 'rgt');

static::assertSame(5, $left);
static::assertSame(6, $right);

$node = $this->em->getRepository(Category::class)
->findOneBy(['title' => 'Carrots']);
$left = $meta->getReflectionProperty('lft')->getValue($node);
$right = $meta->getReflectionProperty('rgt')->getValue($node);
$left = $meta->getFieldValue($node, 'lft');
$right = $meta->getFieldValue($node, 'rgt');

static::assertSame(7, $left);
static::assertSame(8, $right);

$node = $this->em->getRepository(Category::class)
->findOneBy(['title' => 'Onions']);
$left = $meta->getReflectionProperty('lft')->getValue($node);
$right = $meta->getReflectionProperty('rgt')->getValue($node);
$left = $meta->getFieldValue($node, 'lft');
$right = $meta->getFieldValue($node, 'rgt');

static::assertSame(9, $left);
static::assertSame(10, $right);

$node = $this->em->getRepository(Category::class)
->findOneBy(['title' => 'Potatoes']);
$left = $meta->getReflectionProperty('lft')->getValue($node);
$right = $meta->getReflectionProperty('rgt')->getValue($node);
$left = $meta->getFieldValue($node, 'lft');
$right = $meta->getFieldValue($node, 'rgt');

static::assertSame(11, $left);
static::assertSame(12, $right);
Expand All @@ -266,17 +266,17 @@ public function testAdvancedFunctions(): void

$node = $this->em->getRepository(Category::class)
->findOneBy(['title' => 'Fruits']);
$left = $meta->getReflectionProperty('lft')->getValue($node);
$right = $meta->getReflectionProperty('rgt')->getValue($node);
$left = $meta->getFieldValue($node, 'lft');
$right = $meta->getFieldValue($node, 'rgt');

static::assertSame(2, $left);
static::assertSame(3, $right);
static::assertSame('Food', $node->getParent()->getTitle());

$node = $this->em->getRepository(Category::class)
->findOneBy(['title' => 'Cabbages']);
$left = $meta->getReflectionProperty('lft')->getValue($node);
$right = $meta->getReflectionProperty('rgt')->getValue($node);
$left = $meta->getFieldValue($node, 'lft');
$right = $meta->getFieldValue($node, 'rgt');

static::assertSame(4, $left);
static::assertSame(5, $right);
Expand All @@ -297,16 +297,16 @@ public function testRootRemoval(): void
static::assertNull($food);

$node = $repo->findOneBy(['title' => 'Fruits']);
$left = $meta->getReflectionProperty('lft')->getValue($node);
$right = $meta->getReflectionProperty('rgt')->getValue($node);
$left = $meta->getFieldValue($node, 'lft');
$right = $meta->getFieldValue($node, 'rgt');

static::assertSame(1, $left);
static::assertSame(2, $right);
static::assertNull($node->getParent());

$node = $repo->findOneBy(['title' => 'Vegitables']);
$left = $meta->getReflectionProperty('lft')->getValue($node);
$right = $meta->getReflectionProperty('rgt')->getValue($node);
$left = $meta->getFieldValue($node, 'lft');
$right = $meta->getFieldValue($node, 'rgt');

static::assertSame(3, $left);
static::assertSame(12, $right);
Expand Down Expand Up @@ -367,8 +367,8 @@ public function testMoveRootNode(): void

$meta = $this->em->getClassMetadata(Category::class);

$left = $meta->getReflectionProperty('lft')->getValue($food);
$right = $meta->getReflectionProperty('rgt')->getValue($food);
$left = $meta->getFieldValue($food, 'lft');
$right = $meta->getFieldValue($food, 'rgt');

static::assertSame(3, $left);
static::assertSame(12, $right);
Expand Down
Loading