示例#1
0
 public static function fromArray(array $arr)
 {
     $options = (new OptionsResolver())->setRequired(['layers', 'paths', 'exclude_files', 'ruleset'])->addAllowedTypes('layers', 'array')->addAllowedTypes('paths', 'array')->addAllowedTypes('exclude_files', ['array', 'null'])->addAllowedTypes('ruleset', 'array')->resolve($arr);
     return new static(array_map(function ($v) {
         return ConfigurationLayer::fromArray($v);
     }, $options['layers']), ConfigurationRuleset::fromArray($options['ruleset']), $options['paths'], (array) $options['exclude_files']);
 }
 public function testFromArray()
 {
     $configurationLayer = ConfigurationLayer::fromArray(['name' => 'some_name', 'collectors' => [['type' => 'foo1', 'foo' => 'bar'], ['type' => 'foo2', 'foo' => 'bar']]]);
     $this->assertEquals('some_name', $configurationLayer->getName());
     $this->assertCount(2, $configurationLayer->getCollectors());
     $this->assertEquals('foo1', $configurationLayer->getCollectors()[0]->getType());
     $this->assertEquals(['type' => 'foo1', 'foo' => 'bar'], $configurationLayer->getCollectors()[0]->getArgs());
     $this->assertEquals('foo2', $configurationLayer->getCollectors()[1]->getType());
     $this->assertEquals(['type' => 'foo2', 'foo' => 'bar'], $configurationLayer->getCollectors()[1]->getArgs());
 }
 /**
  * @param $collectA
  * @param $collectB1
  * @param $collectB2
  * @param array $expectedLayers
  * @dataProvider provideGetLayersByClassName
  */
 public function testGetLayersByClassName($collectA, $collectB1, $collectB2, array $expectedLayers)
 {
     $configuration = $this->prophesize(Configuration::class);
     $configuration->getLayers()->willReturn([ConfigurationLayer::fromArray(['name' => 'LayerA', 'collectors' => [['type' => 'CollectorA']]]), ConfigurationLayer::fromArray(['name' => 'LayerB', 'collectors' => [['type' => 'CollectorB1'], ['type' => 'CollectorB2']]])]);
     $astMap = $this->prophesize(AstMap::class);
     $collectorFactory = $this->prophesize(CollectorFactory::class);
     $collectorFactory->getCollector('CollectorA')->willReturn($this->getCollector($collectA, ['type' => 'CollectorA', 'foo' => 'bar']));
     $collectorFactory->getCollector('CollectorB1')->willReturn($this->getCollector($collectB1, ['type' => 'CollectorB', 'foo' => 'bar']));
     $collectorFactory->getCollector('CollectorB2')->willReturn($this->getCollector($collectB2, ['type' => 'CollectorB', 'foo' => 'bar']));
     $resolver = new ClassNameLayerResolver($configuration->reveal(), $astMap->reveal(), $collectorFactory->reveal(), $this->prophesize(AstParserInterface::class)->reveal());
     $this->assertEquals($expectedLayers, $resolver->getLayersByClassName('classA'));
 }