| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Tests\Rest; |
| 4 | |
| 5 | use MediaWiki\Rest\Handler; |
| 6 | use MediaWiki\Rest\HttpException; |
| 7 | use MediaWiki\Rest\RedirectException; |
| 8 | use MediaWiki\Rest\ResponseException; |
| 9 | use RuntimeException; |
| 10 | |
| 11 | class MockHandlerFactory { |
| 12 | |
| 13 | public static function throwHandlerFactory() { |
| 14 | return new class extends Handler { |
| 15 | public function execute() { |
| 16 | throw new HttpException( 'Mock error', 555 ); |
| 17 | } |
| 18 | }; |
| 19 | } |
| 20 | |
| 21 | public static function fatalHandlerFactory() { |
| 22 | return new class extends Handler { |
| 23 | public function execute() { |
| 24 | throw new RuntimeException( 'Fatal mock error', 12345 ); |
| 25 | } |
| 26 | }; |
| 27 | } |
| 28 | |
| 29 | public static function throwRedirectHandlerFactory() { |
| 30 | return new class extends Handler { |
| 31 | public function execute() { |
| 32 | throw new RedirectException( 301, 'http://example.com' ); |
| 33 | } |
| 34 | }; |
| 35 | } |
| 36 | |
| 37 | public static function throwWrappedHandlerFactory() { |
| 38 | return new class extends Handler { |
| 39 | public function execute() { |
| 40 | $response = $this->getResponseFactory()->create(); |
| 41 | $response->setStatus( 200 ); |
| 42 | throw new ResponseException( $response ); |
| 43 | } |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | } |