Skip to content
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 @@ -106,7 +106,7 @@ public function getBundleDocumentPaths($bundle)

return glob(
dirname($bundleReflection->getFileName()) .
DIRECTORY_SEPARATOR . $this->getDocumentDir() .
DIRECTORY_SEPARATOR . str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $this->getDocumentDir()) .
DIRECTORY_SEPARATOR . '*.php'
);
}
Expand Down
50 changes: 50 additions & 0 deletions Tests/Functional/Mapping/DocumentFinderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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\Functional\Mapping;


use ONGR\ElasticsearchBundle\Mapping\DocumentFinder;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class DocumentFinderTest extends WebTestCase
{
/**
* Tests if document paths are returned for fixture bundle.
*/
public function testGetBundleDocumentPaths()
{
$finder = new DocumentFinder($this->getContainer()->getParameter('kernel.bundles'));
$this->assertGreaterThan(0, count($finder->getBundleDocumentPaths('AcmeTestBundle')));
}

/**
* Tests if exception is thrown for unregistered bundle.
*
* @expectedException \LogicException
* @expectedExceptionMessage Bundle 'DemoBundle' does not exist.
*/
public function testGetBundleClassException()
{
$finder = new DocumentFinder($this->getContainer()->getParameter('kernel.bundles'));
$finder->getBundleClass('DemoBundle');
}

/**
* Returns service container.
*
* @return object
*/
public function getContainer()
{
return $this->createClient()->getContainer();
}
}
41 changes: 33 additions & 8 deletions Tests/Unit/Mapping/DocumentFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class DocumentFinderTest extends \PHPUnit_Framework_TestCase
{
/**
* Data provider for getNamespace tests.
* Data provider for testDocumentDir tests.
*
* @return array $out
*/
Expand All @@ -27,19 +27,39 @@ public function getTestData()
// Case #0 one level directory.
$out[] = [
'Document',
'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Product'
'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Product',
'AcmeTestBundle:Product',
true,
];

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

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

// Case #3 two levels directory, `/` directory separator.
$out[] = [
'Document/Test',
'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Test\Item',
'AcmeTestBundle:Item',
true,
];

// Case #4 two levels directory, `\` directory separator.
$out[] = [
'Document\Test',
'ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Test\Item',
'AcmeTestBundle:Item',
true,
];

return $out;
Expand All @@ -48,17 +68,22 @@ public function getTestData()
/**
* Tests if correct namespace is returned.
*
* @param $documentDir
* @param $expectedNamespace
* @param string $documentDir
* @param string $expectedNamespace
* @param string $document
* @param boolean $testPath
*
* @dataProvider getTestData
*/
public function testGetNamespace($documentDir, $expectedNamespace)
public function testDocumentDir($documentDir, $expectedNamespace, $document, $testPath = false)
{
$finder = new DocumentFinder($this->getBundles());
$finder->setDocumentDir($documentDir);

$this->assertEquals($expectedNamespace, $finder->getNamespace('AcmeTestBundle:Product'));
$this->assertEquals($expectedNamespace, $finder->getNamespace($document));
if ($testPath) {
$this->assertGreaterThan(0, count($finder->getBundleDocumentPaths('AcmeTestBundle')));
}
}

/**
Expand Down
79 changes: 79 additions & 0 deletions Tests/app/fixture/Acme/TestBundle/Document/Test/Item.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\ElasticsearchBundle\Tests\app\fixture\Acme\TestBundle\Document\Test;

use ONGR\ElasticsearchBundle\Annotation as ES;
use ONGR\ElasticsearchBundle\Document\DocumentInterface;
use ONGR\ElasticsearchBundle\Document\DocumentTrait;

/**
* Document class Item.
*
* @ES\Document(create=false)
*/
class Item implements DocumentInterface
{
use DocumentTrait;

/**
* @var string
*
* @ES\Property(name="name", type="string")
*/
public $name;

/**
* @var float
*
* @ES\Property(type="float", name="price")
*/
protected $price;

/**
* @var \DateTime
*
* @ES\Property(name="created_at", type="date")
*/
private $createdAt;

/**
* @return float
*/
public function getPrice()
{
return $this->price;
}

/**
* @param float $price
*/
public function setPrice($price)
{
$this->price = $price;
}

/**
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}

/**
* @param \DateTime $createdAt
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
}
}