| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Grafizzi\Graph\Tests\BaseGraphTest: a component of the Grafizzi library. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * (c) 2012 Frédéric G. MARAND <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * Grafizzi is free software: you can redistribute it and/or modify it under the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * terms of the GNU Lesser General Public License as published by the Free | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * Software Foundation, either version 3 of the License, or (at your option) any | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * Grafizzi is distributed in the hope that it will be useful, but WITHOUT ANY | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * You should have received a copy of the GNU Lesser General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * along with Grafizzi, in the COPYING.LESSER.txt file.  If not, see | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * <http://www.gnu.org/licenses/> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | namespace Grafizzi\Graph\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | require 'vendor/autoload.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use \Grafizzi\Graph\Graph; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | use \Monolog\Logger; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | use \Monolog\Handler\StreamHandler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | use Pimple\Container; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  * Base test case. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  * Build a graph that all other test cases will need. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | abstract class BaseGraphTest extends TestCase { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |    * @var Graph | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |   public $Graph; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |    * @var \Pimple\Container | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |   public $dic; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |    * Prepares the environment before running a test. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |   protected function setUpExtended($name = 'G', $attributes = array()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     parent::setUp(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     $log = new Logger(basename(__FILE__, '.php')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     $log->pushHandler(new StreamHandler('php://stderr', Logger::INFO)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     $this->dic = new Container(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |       'logger' => $log, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     $this->Graph = new Graph($this->dic, $name, $attributes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |    * Helper function for testBuild() method. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |    * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |    * @param string $expected | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |    *   A DOT source. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |    * @param string $message | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |    *   The assertion message. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 76 |  |  |    */ | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |   public function check($expected, $message) { | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     $build = $this->Graph->build(); | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |     $this->Graph->logger->debug("\n\n$build\n\n"); | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |     $this->assertEquals($expected, $build, $message); | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |    * Cleans up the environment after running a test. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |   protected function tearDown() : void { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     $this->Graph = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     parent::tearDown(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |   } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 90 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |  | 
            
                        
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.