MediaWiki  1.30.2
TimingTest.php
Go to the documentation of this file.
1 <?php
22 class TimingTest extends PHPUnit_Framework_TestCase {
23 
28  public function testClearMarks() {
29  $timing = new Timing;
30  $this->assertCount( 1, $timing->getEntries() );
31 
32  $timing->mark( 'a' );
33  $timing->mark( 'b' );
34  $this->assertCount( 3, $timing->getEntries() );
35 
36  $timing->clearMarks( 'a' );
37  $this->assertNull( $timing->getEntryByName( 'a' ) );
38  $this->assertNotNull( $timing->getEntryByName( 'b' ) );
39 
40  $timing->clearMarks();
41  $this->assertCount( 1, $timing->getEntries() );
42  }
43 
48  public function testMark() {
49  $timing = new Timing;
50  $timing->mark( 'a' );
51 
52  $entry = $timing->getEntryByName( 'a' );
53  $this->assertEquals( 'a', $entry['name'] );
54  $this->assertEquals( 'mark', $entry['entryType'] );
55  $this->assertArrayHasKey( 'startTime', $entry );
56  $this->assertEquals( 0, $entry['duration'] );
57 
58  usleep( 100 );
59  $timing->mark( 'a' );
60  $newEntry = $timing->getEntryByName( 'a' );
61  $this->assertGreaterThan( $entry['startTime'], $newEntry['startTime'] );
62  }
63 
67  public function testMeasure() {
68  $timing = new Timing;
69 
70  $timing->mark( 'a' );
71  usleep( 100 );
72  $timing->mark( 'b' );
73 
74  $a = $timing->getEntryByName( 'a' );
75  $b = $timing->getEntryByName( 'b' );
76 
77  $timing->measure( 'a_to_b', 'a', 'b' );
78 
79  $entry = $timing->getEntryByName( 'a_to_b' );
80  $this->assertEquals( 'a_to_b', $entry['name'] );
81  $this->assertEquals( 'measure', $entry['entryType'] );
82  $this->assertEquals( $a['startTime'], $entry['startTime'] );
83  $this->assertEquals( $b['startTime'] - $a['startTime'], $entry['duration'] );
84  }
85 
89  public function testGetEntriesByType() {
90  $timing = new Timing;
91 
92  $timing->mark( 'mark_a' );
93  usleep( 100 );
94  $timing->mark( 'mark_b' );
95  usleep( 100 );
96  $timing->mark( 'mark_c' );
97 
98  $timing->measure( 'measure_a', 'mark_a', 'mark_b' );
99  $timing->measure( 'measure_b', 'mark_b', 'mark_c' );
100 
101  $marks = array_map( function ( $entry ) {
102  return $entry['name'];
103  }, $timing->getEntriesByType( 'mark' ) );
104 
105  $this->assertEquals( [ 'requestStart', 'mark_a', 'mark_b', 'mark_c' ], $marks );
106 
107  $measures = array_map( function ( $entry ) {
108  return $entry['name'];
109  }, $timing->getEntriesByType( 'measure' ) );
110 
111  $this->assertEquals( [ 'measure_a', 'measure_b' ], $measures );
112  }
113 }
Timing\mark
mark( $markName)
Store a timestamp with the associated name (a "mark")
Definition: Timing.php:75
php
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
TimingTest
Definition: TimingTest.php:22
TimingTest\testMark
testMark()
Timing::mark Timing::getEntryByName.
Definition: TimingTest.php:48
Timing
An interface to help developers measure the performance of their applications.
Definition: Timing.php:45
TimingTest\testClearMarks
testClearMarks()
Timing::clearMarks Timing::getEntries.
Definition: TimingTest.php:28
TimingTest\testGetEntriesByType
testGetEntriesByType()
Timing::getEntriesByType.
Definition: TimingTest.php:89
TimingTest\testMeasure
testMeasure()
Timing::measure.
Definition: TimingTest.php:67