| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Sportic\Timing\RaceTecClient\Tests\Parsers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Sportic\Timing\CommonClient\Models\Split; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Sportic\Timing\RaceTecClient\Scrapers\ResultPage as PageScraper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Sportic\Timing\RaceTecClient\Parsers\ResultPage as PageParser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Class ResultPageTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @package Sportic\Timing\RaceTecClient\Tests\Scrapers | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | class ResultPageTest extends AbstractPageTest | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     public function testGenerateResultsBox() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         self::assertSame('Marius-Alexandru Dragu', self::$parametersParsed['full_name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         self::assertSame('02:12:11.38', self::$parametersParsed['time']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         self::assertSame('10', self::$parametersParsed['pos_gen']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         self::assertSame('211', self::$parametersParsed['race']['participants']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         self::assertSame('10', self::$parametersParsed['pos_gender']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         self::assertSame('194', self::$parametersParsed['gender']['participants']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         self::assertSame('1', self::$parametersParsed['pos_category']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         self::assertSame('28', self::$parametersParsed['category']['participants']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         self::assertSame('188', self::$parametersParsed['bib']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         self::assertSame('male', self::$parametersParsed['gender']['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         self::assertSame('Masculin 45-49', self::$parametersParsed['category']['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         self::assertSame('Finished', self::$parametersParsed['status']['name']); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 34 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     public function testSplits() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         /** @var Split[] $splits */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $splits = self::$parametersParsed['splits']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         self::assertEquals(12, count($splits)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         self::assertInstanceOf(Split::class, $splits[0]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         self::assertSame('Swim', $splits[0]->getName()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         self::assertSame('00:17:21.53', $splits[0]->getTime()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         self::assertInstanceOf(Split::class, $splits[8]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         self::assertSame('Ciclism 7', $splits[8]->getName()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         self::assertSame('01:17:11.19', $splits[8]->getTimeFromStart()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         self::assertSame('00:08:50.52', $splits[8]->getTime()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      * @inheritdoc | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     protected static function getNewScraper() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         return new PageScraper('16648-2091-1-29925'); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      * @inheritdoc | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     protected static function getNewParser() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         return new PageParser(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |      * @inheritdoc | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     protected static function getSerializedFile() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         return 'result_page.serialized'; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |      * @inheritdoc | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     protected static function getHtmlFile() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         return 'result_page.html'; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 82 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 83 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 84 |  |  |  | 
            
                        
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.