/** * Tests if correct namespace is returned. * * @param string $expectedNamespace * @param string $document * @param bool $testPath * * @dataProvider getTestData */ public function testDocumentDir($expectedNamespace, $document, $testPath = false) { $finder = new DocumentFinder($this->getBundles()); $this->assertEquals($expectedNamespace, $finder->getNamespace($document)); if ($testPath) { $this->assertGreaterThan(0, count($finder->getBundleDocumentPaths('AcmeBarBundle'))); } }
/** * Test for getBundleDocumentClasses(). */ public function testGetBundleDocumentClasses() { $bundles = ['AcmeBarBundle' => 'ONGR\\ElasticsearchBundle\\Tests\\app\\fixture\\Acme\\BarBundle\\AcmeBarBundle']; $finder = new DocumentFinder($bundles); $documents = $finder->getBundleDocumentClasses('AcmeBarBundle'); $this->assertGreaterThan(0, count($documents)); $this->assertContains('Product', $documents); $this->assertContains('Person\\Address', $documents); }
/** * Retrieves document mapping by namespace. * * @param string $namespace Document namespace. * * @return array|null */ public function getMappingByNamespace($namespace) { if (isset($this->mappings[$namespace])) { return $this->mappings[$namespace]; } $mapping = $this->getDocumentReflectionMapping(new \ReflectionClass($this->finder->getNamespace($namespace))); $this->cacheBundle($namespace, $mapping); return $mapping; }
/** * Searches for documents in bundle and tries to read them. * * @param string $bundle * * @return array Empty array on containing zero documents. */ public function getBundleMapping($bundle) { $mappings = []; $this->proxyPaths = []; $bundleNamespace = $this->finder->getBundleClass($bundle); $bundleNamespace = substr($bundleNamespace, 0, strrpos($bundleNamespace, '\\')); $documentDir = str_replace('/', '\\', $this->finder->getDocumentDir()); // Loop through documents found in bundle. foreach ($this->finder->getBundleDocumentPaths($bundle) as $document) { $documentReflection = new \ReflectionClass($bundleNamespace . '\\' . $documentDir . '\\' . pathinfo($document, PATHINFO_FILENAME)); $documentMapping = $this->getDocumentReflectionMapping($documentReflection); if ($documentMapping !== null) { $mappings = array_replace_recursive($mappings, $documentMapping); } } return $mappings; }
/** * Tests if exception is thrown for unregistered bundle. * * @expectedException \LogicException * @expectedExceptionMessage Bundle 'NotExistingBundle' does not exist. */ public function testGetBundleClassException() { $finder = new DocumentFinder($this->getContainer()->getParameter('kernel.bundles')); $finder->getBundleClass('NotExistingBundle'); }
/** * Returns fully qualified class name. * * @param string $className * * @return string */ public function getClassName($className) { return $this->finder->getNamespace($className); }
/** * Retrieves document mapping by namespace. * * @param string $namespace Document namespace. * * @return array|null */ public function getMappingByNamespace($namespace) { return $this->getDocumentReflectionMapping(new \ReflectionClass($this->finder->getNamespace($namespace))); }