Skip to content

Commit 53ef50b

Browse files
committed
Merge pull request #143 from linasmo/patch_document_finder
DocumentFinder namespace generation fix.
2 parents 6e4919e + f5c04fb commit 53ef50b

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

Mapping/DocumentFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function getNamespace($namespace)
4949
list($bundle, $document) = explode(':', $namespace);
5050
$bundle = $this->getBundleClass($bundle);
5151
$namespace = substr($bundle, 0, strrpos($bundle, '\\')) . '\\' .
52-
$this->getDocumentDir() . '\\' . $document;
52+
str_replace('/', '\\', $this->getDocumentDir()) . '\\' . $document;
5353
}
5454

5555
return $namespace;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the ONGR package.
5+
*
6+
* Copyright (c) 2014-2015 NFQ Technologies UAB
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace ONGR\ElasticsearchBundle\Tests\Unit\Mapping;
13+
14+
use ONGR\ElasticsearchBundle\Mapping\DocumentFinder;
15+
16+
class DocumentFinderTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* Data provider for getNamespace tests.
20+
*
21+
* @return array $out
22+
*/
23+
public function getTestData()
24+
{
25+
$out = [];
26+
27+
// Case #0 one level directory.
28+
$out[] = [
29+
'Document',
30+
'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Product'
31+
];
32+
33+
// Case #1 two levels directory, `\` directory separator.
34+
$out[] = [
35+
'Document\Document',
36+
'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Document\Product'
37+
];
38+
39+
// Case #2 two levels directory, `/` directory separator.
40+
$out[] = [
41+
'Document/Document',
42+
'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Document\Product'
43+
];
44+
45+
return $out;
46+
}
47+
48+
/**
49+
* Tests if correct namespace is returned.
50+
*
51+
* @param $documentDir
52+
* @param $expectedNamespace
53+
*
54+
* @dataProvider getTestData
55+
*/
56+
public function testGetNamespace($documentDir, $expectedNamespace)
57+
{
58+
$finder = new DocumentFinder($this->getBundles());
59+
$finder->setDocumentDir($documentDir);
60+
61+
$this->assertEquals($expectedNamespace, $finder->getNamespace('AcmeTestBundle:Product'));
62+
}
63+
64+
/**
65+
* @return array
66+
*/
67+
public function getBundles()
68+
{
69+
return ['AcmeTestBundle' => 'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\AcmeTestBundle'];
70+
}
71+
}

0 commit comments

Comments
 (0)