/** * Validate class constructor arguments * * @param string $className * @return bool * @throws \Magento\Framework\Exception\ValidatorException */ public function validate($className) { $class = new \ReflectionClass($className); $expectedArguments = $this->argumentsReader->getConstructorArguments($class); $actualArguments = $this->sourceArgumentsReader->getConstructorArgumentTypes($class); $expectedArguments = array_map(function ($element) { return $element['type']; }, $expectedArguments); $result = array_diff($expectedArguments, $actualArguments); if (!empty($result)) { throw new \Magento\Framework\Exception\ValidatorException(new \Magento\Framework\Phrase('Invalid constructor argument(s) in %1', [$className])); } return true; }
/** * @param string $class * @param array $expectedResult * @dataProvider getConstructorArgumentTypesDataProvider */ public function testGetConstructorArgumentTypes($class, $expectedResult) { $class = new \ReflectionClass($class); $actualResult = $this->sourceArgumentsReader->getConstructorArgumentTypes($class); $this->assertEquals($expectedResult, $actualResult); }