1 | <?php |
||
18 | class DataKeyValueObjectClassTest extends BaseTest |
||
19 | { |
||
20 | /** |
||
21 | * Tests the DataKeyValueObjectClass parser. |
||
22 | */ |
||
23 | public function testParse() |
||
38 | |||
39 | /** |
||
40 | * Test DataKeyValueObjectClass parser throwing exception on missing sort clause. |
||
41 | * |
||
42 | * @expectedException \eZ\Publish\Core\REST\Common\Exceptions\Parser |
||
43 | * @expectedExceptionMessage The <DatePublished> sort clause doesn't exist in the input structure |
||
44 | */ |
||
45 | public function testParseExceptionOnMissingSortClause() |
||
54 | |||
55 | /** |
||
56 | * Test DataKeyValueObjectClass parser throwing exception on invalid direction format. |
||
57 | * |
||
58 | * @expectedException \eZ\Publish\Core\REST\Common\Exceptions\Parser |
||
59 | * @expectedExceptionMessage Invalid direction format in <DatePublished> sort clause |
||
60 | */ |
||
61 | public function testParseExceptionOnInvalidDirectionFormat() |
||
70 | |||
71 | /** |
||
72 | * Test DataKeyValueObjectClass parser throwing exception on nonexisting value object class. |
||
73 | * |
||
74 | * @expectedException \eZ\Publish\Core\REST\Common\Exceptions\Parser |
||
75 | * @expectedExceptionMessage Value object class <eC\Pubish\APl\Repudiatory\BadValues\Discontent\Queezy\SantaClause\ThisClassIsExistentiallyChallenged> is not defined |
||
76 | */ |
||
77 | public function testParseExceptionOnNonexistingValueObjectClass() |
||
89 | |||
90 | /** |
||
91 | * Returns the DataKeyValueObjectClass parser. |
||
92 | * |
||
93 | * @return \eZ\Publish\Core\REST\Server\Input\Parser\SortClause\DataKeyValueObjectClass |
||
94 | */ |
||
95 | protected function internalGetParser() |
||
102 | } |
||
103 |
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_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.