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