public function testGetBundleFolderFromPath() { /** @var AppKernel|\PHPUnit_Framework_MockObject_MockObject $mockKernel */ $mockKernel = $this->getMockBuilder(AppKernel::class)->disableOriginalConstructor()->getMock(); $bundleHelper = new BundleHelper($mockKernel); $path = '/path/to/project/src/YourNamespace/Bundles/YourBundle/YourNamespaceYourBundle.php'; $this->assertEquals('YourBundle', $bundleHelper->getBundleFolderFromPath($path)); }
/** * @param $configFilePath * @return null|\ReflectionClass */ private function getReflectionClassForConfig($configFilePath) { $bundleName = $this->bundleHelper->getBundleFolderFromPath($configFilePath); $endOfPath = substr($configFilePath, strpos($configFilePath, self::PATH_IN_BUNDLE)); $configClassShortName = str_replace([self::PATH_IN_BUNDLE, self::CONFIG_PATH_SUFFIX], '', $endOfPath); if (!isset($this->entityClassesByBundle[$bundleName])) { return null; } /** @var \ReflectionClass $reflectionClass */ foreach ($this->entityClassesByBundle[$bundleName] as $reflectionClass) { if ($configClassShortName === $reflectionClass->getShortName()) { return $reflectionClass; } } return null; }