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() { $configurationRuleSet = ConfigurationRuleset::fromArray(['foo' => ['bar'], 'lala' => ['xx', 'yy']]); $this->assertEquals(['bar'], $configurationRuleSet->getAllowedDependendencies('foo')); $this->assertEquals(['xx', 'yy'], $configurationRuleSet->getAllowedDependendencies('lala')); $this->assertEquals([], $configurationRuleSet->getAllowedDependendencies('lalax')); }
/** * @param array $dependenciesAsArray * @param array $classesInLayers * @param array $rulesetConfiguration * @param $expectedCount * @dataProvider dependencyProvider */ public function testGetViolationsButNoViolations(array $dependenciesAsArray, array $classesInLayers, array $rulesetConfiguration, $expectedCount) { $dependencyResult = new DependencyResult(); foreach ($this->createDependencies($dependenciesAsArray) as $dep) { $dependencyResult->addDependency($dep); } $classNameLayerResolver = $this->prophesize(ClassNameLayerResolverInterface::class); foreach ($classesInLayers as $classInLayer => $layers) { $classNameLayerResolver->getLayersByClassName($classInLayer)->willReturn($layers); } $this->assertCount($expectedCount, (new RulesetEngine())->getViolations($dependencyResult, $classNameLayerResolver->reveal(), ConfigurationRuleset::fromArray($rulesetConfiguration))); }