Skip to content

Commit

Permalink
php5.4 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mdiyakov committed Mar 24, 2018
1 parent 22eaaa0 commit 6592d15
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 55 deletions.
6 changes: 3 additions & 3 deletions Manager/FinderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class FinderManager
public function __construct(Config $config, SelectQueryBuilder $queryBuilder)
{
$entityConfigs = $config->getIndexedEntities();

$defaultFinderClass = 'Mdiyakov\DoctrineSolrBundle\Finder\ClassFinder';
foreach ($entityConfigs as $entityConfig) {
$entityClass = $entityConfig['class'];
if (!array_key_exists($entityClass, $this->classFinders)) {

$finderClass = (!empty($entityConfig['finder_class'])) ? $entityConfig['finder_class'] : ClassFinder::class;
$finderClass = (!empty($entityConfig['finder_class'])) ? $entityConfig['finder_class'] : $defaultFinderClass;

if ($finderClass != ClassFinder::class && !is_subclass_of($finderClass, ClassFinder::class)) {
if ($finderClass != $defaultFinderClass && !is_subclass_of($finderClass, $defaultFinderClass)) {
throw new FinderException('Finder class of entity must be extended from ClassFinder');
}

Expand Down
12 changes: 6 additions & 6 deletions Schema/Field/Entity/FieldFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
class FieldFactory
{
private $map = [
'string' => StringField::class,
'int' => IntField::class,
'double' => DoubleField::class,
'array' => ArrayField::class,
'boolean' => BooleanField::class,
'date' => DateField::class,
'string' => 'Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\StringField',
'int' => 'Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\IntField',
'double' => 'Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\DoubleField',
'array' => 'Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\ArrayField',
'boolean' => 'Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\BooleanField',
'date' => 'Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\DateField',
];

/**
Expand Down
10 changes: 4 additions & 6 deletions Tests/Config/ConfigValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Mdiyakov\DoctrineSolrBundle\Config\ConfigValidator;
use Mdiyakov\DoctrineSolrBundle\Finder\ClassFinder;
use Mdiyakov\DoctrineSolrBundle\Tests\Config\Entity\MyEntity;
use Mdiyakov\DoctrineSolrBundle\Tests\Config\Entity\MyEntity2;
use Symfony\Component\Yaml\Yaml;

class MyEntityFinder extends ClassFinder {}
Expand Down Expand Up @@ -96,8 +94,8 @@ public function testDiscriminatorConfigNotUnique()
{
$config = $this->configFixtures['discriminator_config_not_unique'];

$config['indexed_entities']['my_entity_1']['class'] = MyEntity::class;
$config['indexed_entities']['my_entity_2']['class'] = MyEntity2::class;
$config['indexed_entities']['my_entity_1']['class'] = 'Mdiyakov\DoctrineSolrBundle\Tests\Config\Entity\MyEntity';
$config['indexed_entities']['my_entity_2']['class'] = 'Mdiyakov\DoctrineSolrBundle\Tests\Config\Entity\MyEntity2';

foreach ($config['indexed_entities'] as $entityConfig) {
$this->validator->validate($entityConfig, $config['schemes'], $config['filters'], $config['solarium_clients']);
Expand All @@ -112,8 +110,8 @@ private function getConfig($configName)
{
$config = $this->configFixtures[$configName];

$config['indexed_entities']['my_entity']['class'] = MyEntity::class;
$config['indexed_entities']['my_entity']['finder_class'] = MyEntityFinder::class;
$config['indexed_entities']['my_entity']['class'] = 'Mdiyakov\DoctrineSolrBundle\Tests\Config\Entity\MyEntity';
$config['indexed_entities']['my_entity']['finder_class'] = 'Mdiyakov\DoctrineSolrBundle\Tests\Config\MyEntityFinder';

return $config;
}
Expand Down
36 changes: 16 additions & 20 deletions Tests/Query/Select/AbstractSelectQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
namespace Mdiyakov\DoctrineSolrBundle\Tests\Query\Select;

use Mdiyakov\DoctrineSolrBundle\Query\Select\AbstractSelectQuery;
use Mdiyakov\DoctrineSolrBundle\Schema\Field\ConfigEntityField;
use Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\Field;
use Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\StringField;
use Mdiyakov\DoctrineSolrBundle\Schema\Schema;

class AbstractSelectQueryTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -19,7 +15,7 @@ public function testAddConfigFieldOrWhere()

$fieldName = 'type';
$documentFieldName = 'discriminator';
$field = $this->getFieldMock($documentFieldName, ConfigEntityField::class);
$field = $this->getFieldMock($documentFieldName, 'Mdiyakov\DoctrineSolrBundle\Schema\Field\ConfigEntityField');
$searchTerm = 'search';

$schema->expects($this->any())
Expand Down Expand Up @@ -51,7 +47,7 @@ public function testAddAndWhere()

$entityFieldName = 'title';
$documentFieldName = 'd_title';
$field = $this->getFieldMock($documentFieldName, StringField::class);
$field = $this->getFieldMock($documentFieldName, 'Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\StringField');
$searchTerm = 'search+-?*';
$searchTermFiltered = 'search\+\-\?\*';
$searchTermWildcardFiltered = 'search\+\-?*';
Expand Down Expand Up @@ -85,7 +81,7 @@ public function testReset()

$entityFieldName = 'title';
$documentFieldName = 'd_title';
$field = $this->getFieldMock($documentFieldName, StringField::class);
$field = $this->getFieldMock($documentFieldName, 'Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\StringField');
$searchTerm = 'search';

$schema->expects($this->any())
Expand Down Expand Up @@ -118,7 +114,7 @@ public function testAddOrWhere()
$entityFieldName = 'title';
$documentFieldName = 'd_title';
$searchTerm = 'search';
$field = $this->getFieldMock($documentFieldName, StringField::class);
$field = $this->getFieldMock($documentFieldName, 'Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\StringField');

$schema->expects($this->any())
->method('getFieldByEntityFieldName')
Expand Down Expand Up @@ -149,7 +145,7 @@ public function testAddOrWhereWithPriority()
$entityFieldName = 'title';
$documentFieldName = 'd_title';
$searchTerm = 'search';
$field = $this->getFieldMock($documentFieldName, StringField::class, 10);
$field = $this->getFieldMock($documentFieldName, 'Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\StringField', 10);

$schema->expects($this->any())
->method('getFieldByEntityFieldName')
Expand Down Expand Up @@ -184,7 +180,7 @@ public function testAddRangeOrWhere()
$from = 3;
$to = 89;

$field = $this->getFieldMock($documentFieldName, StringField::class);
$field = $this->getFieldMock($documentFieldName, 'Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\StringField');

$schema->expects($this->any())
->method('getFieldByEntityFieldName')
Expand Down Expand Up @@ -219,7 +215,7 @@ public function testAddRangeAndWhere()
$from = 3;
$to = 89;

$field = $this->getFieldMock($documentFieldName, StringField::class);
$field = $this->getFieldMock($documentFieldName, 'Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\StringField');
$schema->expects($this->any())
->method('getFieldByEntityFieldName')
->with($entityFieldName)
Expand Down Expand Up @@ -254,7 +250,7 @@ public function testAddFuzzyAndWhere()
$searchTerm = 'search';
$distance = 19;

$field = $this->getFieldMock($documentFieldName, StringField::class);
$field = $this->getFieldMock($documentFieldName, 'Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\StringField');
$schema->expects($this->any())
->method('getFieldByEntityFieldName')
->with($entityFieldName)
Expand Down Expand Up @@ -287,7 +283,7 @@ public function testAddFuzzyOrWhere()
$searchTerm = 'search';
$distance = 19;

$field = $this->getFieldMock($documentFieldName, StringField::class);
$field = $this->getFieldMock($documentFieldName, 'Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\StringField');
$schema->expects($this->any())
->method('getFieldByEntityFieldName')
->with($entityFieldName)
Expand Down Expand Up @@ -318,7 +314,7 @@ public function testGroupConditionsAsOr()
$documentFieldName = 'd_category';
$searchTerm = 'search';

$field = $this->getFieldMock($documentFieldName, StringField::class);
$field = $this->getFieldMock($documentFieldName, 'Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\StringField');
$schema->expects($this->any())
->method('getFieldByEntityFieldName')
->with($entityFieldName)
Expand Down Expand Up @@ -350,7 +346,7 @@ public function testGroupConditionsAsAnd()
$documentFieldName = 'd_category';
$searchTerm = 'search';

$field = $this->getFieldMock($documentFieldName, StringField::class);
$field = $this->getFieldMock($documentFieldName, 'Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\StringField');
$schema->expects($this->any())
->method('getFieldByEntityFieldName')
->with($entityFieldName)
Expand All @@ -374,9 +370,9 @@ public function testGroupConditionsAsAnd()

private function getSchemaMock()
{
$schema = $this->getMockBuilder(Schema::class)->disableOriginalConstructor()->getMock();
$discriminatorField = $this->getMockBuilder(ConfigEntityField::class)->disableOriginalConstructor()->getMock();
$primaryKeyField = $this->getMockBuilder(Field::class)->disableOriginalConstructor()->getMock();
$schema = $this->getMockBuilder('Mdiyakov\DoctrineSolrBundle\Schema\Schema')->disableOriginalConstructor()->getMock();
$discriminatorField = $this->getMockBuilder('Mdiyakov\DoctrineSolrBundle\Schema\Field\ConfigEntityField')->disableOriginalConstructor()->getMock();
$primaryKeyField = $this->getMockBuilder('Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\Field')->disableOriginalConstructor()->getMock();

$schema->expects($this->at(0))->method('getDiscriminatorConfigField')
->will($this->returnValue($discriminatorField));
Expand All @@ -395,12 +391,12 @@ private function getSchemaMock()
private function getQueryMock($client, $schema)
{
/** @var AbstractSelectQuery|\PHPUnit_Framework_MockObject_MockObject $query */
return $this->getMockForAbstractClass(AbstractSelectQuery::class, [$client, $schema]);
return $this->getMockForAbstractClass('Mdiyakov\DoctrineSolrBundle\Query\Select\AbstractSelectQuery', [$client, $schema]);
}

private function getClientMock()
{
$client = $this->getMockBuilder(\Solarium\Client::class)->disableOriginalConstructor()->getMock();
$client = $this->getMockBuilder('Solarium\Client')->disableOriginalConstructor()->getMock();

$client->expects($this->at(0))->method('createSelect')
->will($this->returnValue(
Expand Down
9 changes: 4 additions & 5 deletions Tests/Query/Select/ClassSelectQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Mdiyakov\DoctrineSolrBundle\Query\Hydrator\SelectQueryHydrator;
use Mdiyakov\DoctrineSolrBundle\Query\Select\ClassSelectQuery;
use Mdiyakov\DoctrineSolrBundle\Schema\Field\ConfigEntityField;
use Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\Field;
use Mdiyakov\DoctrineSolrBundle\Schema\Schema;

class ClassSelectQueryTest extends \PHPUnit_Framework_TestCase
Expand All @@ -23,17 +22,17 @@ public function testInitDiscriminatorConditionsSuccess()
];

/** @var \Solarium\Client|\PHPUnit_Framework_MockObject_MockObject $client */
$client = $this->getMockBuilder(\Solarium\Client::class)->disableOriginalConstructor()->getMock();
$client = $this->getMockBuilder('Solarium\Client')->disableOriginalConstructor()->getMock();
$client->expects($this->at(0))->method('createSelect')
->will($this->returnValue(
$this->createMock('Solarium\QueryType\Select\Query\Query')
));


/** @var Schema|\PHPUnit_Framework_MockObject_MockObject $schema */
$schema = $this->getMockBuilder(Schema::class)->disableOriginalConstructor()->getMock();
$schema = $this->getMockBuilder('Mdiyakov\DoctrineSolrBundle\Schema\Schema')->disableOriginalConstructor()->getMock();
$discriminatorField = new ConfigEntityField($configFieldName, $documentFieldName, true, 10);
$primaryKeyField = $this->getMockBuilder(Field::class)->disableOriginalConstructor()->getMock();
$primaryKeyField = $this->getMockBuilder('Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\Field')->disableOriginalConstructor()->getMock();

$schema->expects($this->any())->method('getDiscriminatorConfigField')
->will($this->returnValue($discriminatorField));
Expand All @@ -42,7 +41,7 @@ public function testInitDiscriminatorConditionsSuccess()
->will($this->returnValue($primaryKeyField));

/** @var SelectQueryHydrator|\PHPUnit_Framework_MockObject_MockObject $hydrator */
$hydrator = $this->getMockBuilder(SelectQueryHydrator::class)->disableOriginalConstructor()->getMock();
$hydrator = $this->getMockBuilder('Mdiyakov\DoctrineSolrBundle\Query\Hydrator\SelectQueryHydrator')->disableOriginalConstructor()->getMock();
$query = new ClassSelectQuery(
$client,
$schema,
Expand Down
11 changes: 4 additions & 7 deletions Tests/Query/Select/MultiClassSelectQueryTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<?php


namespace Mdiyakov\DoctrineSolrBundle\Tests\Query\Select;


use Mdiyakov\DoctrineSolrBundle\Query\Hydrator\SelectQueryHydrator;
use Mdiyakov\DoctrineSolrBundle\Query\Select\MultiClassSelectQuery;
use Mdiyakov\DoctrineSolrBundle\Schema\Field\ConfigEntityField;
use Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\Field;
use Mdiyakov\DoctrineSolrBundle\Schema\Schema;

class MultiClassSelectQueryTest extends \PHPUnit_Framework_TestCase
Expand All @@ -32,17 +29,17 @@ public function testInitDiscriminatorConditionsSuccess()
];

/** @var \Solarium\Client|\PHPUnit_Framework_MockObject_MockObject $client */
$client = $this->getMockBuilder(\Solarium\Client::class)->disableOriginalConstructor()->getMock();
$client = $this->getMockBuilder('Solarium\Client')->disableOriginalConstructor()->getMock();
$client->expects($this->at(0))->method('createSelect')
->will($this->returnValue(
$this->createMock('Solarium\QueryType\Select\Query\Query')
));


/** @var Schema|\PHPUnit_Framework_MockObject_MockObject $schema */
$schema = $this->getMockBuilder(Schema::class)->disableOriginalConstructor()->getMock();
$schema = $this->getMockBuilder('Mdiyakov\DoctrineSolrBundle\Schema\Schema')->disableOriginalConstructor()->getMock();
$discriminatorField = new ConfigEntityField($configFieldName, $documentFieldName, true, 10);
$primaryKeyField = $this->getMockBuilder(Field::class)->disableOriginalConstructor()->getMock();
$primaryKeyField = $this->getMockBuilder('Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\Field')->disableOriginalConstructor()->getMock();

$schema->expects($this->any())->method('getDiscriminatorConfigField')
->will($this->returnValue($discriminatorField));
Expand All @@ -51,7 +48,7 @@ public function testInitDiscriminatorConditionsSuccess()
->will($this->returnValue($primaryKeyField));

/** @var SelectQueryHydrator|\PHPUnit_Framework_MockObject_MockObject $hydrator */
$hydrator = $this->getMockBuilder(SelectQueryHydrator::class)->disableOriginalConstructor()->getMock();
$hydrator = $this->getMockBuilder('Mdiyakov\DoctrineSolrBundle\Query\Hydrator\SelectQueryHydrator')->disableOriginalConstructor()->getMock();
$query = new MultiClassSelectQuery(
$schema,
$client,
Expand Down
13 changes: 5 additions & 8 deletions Tests/Schema/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace Mdiyakov\DoctrineSolrBundle\Tests\Schema;

use Mdiyakov\DoctrineSolrBundle\Schema\Field\ConfigEntityField;
use Mdiyakov\DoctrineSolrBundle\Schema\Field\DocumentUniqueField;
use Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\Field;
use Mdiyakov\DoctrineSolrBundle\Schema\Schema;
use Symfony\Component\Yaml\Yaml;

Expand Down Expand Up @@ -65,7 +62,7 @@ function($configFieldConfig) { return $configFieldConfig['document_field_name'];

$discriminator = false;
foreach($configFields as $configField) {
$this->assertInstanceOf(ConfigEntityField::class, $configField);
$this->assertInstanceOf('Mdiyakov\DoctrineSolrBundle\Schema\Field\ConfigEntityField', $configField);
$discriminator = $discriminator ? $discriminator : $configField->isDiscriminator();
$this->assertArrayHasKey($configField->getConfigFieldName(), $configFieldNames);
$this->assertArrayHasKey($configField->getDocumentFieldName(), $documentConfigFieldNames);
Expand All @@ -74,23 +71,23 @@ function($configFieldConfig) { return $configFieldConfig['document_field_name'];
$this->assertEquals(true, $discriminator);

$uniqueDocumentField = $schema->getDocumentUniqueField();
$this->assertInstanceOf(DocumentUniqueField::class, $uniqueDocumentField);
$this->assertInstanceOf('Mdiyakov\DoctrineSolrBundle\Schema\Field\DocumentUniqueField', $uniqueDocumentField);
$this->assertEquals($schemaConfig['document_unique_field']['name'], $uniqueDocumentField->getName());

$primaryKeyField = $schema->getEntityPrimaryKeyField();
$this->assertInstanceOf(Field::class, $primaryKeyField);
$this->assertInstanceOf('Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\Field', $primaryKeyField);
$this->assertEquals('id', $primaryKeyField->getEntityFieldName());
$this->assertEquals('d_id', $primaryKeyField->getDocumentFieldName());

$fields = $schema->getFields();
foreach($fields as $field) {
$this->assertInstanceOf(Field::class, $field);
$this->assertInstanceOf('Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\Field', $field);
$this->assertArrayHasKey($field->getEntityFieldName(), $fieldNames);
$this->assertArrayHasKey($field->getDocumentFieldName(), $documentFieldNames);
}

$titleField = $schema->getFieldByEntityFieldName('title');
$this->assertInstanceOf(Field::class, $titleField);
$this->assertInstanceOf('Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\Field', $titleField);
$this->assertEquals('title', $titleField->getEntityFieldName());
$this->assertEquals('d_title', $titleField->getDocumentFieldName());
}
Expand Down

0 comments on commit 6592d15

Please sign in to comment.