|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bundle\FrameworkBundle\Tests\Command; |
| 13 | + |
| 14 | +use Symfony\Bundle\FrameworkBundle\Command\DebugDeprecationsWarmedCommand; |
| 15 | +use Symfony\Bundle\FrameworkBundle\Tests\TestCase; |
| 16 | +use Symfony\Component\Console\Application; |
| 17 | +use Symfony\Component\Console\Tester\CommandTester; |
| 18 | + |
| 19 | +class DebugDeprecationsWarmedCommandTest extends TestCase |
| 20 | +{ |
| 21 | + public function testGetDeprecation() |
| 22 | + { |
| 23 | + $path = tempnam(sys_get_temp_dir(), 'sf'); |
| 24 | + touch($path); |
| 25 | + file_put_contents($path, 'a:2:{i:0;a:6:{s:4:"type";i:16384;s:7:"message";s:171:"The "Symfony\Bundle\FrameworkBundle\Controller\Controller" class is deprecated since Symfony 4.2, use Symfony\Bundle\FrameworkBundle\Controller\AbstractController instead.";s:4:"file";s:87:"/home/hamza/projet/contrib/sf/vendor/symfony/framework-bundle/Controller/Controller.php";s:4:"line";i:17;s:5:"trace";a:1:{i:0;a:3:{s:4:"file";s:66:"/home/hamza/projet/contrib/sf/src/Controller/DefaultController.php";s:4:"line";i:9;s:8:"function";s:17:"spl_autoload_call";}}s:5:"count";i:1;}i:1;a:6:{s:4:"type";i:16384;s:7:"message";s:188:"The "App\Controller\DefaultController" class extends "Symfony\Bundle\FrameworkBundle\Controller\Controller" that is deprecated since Symfony 4.2, use {@see AbstractController} instead. |
| 26 | + *.";s:4:"file";s:71:"/home/hamza/projet/contrib/sf/vendor/symfony/debug/DebugClassLoader.php";s:4:"line";i:191;s:5:"trace";a:1:{i:0;a:1:{s:8:"function";s:17:"spl_autoload_call";}}s:5:"count";i:1;}}'); |
| 27 | + |
| 28 | + /** @var CommandTester $tester */ |
| 29 | + $tester = $this->getCommandTester($path); |
| 30 | + $tester->execute([]); |
| 31 | + |
| 32 | + $this->assertSame(0, $tester->getStatusCode()); |
| 33 | + $this->assertContains('Symfony\Bundle\FrameworkBundle\Controller\Controller', $tester->getDisplay()); |
| 34 | + $this->assertContains('/home/hamza/projet/contrib/sf/vendor/symfony/framework-bundle/Controller/Controller.php', $tester->getDisplay()); |
| 35 | + } |
| 36 | + |
| 37 | + public function testGetDeprecationNone() |
| 38 | + { |
| 39 | + $path = tempnam(sys_get_temp_dir(), 'sf'); |
| 40 | + touch($path); |
| 41 | + file_put_contents($path, 'a:0:{}'); |
| 42 | + |
| 43 | + /** @var CommandTester $tester */ |
| 44 | + $tester = $this->getCommandTester($path); |
| 45 | + $tester->execute([]); |
| 46 | + |
| 47 | + $this->assertSame(0, $tester->getStatusCode()); |
| 48 | + $this->assertContains('[OK] There are no deprecations in the logs!', $tester->getDisplay()); |
| 49 | + } |
| 50 | + |
| 51 | + public function testGetDeprecationNoFile(): void |
| 52 | + { |
| 53 | + $tester = $this->getCommandTester('notexist'); |
| 54 | + $tester->execute([]); |
| 55 | + |
| 56 | + $this->assertSame(0, $tester->getStatusCode()); |
| 57 | + $this->assertContains('[WARNING] The deprecation file does not exist', $tester->getDisplay()); |
| 58 | + } |
| 59 | + |
| 60 | + private function getCommandTester($path): CommandTester |
| 61 | + { |
| 62 | + $command = new DebugDeprecationsWarmedCommand($path); |
| 63 | + $application = new Application(); |
| 64 | + $application->add($command); |
| 65 | + |
| 66 | + return new CommandTester($application->get('debug:deprecations:warmed')); |
| 67 | + } |
| 68 | +} |
0 commit comments