Skip to content

Commit aa75c61

Browse files
fattouchsquallsaimaz
authored andcommitted
Add isser for boolean properties. (#782)
* Add isser for boolean properties. * Fix namespace subdirectory in document mapping. * Add tests for a subdir used in document dir configuration option. * Use product for testing subdirectory fix.
1 parent 162bbe1 commit aa75c61

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

Generator/DocumentGenerator.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace ONGR\ElasticsearchBundle\Generator;
1313

14+
use Doctrine\Common\Inflector\Inflector;
15+
1416
/**
1517
* Document Generator
1618
*/
@@ -33,6 +35,20 @@ class DocumentGenerator
3335
public function get<methodName>()
3436
{
3537
<spaces>return $this-><fieldName>;
38+
}';
39+
40+
/**
41+
* @var string
42+
*/
43+
private $isMethodTemplate =
44+
'/**
45+
* Returns <fieldName>
46+
*
47+
* @return string
48+
*/
49+
public function is<methodName>()
50+
{
51+
<spaces>return $this-><fieldName>;
3652
}';
3753

3854
/**
@@ -141,6 +157,10 @@ private function generateDocumentMethods(array $metadata)
141157

142158
foreach ($metadata['properties'] as $property) {
143159
$lines[] = $this->generateDocumentMethod($property, $this->setMethodTemplate) . "\n";
160+
if (isset($property['property_type']) && $property['property_type'] === 'boolean') {
161+
$lines[] = $this->generateDocumentMethod($property, $this->isMethodTemplate) . "\n";
162+
}
163+
144164
$lines[] = $this->generateDocumentMethod($property, $this->getMethodTemplate) . "\n";
145165
}
146166

@@ -249,8 +269,8 @@ private function generateDocumentDocBlock(array $metadata)
249269
[
250270
$this->getClassName($metadata),
251271
ucfirst($metadata['annotation']),
252-
$metadata['type'] != lcfirst($this->getClassName($metadata))
253-
? sprintf('type="%s"', $metadata['type']) : '',
272+
$metadata['annotation'] != 'object' ? ($metadata['type'] != lcfirst($this->getClassName($metadata))
273+
? sprintf('type="%s"', $metadata['type']) : '') : '',
254274
],
255275
'/**
256276
* <className>

Mapping/DocumentFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function getBundleDocumentClasses($bundle, $documentsDirectory = null)
135135

136136
$bundleReflection = new \ReflectionClass($this->getBundleClass($bundle));
137137

138-
$documentsDirectory = DIRECTORY_SEPARATOR . $documentsDirectory . DIRECTORY_SEPARATOR;
138+
$documentsDirectory = DIRECTORY_SEPARATOR . str_replace('\\', '/', $documentsDirectory) . DIRECTORY_SEPARATOR;
139139
$directory = dirname($bundleReflection->getFileName()) . $documentsDirectory;
140140

141141
if (!is_dir($directory)) {

Tests/Unit/Mapping/DocumentFinderTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ public function getTestGetNamespaceData()
3434
];
3535
}
3636

37+
/**
38+
* Data provider for testGetNamespaceWithSubDirInDocumentDirectory().
39+
*
40+
* @return array
41+
*/
42+
public function getTestGetNamespaceDataWithSubDirInDocumentDir()
43+
{
44+
return [
45+
[
46+
'ONGR\ElasticsearchBundle\Tests\app\fixture\TestBundle\Document\Store\Product',
47+
'TestBundle:Product',
48+
'Document\Store'
49+
],
50+
];
51+
}
52+
3753
/**
3854
* Tests for getNamespace().
3955
*
@@ -52,6 +68,25 @@ public function testGetNamespace($expectedNamespace, $className)
5268
$this->assertEquals($expectedNamespace, $finder->getNamespace($className));
5369
}
5470

71+
/**
72+
* Tests for getNamespace() with a configured document directory.
73+
*
74+
* @param string $expectedNamespace
75+
* @param string $className
76+
* @param string $documentDir
77+
*
78+
* @dataProvider getTestGetNamespaceDataWithSubDirInDocumentDir()
79+
*/
80+
public function testGetNamespaceWithSubDirInDocumentDirectory($expectedNamespace, $className, $documentDir)
81+
{
82+
$bundles = [
83+
'TestBundle' => 'ONGR\ElasticsearchBundle\Tests\app\fixture\TestBundle\TestBundle'
84+
];
85+
$finder = new DocumentFinder($bundles);
86+
87+
$this->assertEquals($expectedNamespace, $finder->getNamespace($className, $documentDir));
88+
}
89+
5590
/**
5691
* Test for getBundleDocumentClasses().
5792
*/

0 commit comments

Comments
 (0)