Skip to content

Commit

Permalink
Add deprecations in Console package.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 25, 2017
1 parent c557070 commit b368474
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 38 deletions.
1 change: 1 addition & 0 deletions src/Console/ConsoleIo.php
Expand Up @@ -372,6 +372,7 @@ public function setOutputAs($mode)
*/
public function outputAs($mode)
{
deprecationWarning('ConsoleIo::outputAs() is deprecated. Use ConsoleIo::setOutputAs() instead.');
$this->_out->setOutputAs($mode);
}

Expand Down
16 changes: 16 additions & 0 deletions src/Console/ConsoleOptionParser.php
Expand Up @@ -310,6 +310,10 @@ public function getCommand()
*/
public function command($text = null)
{
deprecationWarning(
'ConsoleOptionParser::command() is deprecated. ' .
'Use ConsoleOptionParser::setCommand()/getCommand() instead.'
);
if ($text !== null) {
return $this->setCommand($text);
}
Expand Down Expand Up @@ -354,6 +358,10 @@ public function getDescription()
*/
public function description($text = null)
{
deprecationWarning(
'ConsoleOptionParser::description() is deprecated. ' .
'Use ConsoleOptionParser::setDescription()/getDescription() instead.'
);
if ($text !== null) {
return $this->setDescription($text);
}
Expand Down Expand Up @@ -400,6 +408,10 @@ public function getEpilog()
*/
public function epilog($text = null)
{
deprecationWarning(
'ConsoleOptionParser::epliog() is deprecated. ' .
'Use ConsoleOptionParser::setEpilog()/getEpilog() instead.'
);
if ($text !== null) {
return $this->setEpilog($text);
}
Expand Down Expand Up @@ -785,6 +797,10 @@ public function help($subcommand = null, $format = 'text', $width = 72)
*/
public function setHelpAlias($alias)
{
deprecationWarning(
'ConsoleOptionParser::setHelpAlias() is deprecated. ' .
'Use ConsoleOptionParser::setRootName() instead.'
);
$this->rootName = $alias;
}

Expand Down
4 changes: 4 additions & 0 deletions src/Console/ConsoleOutput.php
Expand Up @@ -339,6 +339,10 @@ public function setOutputAs($type)
*/
public function outputAs($type = null)
{
deprecationWarning(
'ConsoleOutput::outputAs() is deprecated. ' .
'Use ConsoleOutput::setOutputAs()/getOutputAs() instead.'
);
if ($type === null) {
return $this->_outputAs;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Console/Shell.php
Expand Up @@ -243,6 +243,10 @@ public function setIo(ConsoleIo $io)
*/
public function io(ConsoleIo $io = null)
{
deprecationWarning(
'Shell::io() is deprecated. ' .
'Use Shell::setIo()/getIo() instead.'
);
if ($io !== null) {
$this->_io = $io;
}
Expand Down Expand Up @@ -783,6 +787,10 @@ public function success($message = null, $newlines = 1, $level = Shell::NORMAL)
*/
protected function wrapMessageWithType($messageType, $message)
{
deprecationWarning(
'Shell::wrapMessageWithType() is deprecated. ' .
'Use output methods on ConsoleIo instead.'
);
if (is_array($message)) {
foreach ($message as $k => $v) {
$message[$k] = "<$messageType>" . $v . "</$messageType>";
Expand Down Expand Up @@ -849,6 +857,7 @@ public function abort($message, $exitCode = self::CODE_ERROR)
*/
public function error($title, $message = null, $exitCode = self::CODE_ERROR)
{
deprecationWarning('Shell::error() is deprecated. `Use Shell::abort() instead.');
$this->_io->err(sprintf('<error>Error:</error> %s', $title));

if (!empty($message)) {
Expand Down
60 changes: 47 additions & 13 deletions tests/TestCase/Console/ConsoleOptionParserTest.php
Expand Up @@ -26,6 +26,23 @@
class ConsoleOptionParserTest extends TestCase
{

/**
* test setting the console description
*
* @group deprecated
* @return void
*/
public function testDescriptionDeprecated()
{
$this->deprecated(function() {
$parser = new ConsoleOptionParser('test', false);
$result = $parser->description('A test');

$this->assertEquals($parser, $result, 'Setting description is not chainable');
$this->assertEquals('A test', $parser->description(), 'getting value is wrong.');
});
}

/**
* test setting the console description
*
Expand All @@ -34,13 +51,30 @@ class ConsoleOptionParserTest extends TestCase
public function testDescription()
{
$parser = new ConsoleOptionParser('test', false);
$result = $parser->description('A test');
$result = $parser->setDescription('A test');

$this->assertEquals($parser, $result, 'Setting description is not chainable');
$this->assertEquals('A test', $parser->description(), 'getting value is wrong.');
$this->assertEquals('A test', $parser->getDescription(), 'getting value is wrong.');

$result = $parser->setDescription(['A test', 'something']);
$this->assertEquals("A test\nsomething", $parser->getDescription(), 'getting value is wrong.');
}

/**
* test setting the console description
*
* @group deprecated
* @return void
*/
public function testEplilogDeprecated()
{
$this->deprecated(function() {
$parser = new ConsoleOptionParser('test', false);
$result = $parser->epilog('A test');

$result = $parser->description(['A test', 'something']);
$this->assertEquals("A test\nsomething", $parser->description(), 'getting value is wrong.');
$this->assertEquals($parser, $result, 'Setting epilog is not chainable');
$this->assertEquals('A test', $parser->epilog(), 'getting value is wrong.');
});
}

/**
Expand All @@ -51,13 +85,13 @@ public function testDescription()
public function testEpilog()
{
$parser = new ConsoleOptionParser('test', false);
$result = $parser->epilog('A test');
$result = $parser->setEpilog('A test');

$this->assertEquals($parser, $result, 'Setting epilog is not chainable');
$this->assertEquals('A test', $parser->epilog(), 'getting value is wrong.');
$this->assertEquals('A test', $parser->getEpilog(), 'getting value is wrong.');

$result = $parser->epilog(['A test', 'something']);
$this->assertEquals("A test\nsomething", $parser->epilog(), 'getting value is wrong.');
$result = $parser->setEpilog(['A test', 'something']);
$this->assertEquals("A test\nsomething", $parser->getEpilog(), 'getting value is wrong.');
}

/**
Expand Down Expand Up @@ -789,7 +823,7 @@ public function testHelpSubcommandHelpArray()
public function testHelpWithRootName()
{
$parser = new ConsoleOptionParser('sample', false);
$parser->description('A command!')
$parser->setDescription('A command!')
->setRootName('tool')
->addOption('test', ['help' => 'A test option.']);

Expand Down Expand Up @@ -874,8 +908,8 @@ public function testBuildFromArray()
];
$parser = ConsoleOptionParser::buildFromArray($spec);

$this->assertEquals($spec['description'], $parser->description());
$this->assertEquals($spec['epilog'], $parser->epilog());
$this->assertEquals($spec['description'], $parser->getDescription());
$this->assertEquals($spec['epilog'], $parser->getEpilog());

$options = $parser->options();
$this->assertTrue(isset($options['name']));
Expand All @@ -897,7 +931,7 @@ public function testCreateFactory()
{
$parser = ConsoleOptionParser::create('factory', false);
$this->assertInstanceOf('Cake\Console\ConsoleOptionParser', $parser);
$this->assertEquals('factory', $parser->command());
$this->assertEquals('factory', $parser->getCommand());
}

/**
Expand All @@ -908,7 +942,7 @@ public function testCreateFactory()
public function testCommandInflection()
{
$parser = new ConsoleOptionParser('CommandLine');
$this->assertEquals('command_line', $parser->command());
$this->assertEquals('command_line', $parser->getCommand());
}

/**
Expand Down
34 changes: 26 additions & 8 deletions tests/TestCase/Console/ConsoleOutputTest.php
Expand Up @@ -36,7 +36,7 @@ public function setUp()
$this->output = $this->getMockBuilder('Cake\Console\ConsoleOutput')
->setMethods(['_write'])
->getMock();
$this->output->outputAs(ConsoleOutput::COLOR);
$this->output->setOutputAs(ConsoleOutput::COLOR);
}

/**
Expand Down Expand Up @@ -221,14 +221,32 @@ public function testFormattingMultipleSameTags()
$this->output->write('<error>Bad</error> <error>Warning</error> Regular', false);
}

/**
* test deprecated outputAs
*
* @group deprecated
* @return void
*/
public function testOutputAsPlain()
{
$this->deprecated(function() {
$this->output->outputAs(ConsoleOutput::PLAIN);
$this->assertSame(ConsoleOutput::PLAIN, $this->output->outputAs());
$this->output->expects($this->once())->method('_write')
->with('Bad Regular');

$this->output->write('<error>Bad</error> Regular', false);
});
}

/**
* test raw output not getting tags replaced.
*
* @return void
*/
public function testOutputAsRaw()
public function testSetOutputAsRaw()
{
$this->output->outputAs(ConsoleOutput::RAW);
$this->output->setOutputAs(ConsoleOutput::RAW);
$this->output->expects($this->once())->method('_write')
->with('<error>Bad</error> Regular');

Expand All @@ -240,9 +258,9 @@ public function testOutputAsRaw()
*
* @return void
*/
public function testOutputAsPlain()
public function testSetOutputAsPlain()
{
$this->output->outputAs(ConsoleOutput::PLAIN);
$this->output->setOutputAs(ConsoleOutput::PLAIN);
$this->output->expects($this->once())->method('_write')
->with('Bad Regular');

Expand All @@ -254,7 +272,7 @@ public function testOutputAsPlain()
*
* @return void
*/
public function testSetOutputAsPlain()
public function testSetSetOutputAsPlain()
{
$this->output->setOutputAs(ConsoleOutput::PLAIN);
$this->output->expects($this->once())->method('_write')
Expand All @@ -279,9 +297,9 @@ public function testSetOutputWrongType()
*
* @return void
*/
public function testOutputAsPlainSelectiveTagRemoval()
public function testSetOutputAsPlainSelectiveTagRemoval()
{
$this->output->outputAs(ConsoleOutput::PLAIN);
$this->output->setOutputAs(ConsoleOutput::PLAIN);
$this->output->expects($this->once())->method('_write')
->with('Bad Regular <b>Left</b> <i>behind</i> <name>');

Expand Down
10 changes: 5 additions & 5 deletions tests/TestCase/Console/HelpFormatterTest.php
Expand Up @@ -34,7 +34,7 @@ class HelpFormatterTest extends TestCase
public function testWidthFormatting()
{
$parser = new ConsoleOptionParser('test', false);
$parser->description('This is fifteen This is fifteen This is fifteen')
$parser->setDescription('This is fifteen This is fifteen This is fifteen')
->addOption('four', ['help' => 'this is help text this is help text'])
->addArgument('four', ['help' => 'this is help text this is help text'])
->addSubcommand('four', ['help' => 'this is help text this is help text']);
Expand Down Expand Up @@ -115,8 +115,8 @@ public function testHelpWithChoices()
public function testHelpDescriptionAndEpilog()
{
$parser = new ConsoleOptionParser('mycommand', false);
$parser->description('Description text')
->epilog('epilog text')
$parser->setDescription('Description text')
->setEpilog('epilog text')
->addOption('test', ['help' => 'A test option.'])
->addArgument('model', ['help' => 'The model to make.', 'required' => true]);

Expand Down Expand Up @@ -384,8 +384,8 @@ public function testXmlHelpWithChoices()
public function testXmlHelpDescriptionAndEpilog()
{
$parser = new ConsoleOptionParser('mycommand', false);
$parser->description('Description text')
->epilog('epilog text')
$parser->setDescription('Description text')
->setEpilog('epilog text')
->addOption('test', ['help' => 'A test option.'])
->addArgument('model', ['help' => 'The model to make.', 'required' => true]);

Expand Down

0 comments on commit b368474

Please sign in to comment.