| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace Netdudes\DataSourceryBundle\Tests\UQL; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Netdudes\DataSourceryBundle\DataSource\Configuration\Field; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Netdudes\DataSourceryBundle\DataSource\DataSourceInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Netdudes\DataSourceryBundle\DataType\NumberDataType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Netdudes\DataSourceryBundle\DataType\StringDataType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Netdudes\DataSourceryBundle\Extension\ContextFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Netdudes\DataSourceryBundle\Extension\UqlExtensionContainer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Netdudes\DataSourceryBundle\Query\Filter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Netdudes\DataSourceryBundle\Query\FilterCondition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Netdudes\DataSourceryBundle\Query\FilterConditionFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Netdudes\DataSourceryBundle\UQL\AST\ASTAssertion; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Netdudes\DataSourceryBundle\UQL\AST\ASTGroup; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Netdudes\DataSourceryBundle\UQL\InterpreterFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | class InterpreterTest extends \PHPUnit_Framework_TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * @var ContextFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     private $contextFactoryProphecy; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * @var UqlExtensionContainer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     private $extensionContainerProphecy; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * Test the filter construction against a typical complex multilevel situation. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     public function testBuildFilter() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $astSubtree = new ASTGroup( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             'T_LOGIC_AND', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                 new ASTGroup( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |                     'T_LOGIC_OR', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                     [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |                         new ASTAssertion( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                             'test_dse_1', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                             'T_OP_EQ', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                             'value1' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                         ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                         new ASTAssertion( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                             'test_dse_2', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                             'T_OP_LT', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                             'value2' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                         ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                     ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 new ASTAssertion( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                     'test_dse_3', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                     'T_OP_NEQ', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                     'value3' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $filterDefinition1 = new Filter(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $filterDefinition1->setConditionType('OR'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $filter1 = new FilterCondition('test_dse_1', FilterCondition::METHOD_NUMERIC_EQ, 'value1', 'value1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $filter2 = new FilterCondition('test_dse_2', FilterCondition::METHOD_NUMERIC_LT, 'value2', 'value2'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $filterDefinition1[] = $filter1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $filterDefinition1[] = $filter2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $filter3 = new FilterCondition('test_dse_3', FilterCondition::METHOD_NUMERIC_NEQ, 'value3', 'value3'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $filterDefinition2 = new Filter(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $filterDefinition2->setConditionType('AND'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $filterDefinition2[] = $filterDefinition1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $filterDefinition2[] = $filter3; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $expectedFilter = $filterDefinition2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $dataSourceElements = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             new Field('test_dse_1', '', '', new NumberDataType()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             new Field('test_dse_2', '', '', new NumberDataType()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             new Field('test_dse_3', '', '', new NumberDataType()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         $dataSourceProphecy = $this->prophesize(DataSourceInterface::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $dataSourceProphecy->getFields()->willReturn($dataSourceElements); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $interpreterFactory = new InterpreterFactory($this->extensionContainerProphecy->reveal(), new FilterConditionFactory(), $this->contextFactoryProphecy->reveal()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         $interpreter = $interpreterFactory->create($dataSourceProphecy->reveal()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $actualFilter = $interpreter->buildFilter($astSubtree); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $this->assertEquals($expectedFilter, $actualFilter); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     public function testTranslateOperator() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         // Manually set the data source element, mimic what the data source would do | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $dataSourceElement = new Field( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             'test_data_source_element_name', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             new StringDataType() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         $dataSourceProphecy = $this->prophesize(DataSourceInterface::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         $dataSourceProphecy->getFields()->willReturn([$dataSourceElement]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $interpreterFactory = new InterpreterFactory($this->extensionContainerProphecy->reveal(), new FilterConditionFactory(), $this->contextFactoryProphecy->reveal()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $interpreter = $interpreterFactory->create($dataSourceProphecy->reveal()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         // LIKE is valid for String type, should return LIKE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $this->assertEquals(FilterCondition::METHOD_STRING_LIKE, $interpreter->translateOperator('T_OP_LIKE', $dataSourceElement), 'Failed to translate T_OP_LIKE into STRING_LIKE for type String'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         // EQ is valid for String, and should choose STRING_EQ as it's the default for the type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         $this->assertEquals(FilterCondition::METHOD_STRING_EQ, $interpreter->translateOperator('T_OP_EQ', $dataSourceElement), 'Failed to translate T_OP_EQ into STRING_EQ for type String'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 113 |  |  |     protected function setUp() | 
            
                                                        
            
                                    
            
            
                | 114 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 115 |  |  |         $this->extensionContainerProphecy = $this->prophesize(UqlExtensionContainer::class); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 116 |  |  |         $this->contextFactoryProphecy = $this->prophesize(ContextFactory::class); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 117 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 118 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 119 |  |  |  | 
            
                        
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.