public function testAddCollection() { $this->model->addDefinition(self::INSTANCE_1, $this->getArgument()); $this->collectionMock->expects($this->any())->method('getCollection')->willReturn([self::INSTANCE_2 => $this->getArgument()]); $this->model->addCollection($this->collectionMock); $this->assertEquals([self::INSTANCE_1 => $this->getArgument(), self::INSTANCE_2 => $this->getArgument()], $this->model->getCollection()); }
/** * @return Collection */ private function getDefinitionsCollection() { $definitionCollection = new Collection(); $definitionCollection->addDefinition('ConcreteType1', ['argument1', 'argument2']); $definitionCollection->addDefinition('ConcreteType2', ['argument1', 'argument2']); $definitionCollection->addDefinition('Interface1', [null]); return $definitionCollection; }
/** * Returns definitions collection * * @param string $path * @return DefinitionsCollection */ protected function getDefinitionsCollection($path) { $definitions = new DefinitionsCollection(); foreach ($this->classesScanner->getList($path) as $className => $constructorArguments) { $definitions->addDefinition($className, $constructorArguments); } return $definitions; }
public function testDoOperationGlobalArea() { $path = 'path/to/codebase/'; $generatedConfig = ['arguments' => [], 'nonShared' => [], 'preferences' => [], 'instanceTypes' => []]; $definitions = new DefinitionsCollection(); $definitions->addDefinition('class', []); $areaOperation = new Area($this->areaListMock, $this->classesScannerMock, $this->configReaderMock, $this->configWriterMock, [$path]); $this->areaListMock->expects($this->once())->method('getCodes')->willReturn([]); $this->classesScannerMock->expects($this->once())->method('getList')->with($path)->willReturn(['class' => []]); $this->configReaderMock->expects($this->once())->method('generateCachePerScope')->with($this->isInstanceOf('Magento\\Tools\\Di\\Definition\\Collection'), App\Area::AREA_GLOBAL)->willReturn($generatedConfig); $this->configWriterMock->expects($this->once())->method('write')->with(App\Area::AREA_GLOBAL, $generatedConfig); $areaOperation->doOperation(); }
/** * Returns preferences for third party code * * @param ConfigInterface $config * @param DefinitionsCollection $definitionsCollection * @SuppressWarnings(PHPMD.UnusedLocalVariable) * * @return void */ private function fillThirdPartyInterfaces(ConfigInterface $config, DefinitionsCollection $definitionsCollection) { $definedInstances = $definitionsCollection->getInstancesNamesList(); foreach ($config->getPreferences() as $interface => $preference) { if (in_array($interface, $definedInstances)) { continue; } $definitionsCollection->addDefinition($interface, []); } }