Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocumentFinder namespace generation fix. #143

Merged
merged 2 commits into from
Jan 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Mapping/DocumentFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getNamespace($namespace)
list($bundle, $document) = explode(':', $namespace);
$bundle = $this->getBundle($bundle);
$namespace = substr($bundle, 0, strrpos($bundle, '\\')) . '\\' .
$this->getDocumentDir() . '\\' . $document;
str_replace('/', '\\', $this->getDocumentDir()) . '\\' . $document;
}

return $namespace;
Expand Down
71 changes: 71 additions & 0 deletions Tests/Unit/Mapping/DocumentFinderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/*
* This file is part of the ONGR package.
*
* Copyright (c) 2014-2015 NFQ Technologies UAB
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\ElasticsearchBundle\Tests\Unit\Mapping;

use ONGR\ElasticsearchBundle\Mapping\DocumentFinder;

class DocumentFinderTest extends \PHPUnit_Framework_TestCase
{
/**
* Data provider for getNamespace tests.
*
* @return array $out
*/
public function getTestData()
{
$out = [];

// Case #0 one level directory.
$out[] = [
'Document',
'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Product'
];

// Case #1 two levels directory, `\` directory separator.
$out[] = [
'Document\Document',
'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Document\Product'
];

// Case #2 two levels directory, `/` directory separator.
$out[] = [
'Document/Document',
'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Document\Product'
];

return $out;
}

/**
* Tests if correct namespace is returned.
*
* @param $documentDir
* @param $expectedNamespace
*
* @dataProvider getTestData
*/
public function testGetNamespace($documentDir, $expectedNamespace)
{
$finder = new DocumentFinder($this->getBundles());
$finder->setDocumentDir($documentDir);

$this->assertEquals($expectedNamespace, $finder->getNamespace('AcmeTestBundle:Product'));
}

/**
* @return array
*/
public function getBundles()
{
return ['AcmeTestBundle' => 'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\AcmeTestBundle'];
}
}