Debian Codegraph @

tests/phpunit/integration/includes/MediaWikiEntryPointTest.php

raw symbols SCIP
1 <?php
2 namespace MediaWiki\Tests;
3
4 use MediaWiki\Context\RequestContext;
5 use MediaWiki\MediaWikiEntryPoint;
6 use MediaWiki\MediaWikiServices;
7 use MediaWiki\Request\FauxRequest;
8 use MediaWikiIntegrationTestCase;
9 use Wikimedia\TestingAccessWrapper;
10
11 /**
12 * @covers \MediaWiki\MediaWikiEntryPoint
13 */
14 class MediaWikiEntryPointTest extends MediaWikiIntegrationTestCase {
15
16 private function newEntryPoint(): MediaWikiEntryPoint {
17 $context = new RequestContext();
18 $context->setRequest( new FauxRequest() );
19 $environment = new MockEnvironment();
20 $services = $this->createMock( MediaWikiServices::class );
21
22 $mw = $this->getMockBuilder( MediaWikiEntryPoint::class )
23 ->onlyMethods( [ 'execute' ] )
24 ->setConstructorArgs( [ $context, $environment, $services ] )
25 ->getMockForAbstractClass();
26
27 return $mw;
28 }
29
30 /**
31 * Assert that we can create, flush, and access output buffers.
32 *
33 * Note that can't test the behaviour for non-removable buffers,
34 * because then we are stuck with a non-removable buffer,
35 * and PHPUnit will choke on it.
36 *
37 * We also can't test that content gets send to the client by calling
38 * flush(), since we can't mock that function, and we can't capture
39 * its output.
40 */
41 public function testOutputBuffer() {
42 $oldLevel = ob_get_level();
43
44 $mw = TestingAccessWrapper::newFromObject( $this->newEntryPoint() );
45 $mw->enableOutputCapture();
46
47 $mw->startOutputBuffer();
48 $this->assertSame( 1, $mw->getOutputBufferLevel(), 'getOutputBufferLevel' );
49
50 print 'Testing test';
51 $this->assertSame( 12, $mw->getOutputBufferLength(), 'getOutputBufferLength' );
52
53 $mw->flushOutputBuffer();
54
55 $this->assertSame( $oldLevel, ob_get_level(), 'ob_get_level' );
56 $this->assertSame( 'Testing test', $mw->drainOutputBuffer() );
57 }
58
59 /**
60 * Check that flushOutputBuffer() will not try to send output
61 * when in post-send mode.
62 */
63 public function testFlushOutputBuffers_sent() {
64 $mw = TestingAccessWrapper::newFromObject( $this->newEntryPoint() );
65 $mw->enableOutputCapture();
66
67 ob_start( null, 0, PHP_OUTPUT_HANDLER_STDFLAGS & ~PHP_OUTPUT_HANDLER_FLUSHABLE );
68 print 'Testing test';
69
70 $mw->enterPostSendMode();
71
72 $this->expectPHPError(
73 E_USER_NOTICE,
74 static function () use ( $mw ) {
75 $mw->flushOutputBuffer();
76 }
77 );
78
79 $this->assertSame( '', $mw->drainOutputBuffer() );
80 }
81
82 }