Add test for ThrottledError exception
authoraddshore <addshorewiki@gmail.com>
Tue, 25 Feb 2014 19:07:06 +0000 (20:07 +0100)
committeraddshore <addshorewiki@gmail.com>
Tue, 25 Feb 2014 21:35:06 +0000 (22:35 +0100)
Change-Id: Ia98d6c24ce56c6707a67498e26107250d427a3bf

tests/phpunit/includes/exception/ThrottledErrorTest.php [new file with mode: 0644]

diff --git a/tests/phpunit/includes/exception/ThrottledErrorTest.php b/tests/phpunit/includes/exception/ThrottledErrorTest.php
new file mode 100644 (file)
index 0000000..ca67241
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * @covers ThrottledError
+ * @author Adam Shorland
+ */
+class ThrottledErrorTest extends MediaWikiTestCase {
+
+       protected $wgOut;
+
+       protected function setUp() {
+               parent::setUp();
+               global $wgOut;
+               $this->wgOut = clone $wgOut;
+       }
+
+       protected function tearDown() {
+               parent::tearDown();
+               global $wgOut;
+               $wgOut = $this->wgOut;
+       }
+
+       public function testExceptionSetsStatusCode() {
+               global $wgOut;
+               $wgOut = $this->getMockWgOut();
+               try{
+                       throw new ThrottledError();
+               }
+               catch( ThrottledError $e ) {
+                       $e->report();
+                       $this->assertTrue( true );
+               }
+       }
+
+       private function getMockWgOut() {
+               $mock = $this->getMockBuilder( 'OutputPage' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+               $mock->expects( $this->once() )
+                       ->method( 'setStatusCode' )
+                       ->with( 503 );
+               return $mock;
+       }
+
+}