|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +/** |
| 5 | + * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) |
| 6 | + * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) |
| 7 | + * |
| 8 | + * Licensed under The MIT License |
| 9 | + * Redistributions of files must retain the above copyright notice. |
| 10 | + * |
| 11 | + * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) |
| 12 | + * @link http://cakephp.org CakePHP(tm) Project |
| 13 | + * @license http://www.opensource.org/licenses/mit-license.php MIT License |
| 14 | + **/ |
| 15 | +namespace DebugKit\Test\TestCase\Panel; |
| 16 | + |
| 17 | +use Cake\Controller\Controller; |
| 18 | +use Cake\Event\Event; |
| 19 | +use Cake\Http\ServerRequest; |
| 20 | +use Cake\TestSuite\TestCase; |
| 21 | +use DebugKit\Panel\RequestPanel; |
| 22 | + |
| 23 | +/** |
| 24 | + * Class RequestPanelTest |
| 25 | + */ |
| 26 | +class RequestPanelTest extends TestCase |
| 27 | +{ |
| 28 | + /** |
| 29 | + * @var RequestPanel |
| 30 | + */ |
| 31 | + protected $panel; |
| 32 | + |
| 33 | + /** |
| 34 | + * set up |
| 35 | + * |
| 36 | + * @return void |
| 37 | + */ |
| 38 | + public function setUp(): void |
| 39 | + { |
| 40 | + parent::setUp(); |
| 41 | + $this->panel = new RequestPanel(); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Test that shutdown will skip unserializable attributes. |
| 46 | + * |
| 47 | + * @return void |
| 48 | + */ |
| 49 | + public function testShutdownSkipAttributes() |
| 50 | + { |
| 51 | + $request = new ServerRequest([ |
| 52 | + 'url' => '/', |
| 53 | + 'post' => ['name' => 'bob'], |
| 54 | + 'query' => ['page' => 1], |
| 55 | + ]); |
| 56 | + $request = $request |
| 57 | + ->withAttribute('ok', 'string') |
| 58 | + ->withAttribute('closure', function () { |
| 59 | + }); |
| 60 | + |
| 61 | + $controller = new Controller($request); |
| 62 | + $event = new Event('Controller.shutdown', $controller); |
| 63 | + $this->panel->shutdown($event); |
| 64 | + |
| 65 | + $data = $this->panel->data(); |
| 66 | + $this->assertArrayHasKey('attributes', $data); |
| 67 | + $this->assertEquals('string', $data['attributes']['ok']); |
| 68 | + $this->assertStringContainsString('Could not serialize `closure`', $data['attributes']['closure']); |
| 69 | + } |
| 70 | +} |
0 commit comments