|
| 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