| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Tests\PHPSA\Expression\Operators; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use PhpParser\Node; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use PHPSA\CompiledExpression; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use PHPSA\Compiler\Expression; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use PHPSA\Variable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * Class PreDecTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @package Tests\PHPSA\Expression\BinaryOp | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class PreDecTest extends \Tests\PHPSA\TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     public function getDataProviderForSuccess() | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |         return array( | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |             array(-1), | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |             array(1), | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |             array(99), | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |             array(0), | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @dataProvider getDataProviderForSuccess | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     public function testSuccessFromDataProvider($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $testVariableName = 'myTestVariable'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $context = $this->getContext(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $context->addVariable(new Variable($testVariableName, $value, CompiledExpression::INTEGER)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $baseExpression = new Node\Expr\PreDec( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             new Node\Expr\Variable( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                 new Node\Name($testVariableName) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $compiledExpression = $this->compileExpression($baseExpression, $context); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $this->assertInstanceOfCompiledExpression($compiledExpression); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $this->assertSame(CompiledExpression::INTEGER, $compiledExpression->getType()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->assertSame(--$value, $compiledExpression->getValue()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     public function getDataProviderForSuccessDouble() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             array(-1.4), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             array(1.4), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             array(99.4), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             array(0.4), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @dataProvider getDataProviderForSuccessDouble | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     public function testSuccessDoubleFromDataProvider($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $testVariableName = 'myTestVariable'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $context = $this->getContext(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $context->addVariable(new Variable($testVariableName, $value, CompiledExpression::DOUBLE)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $baseExpression = new Node\Expr\PreDec( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             new Node\Expr\Variable( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                 new Node\Name($testVariableName) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $compiledExpression = $this->compileExpression($baseExpression, $context); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $this->assertInstanceOfCompiledExpression($compiledExpression); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $this->assertSame(CompiledExpression::DOUBLE, $compiledExpression->getType()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $this->assertSame(--$value, $compiledExpression->getValue()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 85 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 86 |  |  |  |