Skip to content

Commit

Permalink
fix(repository): Use metadata cache on RepositoryQueryFactory (#FRAM-…
Browse files Browse the repository at this point in the history
…117) (#74)
  • Loading branch information
vincent4vx committed May 7, 2023
1 parent e5f7532 commit ca4008d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Repository/EntityRepository.php
Expand Up @@ -129,7 +129,7 @@ public function __construct(Mapper $mapper, ServiceLocator $serviceLocator, ?Cac
$this->serviceLocator = $serviceLocator;

$this->collectionFactory = CollectionFactory::forRepository($this);
$this->queries = new RepositoryQueryFactory($this, $cache);
$this->queries = new RepositoryQueryFactory($this, $cache, $serviceLocator->mappers()->getMetadataCache());
$this->writer = new Writer($this, $serviceLocator);

$this->mapper->events($this);
Expand Down Expand Up @@ -1072,7 +1072,7 @@ private function reset(): void
}

// Reset queries
$this->queries = new RepositoryQueryFactory($this, $this->resultCache);
$this->queries = new RepositoryQueryFactory($this, $this->resultCache, $this->serviceLocator->mappers()->getMetadataCache());
$this->writer = new Writer($this, $this->serviceLocator);
$this->relations = []; // Relation may contains inner query : it must be reseted

Expand Down
17 changes: 17 additions & 0 deletions tests/Repository/EntityRepositoryTest.php
Expand Up @@ -16,6 +16,7 @@
use Bdf\Prime\TestEntity;
use Bdf\Prime\TestEmbeddedEntity;
use PHPUnit\Framework\TestCase;
use Psr\SimpleCache\CacheInterface;

/**
*
Expand Down Expand Up @@ -742,6 +743,22 @@ public function test_filter()

$this->assertEquals([$this->getTestPack()->get('entity')], iterator_to_array($query));
}

public function test_queries_should_have_metadataCache()
{
// Reset prime
$this->unsetPrime();
$this->configurePrime();

$cache = $this->createMock(CacheInterface::class);
$this->prime()->mappers()->setMetadataCache($cache);

$queries = TestEntity::repository()->queries();
$r = new \ReflectionProperty($queries, 'metadataCache');
$r->setAccessible(true);

$this->assertSame($cache, $r->getValue($queries));
}
}


Expand Down

0 comments on commit ca4008d

Please sign in to comment.