-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Full code coverage with MSI = 100% (#83)
* Full code coverage with MSI = 100% * Disabling proxying to original method for MongoDB Query * Implementing missing abstract method in mock
- Loading branch information
1 parent
7aa26d9
commit 7c96307
Showing
10 changed files
with
498 additions
and
5 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/KGzocha/Searcher/CriteriaBuilder/Doctrine/AbstractODMCriteriaBuilder.php
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
3 changes: 1 addition & 2 deletions
3
...achedQueryBuilderSearchingContextTest.php → ...achedQueryBuilderSearchingContextTest.php
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,47 @@ | ||
<?php | ||
|
||
namespace KGzocha\Searcher\Test\Context\Doctrine; | ||
|
||
use KGzocha\Searcher\Context\Doctrine\ODMBuilderSearchingContext; | ||
use KGzocha\Searcher\Test\Context\MongoDBQueryStub; | ||
|
||
/** | ||
* @author Krzysztof Gzocha <krzysztof@propertyfinder.ae> | ||
*/ | ||
class ODMBuilderSearchingContextTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testConstructor() | ||
{ | ||
$context = new ODMBuilderSearchingContext($builder = $this->getBuilderMock()); | ||
|
||
$this->assertEquals($builder, $context->getQueryBuilder()); | ||
} | ||
|
||
public function testGetResults() | ||
{ | ||
$context = new ODMBuilderSearchingContext($this->getBuilderMock( | ||
$results = [1, 2, 3] | ||
)); | ||
|
||
$this->assertEquals($results, $context->getResults()); | ||
} | ||
|
||
/** | ||
* @param array $results | ||
* @return \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private function getBuilderMock(array $results = []) | ||
{ | ||
$mock = $this | ||
->getMockBuilder('\Doctrine\ODM\MongoDB\Query\Builder') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$mock | ||
->expects($this->any()) | ||
->method('getQuery') | ||
->willReturn(new MongoDBQueryStub($results)); | ||
|
||
return $mock; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
tests/Context/Doctrine/QueryBuilderSearchingContextTest.php
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,56 @@ | ||
<?php | ||
|
||
namespace KGzocha\Searcher\Test\Context\Doctrine; | ||
|
||
use Doctrine\ORM\QueryBuilder; | ||
use KGzocha\Searcher\Context\Doctrine\QueryBuilderSearchingContext; | ||
use KGzocha\Searcher\Test\Context\QueryStub; | ||
|
||
/** | ||
* @author Krzysztof Gzocha <krzysztof@propertyfinder.ae> | ||
*/ | ||
class QueryBuilderSearchingContextTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testConstructor() | ||
{ | ||
$context = new QueryBuilderSearchingContext( | ||
$queryBuilder = $this->getQueryBuilderMock() | ||
); | ||
|
||
$this->assertEquals( | ||
$queryBuilder, | ||
$context->getQueryBuilder() | ||
); | ||
} | ||
|
||
public function testResults() | ||
{ | ||
$context = new QueryBuilderSearchingContext( | ||
$this->getQueryBuilderMock($results = [1,2,3]) | ||
); | ||
|
||
$this->assertEquals( | ||
$results, | ||
$context->getResults() | ||
); | ||
} | ||
|
||
/** | ||
* @param array $results | ||
* @return \PHPUnit_Framework_MockObject_MockObject|QueryBuilder | ||
*/ | ||
private function getQueryBuilderMock(array $results = []) | ||
{ | ||
$mock = $this | ||
->getMockBuilder('\Doctrine\ORM\QueryBuilder') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$mock | ||
->expects($this->any()) | ||
->method('getQuery') | ||
->willReturn(new QueryStub($results)); | ||
|
||
return $mock; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace KGzocha\Searcher\Test\Context; | ||
|
||
/** | ||
* @author Krzysztof Gzocha <krzysztof@propertyfinder.ae> | ||
*/ | ||
class MongoDBQueryStub | ||
{ | ||
/** | ||
* @var mixed | ||
*/ | ||
private $results; | ||
|
||
/** | ||
* @param $results | ||
*/ | ||
public function __construct($results = null) | ||
{ | ||
$this->results = $results; | ||
} | ||
|
||
public function execute() | ||
{ | ||
return $this->results; | ||
} | ||
} |
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
62 changes: 62 additions & 0 deletions
62
tests/CriteriaBuilder/Doctrine/AbstractODMCriteriaBuilderTest.php
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,62 @@ | ||
<?php | ||
|
||
namespace KGzocha\Searcher\Test\CriteriaBuilder\Doctrine; | ||
|
||
use KGzocha\Searcher\Context\SearchingContextInterface; | ||
use KGzocha\Searcher\CriteriaBuilder\Doctrine\AbstractODMCriteriaBuilder; | ||
|
||
/** | ||
* @author Krzysztof Gzocha <krzysztof@propertyfinder.ae> | ||
*/ | ||
class AbstractODMCriteriaBuilderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @param SearchingContextInterface $searchingContext | ||
* @param $expected | ||
* @dataProvider supportedContextDataProvider | ||
*/ | ||
public function testSupportSearchingContext( | ||
SearchingContextInterface $searchingContext, | ||
$expected | ||
) { | ||
/** @var AbstractODMCriteriaBuilder $criteriaBuilder */ | ||
$criteriaBuilder = $this | ||
->getMockBuilder('\KGzocha\Searcher\CriteriaBuilder\Doctrine\AbstractODMCriteriaBuilder') | ||
->getMockForAbstractClass(); | ||
|
||
$this->assertEquals( | ||
$expected, | ||
$criteriaBuilder->supportsSearchingContext($searchingContext) | ||
); | ||
} | ||
|
||
public function supportedContextDataProvider() | ||
{ | ||
return [ | ||
[$this->getSupportedSearchingContextMock(), true], | ||
[$this->getNotSupportedSearchingContextMock(), false], | ||
]; | ||
} | ||
|
||
/** | ||
* @return \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private function getNotSupportedSearchingContextMock() | ||
{ | ||
return $this | ||
->getMockBuilder('\KGzocha\Searcher\Context\SearchingContextInterface') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
} | ||
|
||
/** | ||
* @return \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private function getSupportedSearchingContextMock() | ||
{ | ||
return $this | ||
->getMockBuilder('\KGzocha\Searcher\Context\Doctrine\ODMBuilderSearchingContext') | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
} | ||
} |
Oops, something went wrong.