1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mdiyakov\DoctrineSolrBundle\Tests\Config; |
4
|
|
|
|
5
|
|
|
use Mdiyakov\DoctrineSolrBundle\Config\ConfigValidator; |
6
|
|
|
use Mdiyakov\DoctrineSolrBundle\Finder\ClassFinder; |
7
|
|
|
use Symfony\Component\Yaml\Yaml; |
8
|
|
|
|
9
|
|
|
class MyEntityFinder extends ClassFinder {} |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class ConfigValidatorTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var ConfigValidator |
16
|
|
|
*/ |
17
|
|
|
private $validator; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var array[]][] |
21
|
|
|
*/ |
22
|
|
|
private $configFixtures; |
23
|
|
|
|
24
|
|
|
public function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->validator = new ConfigValidator(); |
27
|
|
|
$this->configFixtures = Yaml::parse(file_get_contents(__DIR__ . '/config_fixtures.yml')); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testSuccessValidation() |
31
|
|
|
{ |
32
|
|
|
$this->runConfigTest('success_config'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @expectedException \Mdiyakov\DoctrineSolrBundle\Exception\ConfigFieldException |
37
|
|
|
*/ |
38
|
|
|
public function testConfigFieldMissed() |
39
|
|
|
{ |
40
|
|
|
$this->runConfigTest('config_field_missed'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @expectedException \Mdiyakov\DoctrineSolrBundle\Exception\SchemaConfigException |
45
|
|
|
* @expectedExceptionMessage You have more than one fields with the same document field name "d_id" |
46
|
|
|
*/ |
47
|
|
|
public function testDocumentNamesAreUnique() |
48
|
|
|
{ |
49
|
|
|
$this->runConfigTest('document_field_names_unique'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @expectedException \Mdiyakov\DoctrineSolrBundle\Exception\RequiredFieldException |
54
|
|
|
* @expectedExceptionMessage Either getter method "getExtraField" or isser method "isExtraField" is not found in Mdiyakov\DoctrineSolrBundle\Tests\Config\Entity\MyEntity. |
55
|
|
|
*/ |
56
|
|
|
public function testEntityFieldNotExist() |
57
|
|
|
{ |
58
|
|
|
$this->runConfigTest('entity_field_not_exist'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @expectedException \Mdiyakov\DoctrineSolrBundle\Exception\FilterConfigException |
63
|
|
|
* @expectedExceptionMessage Filter "filter_1" is not defined in "filters" section |
64
|
|
|
*/ |
65
|
|
|
public function testFilterNotDefined() |
66
|
|
|
{ |
67
|
|
|
$this->runConfigTest('filter_not_defined'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @expectedException \Mdiyakov\DoctrineSolrBundle\Exception\ClientConfigException |
72
|
|
|
* @expectedExceptionMessage Solarium client "my_client" is not defined in "solarium_clients" section |
73
|
|
|
*/ |
74
|
|
|
public function testClientNotDefined() |
75
|
|
|
{ |
76
|
|
|
$this->runConfigTest('client_not_defined'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @expectedException \Mdiyakov\DoctrineSolrBundle\Exception\SchemaNotFoundException |
81
|
|
|
* @expectedExceptionMessage Schema "my_schema" is not found in "schema" config section. Check config.yml |
82
|
|
|
*/ |
83
|
|
|
public function testSchemaNotDefined() |
84
|
|
|
{ |
85
|
|
|
$this->runConfigTest('schema_not_defined'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @expectedException \Mdiyakov\DoctrineSolrBundle\Exception\EntityClassConfigException |
90
|
|
|
* @expectedExceptionMessage It seems entity class "Mdiyakov\DoctrineSolrBundle\Tests\Config\Entity\MyEntity" has been configured more than once inside "indexed_entities" section. You can not have different config for the single entity class |
91
|
|
|
*/ |
92
|
|
|
public function testEntityClassDoubled() |
93
|
|
|
{ |
94
|
|
|
$this->runConfigTest('entity_class_doubled'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @expectedException \Mdiyakov\DoctrineSolrBundle\Exception\ConfigFieldException |
100
|
|
|
* @expectedExceptionMessage "my_enitity_type" discriminator value has already been used. |
101
|
|
|
It seems there are two entity classes inside "indexed_entities" with identical discriminator config field value |
102
|
|
|
*/ |
103
|
|
|
public function testDiscriminatorConfigNotUnique() |
104
|
|
|
{ |
105
|
|
|
$config = $this->configFixtures['discriminator_config_not_unique']; |
106
|
|
|
|
107
|
|
|
$config['indexed_entities']['my_entity_1']['class'] = 'Mdiyakov\DoctrineSolrBundle\Tests\Config\Entity\MyEntity'; |
108
|
|
|
$config['indexed_entities']['my_entity_2']['class'] = 'Mdiyakov\DoctrineSolrBundle\Tests\Config\Entity\MyEntity2'; |
109
|
|
|
|
110
|
|
|
foreach ($config['indexed_entities'] as $entityConfig) { |
111
|
|
|
$this->validator->validate($entityConfig, $config['schemes'], $config['filters'], $config['solarium_clients']); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param string $configName |
117
|
|
|
* @return array |
118
|
|
|
*/ |
119
|
|
|
private function getConfig($configName) |
120
|
|
|
{ |
121
|
|
|
$config = $this->configFixtures[$configName]; |
122
|
|
|
|
123
|
|
|
$config['indexed_entities']['my_entity']['class'] = 'Mdiyakov\DoctrineSolrBundle\Tests\Config\Entity\MyEntity'; |
124
|
|
|
$config['indexed_entities']['my_entity']['finder_class'] = 'Mdiyakov\DoctrineSolrBundle\Tests\Config\MyEntityFinder'; |
125
|
|
|
|
126
|
|
|
return $config; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param string $configName |
131
|
|
|
*/ |
132
|
|
|
private function runConfigTest($configName) |
133
|
|
|
{ |
134
|
|
|
$config = $this->getConfig($configName); |
135
|
|
|
foreach ($config['indexed_entities'] as $entityConfig) { |
136
|
|
|
$this->validator->validate($entityConfig, $config['schemes'], $config['filters'], $config['solarium_clients']); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
} |