Code Duplication    Length = 15-22 lines in 3 locations

Tests/UQL/InterpreterTest.php 3 locations

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