forked from ongr-archive/ContentBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Martynas Sudintas
committed
Nov 3, 2014
1 parent
d97e0e1
commit 50e003a
Showing
3 changed files
with
134 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the ONGR package. | ||
* | ||
* (c) NFQ Technologies UAB <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace ONGR\ContentBundle\Tests\Unit\Service; | ||
|
||
use ONGR\ContentBundle\Service\ContentService; | ||
use ONGR\ElasticsearchBundle\DSL\Query\TermQuery; | ||
|
||
class ContentServiceTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* Tests if method getDocumentBySlug does what is expected. | ||
*/ | ||
public function testGetDocumentBySlug() | ||
{ | ||
$searchMock = $this->getMock('ElasticsearchBundle\DSL\Search', ['addQuery']); | ||
$searchMock | ||
->expects($this->once()) | ||
->method('addQuery') | ||
->with( | ||
new TermQuery('slug', 'foo'), | ||
'must' | ||
); | ||
|
||
$repositoryMock = $this | ||
->getMockBuilder('ElasticsearchBundle\ORM\Repository') | ||
->disableOriginalConstructor() | ||
->setMethods(['execute', 'createSearch']) | ||
->getMock(); | ||
|
||
$repositoryMock | ||
->expects($this->once()) | ||
->method('createSearch') | ||
->will($this->returnValue($searchMock)); | ||
|
||
$repositoryMock | ||
->expects($this->once()) | ||
->method('execute') | ||
->with() | ||
->will($this->returnValue(new \ArrayIterator(['first', 'second']))); | ||
|
||
$service = new ContentService($repositoryMock); | ||
|
||
$result = $service->getDocumentBySlug('foo'); | ||
$this->assertEquals('first', $result, 'Expected first result.'); | ||
} | ||
|
||
/** | ||
* Tests if method getDocumentBySlug is logging when no documents found. | ||
*/ | ||
public function testGetDocumentBySlugLogger() | ||
{ | ||
$searchMock = $this->getMock('ElasticsearchBundle\DSL\Search', ['addQuery']); | ||
$searchMock | ||
->expects($this->once()) | ||
->method('addQuery') | ||
->with( | ||
$this->isInstanceOf('ONGR\ElasticsearchBundle\DSL\Query\TermQuery'), | ||
'must' | ||
); | ||
|
||
$repositoryMock = $this | ||
->getMockBuilder('ElasticsearchBundle\ORM\Repository') | ||
->disableOriginalConstructor() | ||
->setMethods(['execute', 'createSearch']) | ||
->getMock(); | ||
|
||
$repositoryMock | ||
->expects($this->once()) | ||
->method('createSearch') | ||
->will($this->returnValue($searchMock)); | ||
|
||
$repositoryMock | ||
->expects($this->once()) | ||
->method('execute') | ||
->with() | ||
->will($this->returnValue(new \ArrayIterator([]))); | ||
|
||
$loggerMock = $this->getMock('Psr\\Log\\LoggerInterface'); | ||
$loggerMock | ||
->expects($this->once()) | ||
->method('warning') | ||
->with('Can not render snippet for \'foo\' because content was not found.'); | ||
|
||
$service = new ContentService($repositoryMock); | ||
$service->setLogger($loggerMock); | ||
|
||
$this->assertNull($service->getDocumentBySlug('foo'), 'Result expected to be null.'); | ||
} | ||
} |