diff --git a/Generator/DocumentGenerator.php b/Generator/DocumentGenerator.php index 18ab985e..4543ef9e 100644 --- a/Generator/DocumentGenerator.php +++ b/Generator/DocumentGenerator.php @@ -11,6 +11,8 @@ namespace ONGR\ElasticsearchBundle\Generator; +use Doctrine\Common\Inflector\Inflector; + /** * Document Generator */ @@ -33,6 +35,20 @@ class DocumentGenerator public function get() { return $this->; +}'; + + /** + * @var string + */ + private $isMethodTemplate = + '/** + * Returns + * + * @return string + */ +public function is() +{ +return $this->; }'; /** @@ -141,6 +157,10 @@ private function generateDocumentMethods(array $metadata) foreach ($metadata['properties'] as $property) { $lines[] = $this->generateDocumentMethod($property, $this->setMethodTemplate) . "\n"; + if (isset($property['property_type']) && $property['property_type'] === 'boolean') { + $lines[] = $this->generateDocumentMethod($property, $this->isMethodTemplate) . "\n"; + } + $lines[] = $this->generateDocumentMethod($property, $this->getMethodTemplate) . "\n"; } @@ -249,8 +269,8 @@ private function generateDocumentDocBlock(array $metadata) [ $this->getClassName($metadata), ucfirst($metadata['annotation']), - $metadata['type'] != lcfirst($this->getClassName($metadata)) - ? sprintf('type="%s"', $metadata['type']) : '', + $metadata['annotation'] != 'object' ? ($metadata['type'] != lcfirst($this->getClassName($metadata)) + ? sprintf('type="%s"', $metadata['type']) : '') : '', ], '/** * diff --git a/Mapping/DocumentFinder.php b/Mapping/DocumentFinder.php index 8a17076a..4e64cb77 100644 --- a/Mapping/DocumentFinder.php +++ b/Mapping/DocumentFinder.php @@ -135,7 +135,7 @@ public function getBundleDocumentClasses($bundle, $documentsDirectory = null) $bundleReflection = new \ReflectionClass($this->getBundleClass($bundle)); - $documentsDirectory = DIRECTORY_SEPARATOR . $documentsDirectory . DIRECTORY_SEPARATOR; + $documentsDirectory = DIRECTORY_SEPARATOR . str_replace('\\', '/', $documentsDirectory) . DIRECTORY_SEPARATOR; $directory = dirname($bundleReflection->getFileName()) . $documentsDirectory; if (!is_dir($directory)) { diff --git a/Tests/Unit/Mapping/DocumentFinderTest.php b/Tests/Unit/Mapping/DocumentFinderTest.php index 3a507273..e81f382f 100644 --- a/Tests/Unit/Mapping/DocumentFinderTest.php +++ b/Tests/Unit/Mapping/DocumentFinderTest.php @@ -34,6 +34,22 @@ public function getTestGetNamespaceData() ]; } + /** + * Data provider for testGetNamespaceWithSubDirInDocumentDirectory(). + * + * @return array + */ + public function getTestGetNamespaceDataWithSubDirInDocumentDir() + { + return [ + [ + 'ONGR\ElasticsearchBundle\Tests\app\fixture\TestBundle\Document\Store\Product', + 'TestBundle:Product', + 'Document\Store' + ], + ]; + } + /** * Tests for getNamespace(). * @@ -52,6 +68,25 @@ public function testGetNamespace($expectedNamespace, $className) $this->assertEquals($expectedNamespace, $finder->getNamespace($className)); } + /** + * Tests for getNamespace() with a configured document directory. + * + * @param string $expectedNamespace + * @param string $className + * @param string $documentDir + * + * @dataProvider getTestGetNamespaceDataWithSubDirInDocumentDir() + */ + public function testGetNamespaceWithSubDirInDocumentDirectory($expectedNamespace, $className, $documentDir) + { + $bundles = [ + 'TestBundle' => 'ONGR\ElasticsearchBundle\Tests\app\fixture\TestBundle\TestBundle' + ]; + $finder = new DocumentFinder($bundles); + + $this->assertEquals($expectedNamespace, $finder->getNamespace($className, $documentDir)); + } + /** * Test for getBundleDocumentClasses(). */