SemanticMediaWiki /
SemanticBreadcrumbLinks
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SBL\Tests; |
||
| 4 | |||
| 5 | use SBL\HookRegistry; |
||
| 6 | use SBL\Options; |
||
| 7 | use Title; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * @covers \SBL\HookRegistry |
||
| 11 | * @group semantic-breadcrumb-links |
||
| 12 | * |
||
| 13 | * @license GNU GPL v2+ |
||
| 14 | * @since 1.0 |
||
| 15 | * |
||
| 16 | * @author mwjames |
||
| 17 | */ |
||
| 18 | class HookRegistryTest extends \PHPUnit_Framework_TestCase { |
||
| 19 | |||
| 20 | public function testCanConstruct() { |
||
| 21 | |||
| 22 | $store = $this->getMockBuilder( '\SMW\Store' ) |
||
| 23 | ->disableOriginalConstructor() |
||
| 24 | ->getMockForAbstractClass(); |
||
| 25 | |||
| 26 | $options = $this->getMockBuilder( '\SBL\Options' ) |
||
| 27 | ->disableOriginalConstructor() |
||
| 28 | ->getMock(); |
||
| 29 | |||
| 30 | $this->assertInstanceOf( |
||
| 31 | '\SBL\HookRegistry', |
||
| 32 | new HookRegistry( $store, new $options ) |
||
| 33 | ); |
||
| 34 | } |
||
| 35 | |||
| 36 | public function testRegister() { |
||
| 37 | |||
| 38 | $title = Title::newFromText( __METHOD__ ); |
||
| 39 | |||
| 40 | $outputPage = $this->getMockBuilder( '\OutputPage' ) |
||
| 41 | ->disableOriginalConstructor() |
||
| 42 | ->getMock(); |
||
| 43 | |||
| 44 | $outputPage->expects( $this->any() ) |
||
| 45 | ->method( 'getTitle' ) |
||
| 46 | ->will( $this->returnValue( $title ) ); |
||
| 47 | |||
| 48 | $skin = $this->getMockBuilder( '\Skin' ) |
||
| 49 | ->disableOriginalConstructor() |
||
| 50 | ->getMock(); |
||
| 51 | |||
| 52 | $skin->expects( $this->any() ) |
||
| 53 | ->method( 'getOutput' ) |
||
| 54 | ->will( $this->returnValue( $outputPage ) ); |
||
| 55 | |||
| 56 | $store = $this->getMockBuilder( '\SMW\Store' ) |
||
| 57 | ->disableOriginalConstructor() |
||
| 58 | ->getMockForAbstractClass(); |
||
| 59 | |||
| 60 | $configuration = array( |
||
| 61 | 'useSubpageFinderFallback' => false, |
||
| 62 | 'tryToFindClosestDescendant' => false, |
||
| 63 | 'propertySearchPatternByNamespace' => array(), |
||
| 64 | 'breadcrumbTrailStyleClass' => 'foo', |
||
| 65 | 'breadcrumbDividerStyleClass' => 'bar', |
||
| 66 | 'hideSubpageParent' => true, |
||
| 67 | 'enabledSubpageParentAnnotation' => true, |
||
| 68 | 'wgNamespacesWithSubpages' => array() |
||
| 69 | ); |
||
| 70 | |||
| 71 | $instance = new HookRegistry( |
||
| 72 | $store, |
||
| 73 | new Options( $configuration ) |
||
| 74 | ); |
||
| 75 | |||
| 76 | $instance->register(); |
||
| 77 | |||
| 78 | $this->doTestInitProperties( $instance ); |
||
| 79 | $this->doTestSkinTemplateOutputPageBeforeExec( $instance, $skin ); |
||
| 80 | $this->doTestBeforePageDisplay( $instance, $outputPage, $skin ); |
||
| 81 | $this->doTestParserAfterTidy( $instance ); |
||
| 82 | $this->doTestParserAfterTidyToBailOutEarly( $instance ); |
||
| 83 | } |
||
| 84 | |||
| 85 | private function doTestInitProperties( $instance ) { |
||
| 86 | |||
| 87 | $handler = 'SMW::Property::initProperties'; |
||
| 88 | |||
| 89 | $this->assertTrue( |
||
| 90 | $instance->isRegistered( $handler ) |
||
| 91 | ); |
||
| 92 | |||
| 93 | $this->assertThatHookIsExcutable( |
||
| 94 | $instance->getHandlerFor( $handler ), |
||
| 95 | array() |
||
| 96 | ); |
||
| 97 | } |
||
| 98 | |||
| 99 | private function doTestSkinTemplateOutputPageBeforeExec( $instance, $skin ) { |
||
| 100 | |||
| 101 | $handler = 'SkinTemplateOutputPageBeforeExec'; |
||
| 102 | |||
| 103 | $this->assertTrue( |
||
| 104 | $instance->isRegistered( $handler ) |
||
| 105 | ); |
||
| 106 | |||
| 107 | $template = new \stdClass; |
||
| 108 | |||
| 109 | $this->assertThatHookIsExcutable( |
||
| 110 | $instance->getHandlerFor( $handler ), |
||
| 111 | array( &$skin, &$template ) |
||
| 112 | ); |
||
| 113 | } |
||
| 114 | |||
| 115 | private function doTestBeforePageDisplay( $instance, $outputPage, $skin ) { |
||
| 116 | |||
| 117 | $handler = 'BeforePageDisplay'; |
||
| 118 | |||
| 119 | $this->assertTrue( |
||
| 120 | $instance->isRegistered( $handler ) |
||
| 121 | ); |
||
| 122 | |||
| 123 | $this->assertThatHookIsExcutable( |
||
| 124 | $instance->getHandlerFor( $handler ), |
||
| 125 | array( &$outputPage, &$skin ) |
||
| 126 | ); |
||
| 127 | } |
||
| 128 | |||
| 129 | private function doTestParserAfterTidy( $instance ) { |
||
| 130 | |||
| 131 | $handler = 'ParserAfterTidy'; |
||
| 132 | |||
| 133 | $this->assertTrue( |
||
| 134 | $instance->isRegistered( $handler ) |
||
| 135 | ); |
||
| 136 | |||
| 137 | $title = Title::newFromText( __METHOD__ ); |
||
| 138 | |||
| 139 | $parserOptions = $this->getMockBuilder( '\ParserOptions' ) |
||
| 140 | ->disableOriginalConstructor() |
||
| 141 | ->getMock(); |
||
| 142 | |||
| 143 | $parserOutput = $this->getMockBuilder( '\ParserOutput' ) |
||
| 144 | ->disableOriginalConstructor() |
||
| 145 | ->getMock(); |
||
| 146 | |||
| 147 | $parser = $this->getMockBuilder( '\Parser' ) |
||
| 148 | ->disableOriginalConstructor() |
||
| 149 | ->getMock(); |
||
| 150 | |||
| 151 | $parser->expects( $this->any() ) |
||
| 152 | ->method( 'getTitle' ) |
||
| 153 | ->will( $this->returnValue( $title ) ); |
||
| 154 | |||
| 155 | $parser->expects( $this->any() ) |
||
| 156 | ->method( 'getOptions' ) |
||
| 157 | ->will( $this->returnValue( $parserOptions ) ); |
||
| 158 | |||
| 159 | $parser->expects( $this->any() ) |
||
| 160 | ->method( 'getOutput' ) |
||
| 161 | ->will( $this->returnValue( $parserOutput ) ); |
||
| 162 | |||
| 163 | $text = ''; |
||
| 164 | |||
| 165 | $this->assertThatHookIsExcutable( |
||
| 166 | $instance->getHandlerFor( $handler ), |
||
| 167 | array( &$parser, &$text ) |
||
| 168 | ); |
||
| 169 | } |
||
| 170 | |||
| 171 | private function doTestParserAfterTidyToBailOutEarly( $instance ) { |
||
| 172 | |||
| 173 | $handler = 'ParserAfterTidy'; |
||
| 174 | |||
| 175 | $this->assertTrue( |
||
| 176 | $instance->isRegistered( $handler ) |
||
| 177 | ); |
||
| 178 | |||
| 179 | $title = Title::newFromText( __METHOD__ ); |
||
| 180 | |||
| 181 | $parserOptions = $this->getMockBuilder( '\ParserOptions' ) |
||
| 182 | ->disableOriginalConstructor() |
||
| 183 | ->getMock(); |
||
| 184 | |||
| 185 | $parserOptions->expects( $this->any() ) |
||
| 186 | ->method( 'getInterfaceMessage' ) |
||
| 187 | ->will( $this->returnValue( true ) ); |
||
| 188 | |||
| 189 | $parserOutput = $this->getMockBuilder( '\ParserOutput' ) |
||
|
0 ignored issues
–
show
|
|||
| 190 | ->disableOriginalConstructor() |
||
| 191 | ->getMock(); |
||
| 192 | |||
| 193 | $parser = $this->getMockBuilder( '\Parser' ) |
||
| 194 | ->disableOriginalConstructor() |
||
| 195 | ->getMock(); |
||
| 196 | |||
| 197 | $parser->expects( $this->any() ) |
||
| 198 | ->method( 'getTitle' ) |
||
| 199 | ->will( $this->returnValue( $title ) ); |
||
| 200 | |||
| 201 | $parser->expects( $this->any() ) |
||
| 202 | ->method( 'getOptions' ) |
||
| 203 | ->will( $this->returnValue( $parserOptions ) ); |
||
| 204 | |||
| 205 | $text = ''; |
||
| 206 | |||
| 207 | $this->assertThatHookIsExcutable( |
||
| 208 | $instance->getHandlerFor( $handler ), |
||
| 209 | array( &$parser, &$text ) |
||
| 210 | ); |
||
| 211 | } |
||
| 212 | |||
| 213 | private function assertThatHookIsExcutable( \Closure $handler, $arguments ) { |
||
| 214 | $this->assertInternalType( |
||
| 215 | 'boolean', |
||
| 216 | call_user_func_array( $handler, $arguments ) |
||
| 217 | ); |
||
| 218 | } |
||
| 219 | |||
| 220 | } |
||
| 221 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.