|
| 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; |
| 16 | + |
| 17 | +use Cake\Event\Event; |
| 18 | +use Cake\Event\EventManager; |
| 19 | +use Cake\TestSuite\TestCase; |
| 20 | +use DebugKit\Panel\DeprecationsPanel; |
| 21 | +use DebugKit\Plugin; |
| 22 | +use DebugKit\ToolbarService; |
| 23 | + |
| 24 | +/** |
| 25 | + * Test the Plugin |
| 26 | + */ |
| 27 | +class PluginTest extends TestCase |
| 28 | +{ |
| 29 | + /** |
| 30 | + * Test setDeprecationHandler. |
| 31 | + * |
| 32 | + * @return void |
| 33 | + */ |
| 34 | + public function testSetDeprecationHandler() |
| 35 | + { |
| 36 | + DeprecationsPanel::clearDeprecatedErrors(); |
| 37 | + $service = new ToolbarService(new EventManager(), []); |
| 38 | + $plugin = new Plugin(); |
| 39 | + $plugin->setDeprecationHandler($service); |
| 40 | + $event = new Event(''); |
| 41 | + $panel = new DeprecationsPanel(); |
| 42 | + |
| 43 | + //Without setting the $stackFrame |
| 44 | + deprecationWarning('setDeprecationHandler'); |
| 45 | + //Setting the $stackFrame |
| 46 | + deprecationWarning('setDeprecationHandler_2', 2); |
| 47 | + //Raw error |
| 48 | + $line = __LINE__ + 1; |
| 49 | + trigger_error('raw_error', E_USER_DEPRECATED); |
| 50 | + |
| 51 | + $panel->shutdown($event); |
| 52 | + $data = $panel->data()['plugins']['DebugKit']; |
| 53 | + |
| 54 | + $this->assertCount(3, $data); |
| 55 | + |
| 56 | + //test first two deprecationWarning() |
| 57 | + foreach ([$data[0], $data[1]] as $value) { |
| 58 | + $this->assertStringContainsString($value['file'], $value['message']); |
| 59 | + $this->assertStringContainsString("line: {$value['line']}", $value['message']); |
| 60 | + } |
| 61 | + //test raw error |
| 62 | + $this->assertSame($line, $data[2]['line']); |
| 63 | + } |
| 64 | +} |
0 commit comments