@@ 91-112 (lines=22) @@ | ||
88 | $this->assertEquals($expectedFilter, $actualFilter); |
|
89 | } |
|
90 | ||
91 | public function testTranslateOperator() |
|
92 | { |
|
93 | // Manually set the data source element, mimic what the data source would do |
|
94 | $dataSourceElement = new Field( |
|
95 | 'test_data_source_element_name', |
|
96 | '', |
|
97 | '', |
|
98 | new StringDataType() |
|
99 | ); |
|
100 | ||
101 | $dataSourceProphecy = $this->prophesize(DataSourceInterface::class); |
|
102 | $dataSourceProphecy->getFields()->willReturn([$dataSourceElement]); |
|
103 | ||
104 | $interpreterFactory = new InterpreterFactory($this->extensionContainerProphecy->reveal(), new FilterConditionFactory(), $this->contextFactoryProphecy->reveal()); |
|
105 | $interpreter = $interpreterFactory->create($dataSourceProphecy->reveal()); |
|
106 | ||
107 | // LIKE is valid for String type, should return LIKE |
|
108 | $this->assertEquals(FilterCondition::METHOD_STRING_LIKE, $interpreter->translateOperator('T_OP_LIKE', $dataSourceElement), 'Failed to translate T_OP_LIKE into STRING_LIKE for type String'); |
|
109 | ||
110 | // EQ is valid for String, and should choose STRING_EQ as it's the default for the type |
|
111 | $this->assertEquals(FilterCondition::METHOD_STRING_EQ, $interpreter->translateOperator('T_OP_EQ', $dataSourceElement), 'Failed to translate T_OP_EQ into STRING_EQ for type String'); |
|
112 | } |
|
113 | ||
114 | public function testInStatementsOnlyAcceptArraysAsValues() |
|
115 | { |
|
@@ 114-128 (lines=15) @@ | ||
111 | $this->assertEquals(FilterCondition::METHOD_STRING_EQ, $interpreter->translateOperator('T_OP_EQ', $dataSourceElement), 'Failed to translate T_OP_EQ into STRING_EQ for type String'); |
|
112 | } |
|
113 | ||
114 | public function testInStatementsOnlyAcceptArraysAsValues() |
|
115 | { |
|
116 | $astSubtree = new ASTAssertion('field', 'T_OP_IN', '123'); |
|
117 | $field = new Field('field', '', '', new NumberDataType()); |
|
118 | ||
119 | $dataSourceProphecy = $this->prophesize(DataSourceInterface::class); |
|
120 | $dataSourceProphecy->getFields()->willReturn([$field]); |
|
121 | ||
122 | $interpreterFactory = new InterpreterFactory($this->extensionContainerProphecy->reveal(), new FilterConditionFactory(), $this->contextFactoryProphecy->reveal()); |
|
123 | $interpreter = $interpreterFactory->create($dataSourceProphecy->reveal()); |
|
124 | ||
125 | $this->expectException(UQLInterpreterException::class); |
|
126 | $this->expectExceptionMessage('Only arrays are valid arguments for IN / NOT IN statements'); |
|
127 | $interpreter->buildFilter($astSubtree); |
|
128 | } |
|
129 | ||
130 | public function testNullValueCanBeCheckedOnlyWithIsOperator() |
|
131 | { |
|
@@ 130-144 (lines=15) @@ | ||
127 | $interpreter->buildFilter($astSubtree); |
|
128 | } |
|
129 | ||
130 | public function testNullValueCanBeCheckedOnlyWithIsOperator() |
|
131 | { |
|
132 | $astSubtree = new ASTAssertion('field', 'T_OP_GT', null); |
|
133 | $field = new Field('field', '', '', new NumberDataType()); |
|
134 | ||
135 | $dataSourceProphecy = $this->prophesize(DataSourceInterface::class); |
|
136 | $dataSourceProphecy->getFields()->willReturn([$field]); |
|
137 | ||
138 | $interpreterFactory = new InterpreterFactory($this->extensionContainerProphecy->reveal(), new FilterConditionFactory(), $this->contextFactoryProphecy->reveal()); |
|
139 | $interpreter = $interpreterFactory->create($dataSourceProphecy->reveal()); |
|
140 | ||
141 | $this->expectException(UQLInterpreterException::class); |
|
142 | $this->expectExceptionMessage('Only IS / IS NOT operator can be used to compare against null value'); |
|
143 | $interpreter->buildFilter($astSubtree); |
|
144 | } |
|
145 | ||
146 | protected function setUp() |
|
147 | { |