@@ 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-127 (lines=14) @@ | ||
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->setExpectedException(UQLInterpreterException::class, 'Only arrays are valid arguments for IN / NOT IN statements'); |
|
126 | $interpreter->buildFilter($astSubtree); |
|
127 | } |
|
128 | ||
129 | public function testNullValueCanBeCheckedOnlyWithIsOperator() |
|
130 | { |
|
@@ 129-142 (lines=14) @@ | ||
126 | $interpreter->buildFilter($astSubtree); |
|
127 | } |
|
128 | ||
129 | public function testNullValueCanBeCheckedOnlyWithIsOperator() |
|
130 | { |
|
131 | $astSubtree = new ASTAssertion('field', 'T_OP_GT', null); |
|
132 | $field = new Field('field', '', '', new NumberDataType()); |
|
133 | ||
134 | $dataSourceProphecy = $this->prophesize(DataSourceInterface::class); |
|
135 | $dataSourceProphecy->getFields()->willReturn([$field]); |
|
136 | ||
137 | $interpreterFactory = new InterpreterFactory($this->extensionContainerProphecy->reveal(), new FilterConditionFactory(), $this->contextFactoryProphecy->reveal()); |
|
138 | $interpreter = $interpreterFactory->create($dataSourceProphecy->reveal()); |
|
139 | ||
140 | $this->setExpectedException(UQLInterpreterException::class, 'Only IS / IS NOT operator can be used to compare against null value'); |
|
141 | $interpreter->buildFilter($astSubtree); |
|
142 | } |
|
143 | ||
144 | protected function setUp() |
|
145 | { |