/**
  * 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);
 }
 /**
  * Searches for documents in the bundle and tries to read them.
  *
  * @param string $name
  *
  * @return array Empty array on containing zero documents.
  */
 public function getBundleMapping($name)
 {
     if (!is_string($name)) {
         throw new \LogicException('getBundleMapping() in the Metadata collector expects a string argument only!');
     }
     if (isset($this->mappings[$name])) {
         return $this->mappings[$name];
     }
     // Handle the case when single document mapping requested
     if (strpos($name, ':') !== false) {
         list($bundle, $documentClass) = explode(':', $name);
         $documents = $this->finder->getBundleDocumentClasses($bundle);
         $documents = in_array($documentClass, $documents) ? [$documentClass] : [];
     } else {
         $documents = $this->finder->getBundleDocumentClasses($name);
         $bundle = $name;
     }
     $mappings = [];
     $bundleNamespace = $this->finder->getBundleClass($bundle);
     $bundleNamespace = substr($bundleNamespace, 0, strrpos($bundleNamespace, '\\'));
     if (!count($documents)) {
         return [];
     }
     // Loop through documents found in bundle.
     foreach ($documents as $document) {
         $documentReflection = new \ReflectionClass($bundleNamespace . '\\' . DocumentFinder::DOCUMENT_DIR . '\\' . $document);
         try {
             $documentMapping = $this->getDocumentReflectionMapping($documentReflection);
         } catch (MissingDocumentAnnotationException $exception) {
             // Not a document, just ignore
             continue;
         }
         if (!array_key_exists($documentMapping['type'], $mappings)) {
             $documentMapping['bundle'] = $bundle;
             $mappings = array_merge($mappings, [$documentMapping['type'] => $documentMapping]);
         } else {
             throw new \LogicException($bundle . ' has 2 same type names defined in the documents. ' . 'Type names must be unique!');
         }
     }
     $this->cacheBundle($name, $mappings);
     return $mappings;
 }
 /**
  * Tests if document paths are returned for fixture bundle.
  */
 public function testGetBundleDocumentClasses()
 {
     $finder = new DocumentFinder($this->getContainer()->getParameter('kernel.bundles'));
     $this->assertGreaterThan(0, count($finder->getBundleDocumentClasses('AcmeBarBundle')));
 }