|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
| 4 | + * |
| 5 | + * Copyright (C) 2019 - 2024 Jan Böhmer (https://github.com/jbtronics) |
| 6 | + * |
| 7 | + * This program is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU Affero General Public License as published |
| 9 | + * by the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU Affero General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Affero General Public License |
| 18 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +namespace App\Tests\Exceptions; |
| 22 | + |
| 23 | +use App\Exceptions\TwigModeException; |
| 24 | +use PHPUnit\Framework\TestCase; |
| 25 | +use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
| 26 | +use Twig\Error\Error; |
| 27 | + |
| 28 | +class TwigModeExceptionTest extends KernelTestCase |
| 29 | +{ |
| 30 | + |
| 31 | + private string $projectPath; |
| 32 | + |
| 33 | + public function setUp(): void |
| 34 | + { |
| 35 | + self::bootKernel(); |
| 36 | + |
| 37 | + $this->projectPath = self::getContainer()->getParameter('kernel.project_dir'); |
| 38 | + } |
| 39 | + |
| 40 | + public function testGetSafeMessage(): void |
| 41 | + { |
| 42 | + $testException = new Error("Error at : " . $this->projectPath . "/src/dir/path/file.php"); |
| 43 | + |
| 44 | + $twigModeException = new TwigModeException($testException); |
| 45 | + |
| 46 | + $this->assertSame("Error at : " . $this->projectPath . "/src/dir/path/file.php", $testException->getMessage()); |
| 47 | + $this->assertSame("Error at : [Part-DB Root Folder]/src/dir/path/file.php", $twigModeException->getSafeMessage()); |
| 48 | + } |
| 49 | +} |
0 commit comments