MediaWiki  1.33.0
Go to the documentation of this file.
1 <?php
14  public function testGetRedactedTrace() {
15  $refvar = 'value';
16  try {
17  $array = [ 'a', 'b' ];
18  $object = new stdClass();
19  self::helperThrowAnException( $array, $object, $refvar );
20  } catch ( Exception $e ) {
21  }
23  # Make sure our stack trace contains an array and an object passed to
24  # some function in the stacktrace. Else, we can not assert the trace
25  # redaction achieved its job.
26  $trace = $e->getTrace();
27  $hasObject = false;
28  $hasArray = false;
29  foreach ( $trace as $frame ) {
30  if ( !isset( $frame['args'] ) ) {
31  continue;
32  }
33  foreach ( $frame['args'] as $arg ) {
34  $hasObject = $hasObject || is_object( $arg );
35  $hasArray = $hasArray || is_array( $arg );
36  }
38  if ( $hasObject && $hasArray ) {
39  break;
40  }
41  }
42  $this->assertTrue( $hasObject,
43  "The stacktrace must have a function having an object has parameter" );
44  $this->assertTrue( $hasArray,
45  "The stacktrace must have a function having an array has parameter" );
47  # Now we redact the trace.. and make sure no function arguments are
48  # arrays or objects.
51  foreach ( $redacted as $frame ) {
52  if ( !isset( $frame['args'] ) ) {
53  continue;
54  }
55  foreach ( $frame['args'] as $arg ) {
56  $this->assertNotInternalType( 'array', $arg );
57  $this->assertNotInternalType( 'object', $arg );
58  }
59  }
61  $this->assertEquals( 'value', $refvar, 'Ensuring reference variable wasn\'t changed' );
62  }
71  protected static function helperThrowAnException( $a, $b, &$c ) {
72  throw new Exception();
73  }
74 }
static helperThrowAnException( $a, $b, &$c)
Helper function for testExpandArgumentsInCall.
Definition: MWExceptionHandlerTest.php:71
static getRedactedTrace( $e)
Return a copy of an exception's backtrace as an array.
Definition: MWExceptionHandler.php:440
Definition: MWExceptionHandlerTest.php:9
Definition: MWExceptionHandlerTest.php:14
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Definition: MediaWikiTestCase.php:17
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2162
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9