Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function process(ContextInterface $context)
 {
     if ($context->hasResult()) {
         // a definition is already built
         return;
     }
     $context->setResult(ConfigUtil::getInitialConfig());
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function process(ContextInterface $context)
 {
     /** @var ConfigContext $context */
     if ($context->hasFilters()) {
         // a filters' definition is already built
         return;
     }
     $context->setFilters(ConfigUtil::getInitialConfig());
 }
Пример #3
0
 public function testSorters()
 {
     $this->assertFalse($this->context->hasSorters());
     $this->assertNull($this->context->getSorters());
     $sorters = ConfigUtil::getInitialConfig();
     $this->context->setSorters($sorters);
     $this->assertTrue($this->context->hasSorters());
     $this->assertEquals($sorters, $this->context->getSorters());
     $this->assertEquals($sorters, $this->context->get(SortersConfigExtra::NAME));
     $this->context->setSorters(null);
     $this->assertTrue($this->context->hasSorters());
 }
Пример #4
0
 /**
  * @param RelationConfigContext $context
  * @param array                 $config
  */
 protected function addConfigToContext(RelationConfigContext $context, array $config)
 {
     $hasDefinition = isset($config[ConfigUtil::DEFINITION]);
     if ($hasDefinition) {
         $context->setResult($config[ConfigUtil::DEFINITION]);
     }
     if (isset($config[ConfigUtil::FILTERS]) && null === $context->getFilters()) {
         $context->setFilters($config[ConfigUtil::FILTERS]);
     }
     if (isset($config[ConfigUtil::SORTERS]) && null === $context->getSorters()) {
         $context->setSorters($config[ConfigUtil::SORTERS]);
     }
     if ($hasDefinition) {
         if (null === $context->getFilters()) {
             $context->setFilters(ConfigUtil::getInitialConfig());
         }
         if (null === $context->getSorters()) {
             $context->setSorters(ConfigUtil::getInitialConfig());
         }
     }
 }
Пример #5
0
 public function testLoadMetadata()
 {
     $version = '1.1';
     $requestType = 'rest';
     $entityClass = 'Test\\Class';
     $configExtras = [new TestConfigSection('section1'), new TestConfigSection('section2')];
     $config = ConfigUtil::getInitialConfig();
     $metadata = new EntityMetadata();
     $metadataExtras = [new TestMetadataExtra('extra1')];
     $this->context->setVersion($version);
     $this->context->setRequestType($requestType);
     $this->context->setConfigExtras($configExtras);
     $this->context->setMetadataExtras($metadataExtras);
     $this->context->setClassName($entityClass);
     $this->configProvider->expects($this->once())->method('getConfig')->with($entityClass, $version, [$requestType], $configExtras)->willReturn([ConfigUtil::DEFINITION => $config]);
     $this->metadataProvider->expects($this->once())->method('getMetadata')->with($entityClass, $version, [$requestType], $metadataExtras, $config)->willReturn($metadata);
     // test that metadata are not loaded yet
     $this->assertFalse($this->context->hasMetadata());
     $this->assertSame($metadata, $this->context->getMetadata());
     // load metadata
     $this->assertTrue($this->context->hasMetadata());
     $this->assertTrue($this->context->has(Context::METADATA));
     $this->assertSame($metadata, $this->context->get(Context::METADATA));
     $this->assertEquals($config, $this->context->getConfig());
     // test that metadata are loaded only once
     $this->assertSame($metadata, $this->context->getMetadata());
 }