feature #15709 [WebProfilerBundle] deprecated import/export commands (fabpot)

This PR was merged into the 2.8 branch.

Discussion
----------

[WebProfilerBundle] deprecated import/export commands

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | part of #11742
| License       | MIT
| Doc PR        | n/a

Commits
-------

943fec9 [HtppKernel] deprecated Profiler::import/export
17e00b9 [WebProfilerBundle] deprecated import/export commands
This commit is contained in:
Fabien Potencier 2015-09-09 23:21:50 +02:00
commit 0383559f95
8 changed files with 66 additions and 4 deletions

View File

@ -325,8 +325,11 @@ DependencyInjection
</services> </services>
``` ```
Web Development Toolbar WebProfiler
----------------------- -----------
The `profiler:import` and `profiler:export` commands have been deprecated and
will be removed in 3.0.
The web development toolbar has been completely redesigned. This update has The web development toolbar has been completely redesigned. This update has
introduced some changes in the HTML markup of the toolbar items. introduced some changes in the HTML markup of the toolbar items.

View File

@ -1,6 +1,11 @@
CHANGELOG CHANGELOG
========= =========
2.8.0
-----
* deprecated profiler:import and profiler:export commands
2.7.0 2.7.0
----- -----

View File

@ -20,6 +20,8 @@ use Symfony\Component\HttpKernel\Profiler\Profiler;
/** /**
* Exports a profile. * Exports a profile.
* *
* @deprecated since version 2.8, to be removed in 3.0.
*
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*/ */
class ExportCommand extends Command class ExportCommand extends Command
@ -49,7 +51,7 @@ class ExportCommand extends Command
{ {
$this $this
->setName('profiler:export') ->setName('profiler:export')
->setDescription('Exports a profile') ->setDescription('[DEPRECATED] Exports a profile')
->setDefinition(array( ->setDefinition(array(
new InputArgument('token', InputArgument::REQUIRED, 'The profile token'), new InputArgument('token', InputArgument::REQUIRED, 'The profile token'),
)) ))
@ -64,6 +66,10 @@ EOF
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$formatter = $this->getHelper('formatter');
$output->writeln($formatter->formatSection('warning', 'The profiler:export command is deprecated since version 2.8 and will be removed in 3.0', 'comment'));
$token = $input->getArgument('token'); $token = $input->getArgument('token');
if (!$profile = $this->profiler->loadProfile($token)) { if (!$profile = $this->profiler->loadProfile($token)) {

View File

@ -20,6 +20,8 @@ use Symfony\Component\HttpKernel\Profiler\Profiler;
/** /**
* Imports a profile. * Imports a profile.
* *
* @deprecated since version 2.8, to be removed in 3.0.
*
* @author Fabien Potencier <fabien@symfony.com> * @author Fabien Potencier <fabien@symfony.com>
*/ */
class ImportCommand extends Command class ImportCommand extends Command
@ -49,7 +51,7 @@ class ImportCommand extends Command
{ {
$this $this
->setName('profiler:import') ->setName('profiler:import')
->setDescription('Imports a profile') ->setDescription('[DEPRECATED] Imports a profile')
->setDefinition(array( ->setDefinition(array(
new InputArgument('filename', InputArgument::OPTIONAL, 'The profile path'), new InputArgument('filename', InputArgument::OPTIONAL, 'The profile path'),
)) ))
@ -68,6 +70,10 @@ EOF
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$formatter = $this->getHelper('formatter');
$output->writeln($formatter->formatSection('warning', 'The profiler:import command is deprecated since version 2.8 and will be removed in 3.0', 'comment'));
$data = ''; $data = '';
if ($input->getArgument('filename')) { if ($input->getArgument('filename')) {
$data = file_get_contents($input->getArgument('filename')); $data = file_get_contents($input->getArgument('filename'));

View File

@ -12,9 +12,13 @@
namespace Symfony\Bundle\WebProfilerBundle\Tests\Command; namespace Symfony\Bundle\WebProfilerBundle\Tests\Command;
use Symfony\Bundle\WebProfilerBundle\Command\ExportCommand; use Symfony\Bundle\WebProfilerBundle\Command\ExportCommand;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\Profiler\Profile; use Symfony\Component\HttpKernel\Profiler\Profile;
/**
* @group legacy
*/
class ExportCommandTest extends \PHPUnit_Framework_TestCase class ExportCommandTest extends \PHPUnit_Framework_TestCase
{ {
/** /**
@ -28,7 +32,14 @@ class ExportCommandTest extends \PHPUnit_Framework_TestCase
->getMock() ->getMock()
; ;
$helperSet = new HelperSet();
$helper = $this->getMock('Symfony\Component\Console\Helper\FormatterHelper');
$helper->expects($this->any())->method('formatSection');
$helperSet->set($helper, 'formatter');
$command = new ExportCommand($profiler); $command = new ExportCommand($profiler);
$command->setHelperSet($helperSet);
$commandTester = new CommandTester($command); $commandTester = new CommandTester($command);
$commandTester->execute(array('token' => 'TOKEN')); $commandTester->execute(array('token' => 'TOKEN'));
} }
@ -44,7 +55,14 @@ class ExportCommandTest extends \PHPUnit_Framework_TestCase
$profile = new Profile('TOKEN'); $profile = new Profile('TOKEN');
$profiler->expects($this->once())->method('loadProfile')->with('TOKEN')->will($this->returnValue($profile)); $profiler->expects($this->once())->method('loadProfile')->with('TOKEN')->will($this->returnValue($profile));
$helperSet = new HelperSet();
$helper = $this->getMock('Symfony\Component\Console\Helper\FormatterHelper');
$helper->expects($this->any())->method('formatSection');
$helperSet->set($helper, 'formatter');
$command = new ExportCommand($profiler); $command = new ExportCommand($profiler);
$command->setHelperSet($helperSet);
$commandTester = new CommandTester($command); $commandTester = new CommandTester($command);
$commandTester->execute(array('token' => 'TOKEN')); $commandTester->execute(array('token' => 'TOKEN'));
$this->assertEquals($profiler->export($profile), $commandTester->getDisplay()); $this->assertEquals($profiler->export($profile), $commandTester->getDisplay());

View File

@ -12,9 +12,13 @@
namespace Symfony\Bundle\WebProfilerBundle\Tests\Command; namespace Symfony\Bundle\WebProfilerBundle\Tests\Command;
use Symfony\Bundle\WebProfilerBundle\Command\ImportCommand; use Symfony\Bundle\WebProfilerBundle\Command\ImportCommand;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\Profiler\Profile; use Symfony\Component\HttpKernel\Profiler\Profile;
/**
* @group legacy
*/
class ImportCommandTest extends \PHPUnit_Framework_TestCase class ImportCommandTest extends \PHPUnit_Framework_TestCase
{ {
public function testExecute() public function testExecute()
@ -27,7 +31,14 @@ class ImportCommandTest extends \PHPUnit_Framework_TestCase
$profiler->expects($this->once())->method('import')->will($this->returnValue(new Profile('TOKEN'))); $profiler->expects($this->once())->method('import')->will($this->returnValue(new Profile('TOKEN')));
$helperSet = new HelperSet();
$helper = $this->getMock('Symfony\Component\Console\Helper\FormatterHelper');
$helper->expects($this->any())->method('formatSection');
$helperSet->set($helper, 'formatter');
$command = new ImportCommand($profiler); $command = new ImportCommand($profiler);
$command->setHelperSet($helperSet);
$commandTester = new CommandTester($command); $commandTester = new CommandTester($command);
$commandTester->execute(array('filename' => __DIR__.'/../Fixtures/profile.data')); $commandTester->execute(array('filename' => __DIR__.'/../Fixtures/profile.data'));
$this->assertRegExp('/Profile "TOKEN" has been successfully imported\./', $commandTester->getDisplay()); $this->assertRegExp('/Profile "TOKEN" has been successfully imported\./', $commandTester->getDisplay());

View File

@ -1,6 +1,11 @@
CHANGELOG CHANGELOG
========= =========
2.8.0
-----
* deprecated `Profiler::import` and `Profiler::export`
2.7.0 2.7.0
----- -----

View File

@ -137,9 +137,13 @@ class Profiler
* @param Profile $profile A Profile instance * @param Profile $profile A Profile instance
* *
* @return string The exported data * @return string The exported data
*
* @deprecated since Symfony 2.8, to be removed in 3.0.
*/ */
public function export(Profile $profile) public function export(Profile $profile)
{ {
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
return base64_encode(serialize($profile)); return base64_encode(serialize($profile));
} }
@ -149,9 +153,13 @@ class Profiler
* @param string $data A data string as exported by the export() method * @param string $data A data string as exported by the export() method
* *
* @return Profile A Profile instance * @return Profile A Profile instance
*
* @deprecated since Symfony 2.8, to be removed in 3.0.
*/ */
public function import($data) public function import($data)
{ {
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
$profile = unserialize(base64_decode($data)); $profile = unserialize(base64_decode($data));
if ($this->storage->read($profile->getToken())) { if ($this->storage->read($profile->getToken())) {