Skip to content

Commit

Permalink
Merge pull request #19: Filter Query Options
Browse files Browse the repository at this point in the history
* pr-19:
  Remove php 7.1 from travis config
  improved tests to be compatible with phpunit 8.0
  added tests for creating query with filterQueries options
  added filterQueries options
  fixed docker config
  • Loading branch information
TiSiE committed Jun 27, 2019
2 parents c5097fe + a2e63da commit 90177bc
Show file tree
Hide file tree
Showing 22 changed files with 254 additions and 123 deletions.
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/vendor/
/node_modules/
/build/
.env
vendor
node_modules
build.properties
build
composer.lock
package-lock.json
.phpunit.result.cache

#
# Eclipse project files
#
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ matrix:
- php: 7.2
env: COVERAGE=yes
include:
- php: 7.1
- php: 7.2
- php: 7.3
- php: 7.2
Expand Down
40 changes: 22 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,12 @@
}
],
"keywords": [
"yawik", "solr", "zf"
"yawik",
"solr",
"zf"
],
"prefer-stable": true,
"minimum-stability": "dev",
"require": {
"ext-solr": ">=2.4",
"zendframework/zend-progressbar": "^2.5",
"yawik/core": ">=0.32",
"yawik/cv": ">=0.32",
"yawik/auth": ">=0.32",
"yawik/jobs": ">=0.32",
"yawik/applications": ">=0.32",
"yawik/settings": ">=0.32",
"yawik/organizations": ">=0.32",
"yawik/geo": ">=0.32",
"yawik/composer-plugin": ">=0.32"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"yawik/behat": ">=0.32@dev"
},
"autoload": {
"psr-4": {
"Solr\\": "src/"
Expand Down Expand Up @@ -76,5 +61,24 @@
"zf": {
"module": "Solr"
}
},
"require": {
"php": ">=7.2",
"ext-solr": ">=2.4",
"zendframework/zend-progressbar": "^2.5",
"yawik/core": "^0.33.14",
"yawik/cv": ">=0.32",
"yawik/auth": ">=0.32",
"yawik/jobs": ">=0.32",
"yawik/applications": ">=0.32",
"yawik/settings": ">=0.32",
"yawik/organizations": ">=0.32",
"yawik/geo": ">=0.32",
"yawik/composer-plugin": ">=0.32"
},
"require-dev": {
"yawik/behat": ">=0.32@dev",
"cross-solution/phpunit-utils": "^2.0",
"phpunit/phpunit": "^8.2.3"
}
}
2 changes: 1 addition & 1 deletion etc/docker/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server {
root /var/www/yawik/public;
root /var/www/yawik/test/sandbox/public;

location / {
# try to serve file directly, fallback to index.php
Expand Down
3 changes: 0 additions & 3 deletions etc/docker/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ RUN curl --location https://github.com/php/pecl-search_engine-solr/archive/${SOL
RUN docker-php-ext-enable solr

# Add timezone
RUN rm /etc/localtime && \
ln -s /usr/share/zoneinfo/UTC /etc/localtime && \
"date"
RUN printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini

# Cleanup
Expand Down
20 changes: 17 additions & 3 deletions src/Filter/JobBoardPaginationQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
*/
class JobBoardPaginationQuery extends AbstractPaginationQuery
{

/**
* @var ModuleOptions $options
*/
Expand Down Expand Up @@ -138,8 +137,10 @@ public function createQuery(array $params, SolrDisMaxQuery $query, Facets $facet
$facets->addDefinition($facetField['name'], $facetField['label']);
}

$facets->setParams($params)
->setupQuery($query);
$this->configureFilterQuery($query);

$facets->setParams($params);
$facets->setupQuery($query);

$query->setFacetMinCount(1);

Expand Down Expand Up @@ -174,4 +175,17 @@ public function getRepositoryName()
{
return 'Jobs/Job';
}

private function configureFilterQuery(SolrDisMaxQuery $query)
{
$filters = $this->options->getFilterQueries();

foreach($filters as $filter){
if(is_scalar($filter)){
$query->addFilterQuery($filter);
}elseif(is_callable($filter)){
call_user_func_array($filter,[$query]);
}
}
}
}
21 changes: 21 additions & 0 deletions src/Options/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,27 @@ class ModuleOptions extends AbstractOptions
'employmentType' => 'employmentType_MultiString',
];

/**
* @var array
*/
protected $filterQueries = [];

/**
* @return array
*/
public function getFilterQueries()
{
return $this->filterQueries;
}

/**
* @param array $filterQueries
*/
public function setFilterQueries(array $filterQueries)
{
$this->filterQueries = $filterQueries;
}

/**
* @return boolean
*/
Expand Down
11 changes: 7 additions & 4 deletions test/SolrTest/Bridge/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace SolrTest\Bridge;

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;


use Interop\Container\ContainerInterface;
use Solr\Bridge\Manager;
Expand All @@ -21,15 +24,15 @@
* @author Mathias Gelhausen <gelhausen@cross-solution.de>
* @author Miroslav Fedeleš <miroslav.fedeles@gmail.com>
* @since 0.26
* @covers Solr\Bridge\Manager
* @covers \Solr\Bridge\Manager
* @requires extension solr
* @package SolrTest\Bridge
*/
class ManagerTest extends \PHPUnit_Framework_TestCase
class ManagerTest extends TestCase
{
/**
* Mock for ConnectOption class
* @var \PHPUnit_Framework_MockObject_MockObject
* @var MockObject
*/
protected $option;

Expand All @@ -38,7 +41,7 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
*/
protected $target;

public function setUp()
protected function setUp(): void
{
$option = $this->getMockBuilder(ConnectOption::class)
->getMock()
Expand Down
13 changes: 8 additions & 5 deletions test/SolrTest/Bridge/ResultConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace SolrTest\Bridge;

use PHPUnit\Framework\TestCase;

use Interop\Container\ContainerInterface;
use Solr\Bridge\ResultConverter;
use Core\Repository\RepositoryService;
Expand All @@ -23,11 +25,11 @@
* @author Anthonius Munthi <me@itstoni.com>
* @author Miroslav Fedeleš <miroslav.fedeles@gmail.com>
* @since 0.26
* @covers Solr\Bridge\ResultConverter
* @covers \Solr\Bridge\ResultConverter
* @package SolrTest\Bridge
* @coversDefaultClass \Solr\Bridge\ResultConverter
*/
class ResultConverterTest extends \PHPUnit_Framework_TestCase
class ResultConverterTest extends TestCase
{
/**
* @covers ::factory
Expand Down Expand Up @@ -57,11 +59,12 @@ public function testFactory()
* @covers ::convert
* @depends testFactory
* @dataProvider invalidResponseData
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage invalid response
*/
public function testConvertThrowsExceptionOnInvalidResponseData($responseData, array $data)
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('invalid response');

list ($resultConverter) = $data;

$filter = $this->getMockBuilder(AbstractPaginationQuery::class)
Expand Down Expand Up @@ -154,7 +157,7 @@ public function testConvert(array $data)
->willReturn($repository);

$proxies = $resultConverter->convert($filter, $response);
$this->assertInternalType('array', $proxies);
$this->assertIsArray($proxies);
$this->assertCount($expectedCount, $proxies);
$this->assertContains($proxy1, $proxies);
$this->assertContains($proxy2, $proxies);
Expand Down
7 changes: 5 additions & 2 deletions test/SolrTest/Bridge/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace SolrTest\Bridge;

use PHPUnit\Framework\TestCase;


use Core\Entity\LocationInterface;
use Jobs\Entity\Location;
Expand All @@ -24,7 +26,7 @@
* @since 0.26
* @package SolrTest\Bridge
*/
class UtilTest extends \PHPUnit_Framework_TestCase
class UtilTest extends TestCase
{
public function testConvertDateTime()
{
Expand Down Expand Up @@ -69,7 +71,8 @@ public function testConvertLocationString()
public function testConvertSolrDateToPhpDateTime($solrDate, $expected)
{
if (!$expected) {
$this->setExpectedException(InvalidArgumentException::class, 'invalid format');
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('invalid format');
}

$this->assertEquals($expected, Util::convertSolrDateToPhpDateTime($solrDate));
Expand Down
22 changes: 13 additions & 9 deletions test/SolrTest/Controller/ConsoleControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace SolrTest\Controller;

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

use Core\Console\ProgressBar;
use Doctrine\MongoDB\CursorInterface;
use Solr\Filter\EntityToDocument\JobEntityToSolrDocument;
Expand All @@ -18,6 +21,7 @@
use Jobs\Repository\Job as JobRepository;
use Solr\Controller\ConsoleController;
use stdClass;
use Zend\Log\Filter\Mock;

/**
* Class ConsoleControllerTest
Expand All @@ -28,7 +32,7 @@
* @package SolrTest\Controller
* @coversDefaultClass \Solr\Controller\ConsoleController
*/
class ConsoleControllerTest extends \PHPUnit_Framework_TestCase
class ConsoleControllerTest extends TestCase
{

/**
Expand All @@ -37,22 +41,22 @@ class ConsoleControllerTest extends \PHPUnit_Framework_TestCase
protected $controller;

/**
* @var SolrClient|\PHPUnit_Framework_MockObject_MockObject
* @var SolrClient|MockObject
*/
protected $client;

/**
* @var CursorInterface|\PHPUnit_Framework_MockObject_MockObject
* @var CursorInterface|MockObject
*/
protected $cursor;

/**
* @var ProgressBar|\PHPUnit_Framework_MockObject_MockObject
* @var ProgressBar|MockObject
*/
protected $progressBar;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var MockObject
*/
protected $progressBarFactory;

Expand All @@ -62,9 +66,9 @@ class ConsoleControllerTest extends \PHPUnit_Framework_TestCase
protected $options;

/**
* @see PHPUnit_Framework_TestCase::setUp()
* {@inheritDoc}
*/
public function setUp()
protected function setUp():void
{
$this->client = $this->getMockBuilder(SolrClient::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -123,7 +127,7 @@ public function testActiveJobIndexActionWithoutJobs()
$this->client->expects($this->never())
->method('optimize');

$this->assertContains('no active job', $this->controller->activeJobIndexAction());
$this->assertStringContainsString('no active job', $this->controller->activeJobIndexAction());
}

/**
Expand Down Expand Up @@ -165,6 +169,6 @@ public function testActiveJobIndexActionWithJobs()
public function testGetProgressBarFactory()
{
$progressBarFactory = $this->controller->getProgressBarFactory();
$this->assertInternalType('callable', $progressBarFactory);
$this->assertIsCallable($progressBarFactory);
}
}
11 changes: 7 additions & 4 deletions test/SolrTest/Entity/JobProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace SolrTest\Entity;

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

use Solr\Entity\JobProxy;
use Jobs\Entity\JobInterface;
use ArrayObject;
Expand All @@ -22,7 +25,7 @@
/**
* @coversDefaultClass \Solr\Entity\JobProxy
*/
class JobProxyTest extends \PHPUnit_Framework_TestCase
class JobProxyTest extends TestCase
{

/**
Expand All @@ -31,7 +34,7 @@ class JobProxyTest extends \PHPUnit_Framework_TestCase
protected $jobProxy;

/**
* @var JobInterface|\PHPUnit_Framework_MockObject_MockObject
* @var JobInterface|MockObject
*/
protected $jobDecorated;

Expand All @@ -41,9 +44,9 @@ class JobProxyTest extends \PHPUnit_Framework_TestCase
protected $solrResult;

/**
* @see \PHPUnit_Framework_TestCase::setUp()
* @see \PHPUnit\Framework\TestCase::setUp()
*/
protected function setUp()
protected function setUp(): void
{
$this->jobDecorated = $this->getMockBuilder(JobInterface::class)
->getMock();
Expand Down
Loading

0 comments on commit 90177bc

Please sign in to comment.