/** * @param string|null $fileLocation * * @SuppressWarnings(PHPMD.StaticAccess) */ protected function buildRegister($fileLocation = null) { $vendorDir = $this->composer->getConfig()->get('vendor-dir'); $modules = []; foreach (glob("{$vendorDir}/{*/**,\\.\\.}/masonry.y{a,}ml", GLOB_BRACE) as $masonryConfig) { try { $modules[] = YamlWorkerModuleDefinition::load($masonryConfig); $this->inputOutput->write("<info>Added module:</info> {$masonryConfig}"); } catch (\Exception $e) { $this->inputOutput->writeError("<error>Invalid module:</error> {$masonryConfig}"); $this->inputOutput->writeError("== {$e->getMessage()}"); } } $register = new ModuleRegister($fileLocation); $register->addWorkerModules($modules); $register->save(); }
/** * @test * @covers ::toArray */ public function testToArray() { $module1 = $this->getMockForAbstractClass(WorkerModuleDefinitionInterface::class); $module2 = $this->getMockForAbstractClass(WorkerModuleDefinitionInterface::class); $module1->expects($this->exactly(3))->method('getName')->with()->will($this->returnValue('Module1')); $module1->expects($this->once())->method('getWorkers')->with()->will($this->returnValue([])); $module1->expects($this->once())->method('getDescriptions')->with()->will($this->returnValue([])); $module1->expects($this->once())->method('getExtra')->with()->will($this->returnValue([])); $module2->expects($this->exactly(3))->method('getName')->with()->will($this->returnValue('Module2')); $module2->expects($this->once())->method('getWorkers')->with()->will($this->returnValue(['Worker1', 'Worker2'])); $module2->expects($this->once())->method('getDescriptions')->with()->will($this->returnValue(['Description1', 'Description2'])); $module2->expects($this->once())->method('getExtra')->with()->will($this->returnValue(['something' => 'extra'])); $register = new ModuleRegister(); $register->addWorkerModules([$module1, $module2]); $expected = ['workerModules' => ['Module1' => ['name' => 'Module1', 'workers' => [], 'descriptions' => [], 'extra' => []], 'Module2' => ['name' => 'Module2', 'workers' => ['Worker1', 'Worker2'], 'descriptions' => ['Description1', 'Description2'], 'extra' => ['something' => 'extra']]]]; $toArray = $this->getObjectMethod($register, 'toArray'); $this->assertSame($expected, $toArray()); }