Browse Source

Add deprecations in Console package.

Mark Story 8 years ago
parent
commit
b368474241

+ 1 - 0
src/Console/ConsoleIo.php

@@ -372,6 +372,7 @@ class ConsoleIo
      */
      */
     public function outputAs($mode)
     public function outputAs($mode)
     {
     {
+        deprecationWarning('ConsoleIo::outputAs() is deprecated. Use ConsoleIo::setOutputAs() instead.');
         $this->_out->setOutputAs($mode);
         $this->_out->setOutputAs($mode);
     }
     }
 
 

+ 16 - 0
src/Console/ConsoleOptionParser.php

@@ -310,6 +310,10 @@ class ConsoleOptionParser
      */
      */
     public function command($text = null)
     public function command($text = null)
     {
     {
+        deprecationWarning(
+            'ConsoleOptionParser::command() is deprecated. ' .
+            'Use ConsoleOptionParser::setCommand()/getCommand() instead.'
+        );
         if ($text !== null) {
         if ($text !== null) {
             return $this->setCommand($text);
             return $this->setCommand($text);
         }
         }
@@ -354,6 +358,10 @@ class ConsoleOptionParser
      */
      */
     public function description($text = null)
     public function description($text = null)
     {
     {
+        deprecationWarning(
+            'ConsoleOptionParser::description() is deprecated. ' .
+            'Use ConsoleOptionParser::setDescription()/getDescription() instead.'
+        );
         if ($text !== null) {
         if ($text !== null) {
             return $this->setDescription($text);
             return $this->setDescription($text);
         }
         }
@@ -400,6 +408,10 @@ class ConsoleOptionParser
      */
      */
     public function epilog($text = null)
     public function epilog($text = null)
     {
     {
+        deprecationWarning(
+            'ConsoleOptionParser::epliog() is deprecated. ' .
+            'Use ConsoleOptionParser::setEpilog()/getEpilog() instead.'
+        );
         if ($text !== null) {
         if ($text !== null) {
             return $this->setEpilog($text);
             return $this->setEpilog($text);
         }
         }
@@ -785,6 +797,10 @@ class ConsoleOptionParser
      */
      */
     public function setHelpAlias($alias)
     public function setHelpAlias($alias)
     {
     {
+        deprecationWarning(
+            'ConsoleOptionParser::setHelpAlias() is deprecated. ' .
+            'Use ConsoleOptionParser::setRootName() instead.'
+        );
         $this->rootName = $alias;
         $this->rootName = $alias;
     }
     }
 
 

+ 4 - 0
src/Console/ConsoleOutput.php

@@ -339,6 +339,10 @@ class ConsoleOutput
      */
      */
     public function outputAs($type = null)
     public function outputAs($type = null)
     {
     {
+        deprecationWarning(
+            'ConsoleOutput::outputAs() is deprecated. ' .
+            'Use ConsoleOutput::setOutputAs()/getOutputAs() instead.'
+        );
         if ($type === null) {
         if ($type === null) {
             return $this->_outputAs;
             return $this->_outputAs;
         }
         }

+ 9 - 0
src/Console/Shell.php

@@ -243,6 +243,10 @@ class Shell
      */
      */
     public function io(ConsoleIo $io = null)
     public function io(ConsoleIo $io = null)
     {
     {
+        deprecationWarning(
+            'Shell::io() is deprecated. ' .
+            'Use Shell::setIo()/getIo() instead.'
+        );
         if ($io !== null) {
         if ($io !== null) {
             $this->_io = $io;
             $this->_io = $io;
         }
         }
@@ -783,6 +787,10 @@ class Shell
      */
      */
     protected function wrapMessageWithType($messageType, $message)
     protected function wrapMessageWithType($messageType, $message)
     {
     {
+        deprecationWarning(
+            'Shell::wrapMessageWithType() is deprecated. ' .
+            'Use output methods on ConsoleIo instead.'
+        );
         if (is_array($message)) {
         if (is_array($message)) {
             foreach ($message as $k => $v) {
             foreach ($message as $k => $v) {
                 $message[$k] = "<$messageType>" . $v . "</$messageType>";
                 $message[$k] = "<$messageType>" . $v . "</$messageType>";
@@ -849,6 +857,7 @@ class Shell
      */
      */
     public function error($title, $message = null, $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));
         $this->_io->err(sprintf('<error>Error:</error> %s', $title));
 
 
         if (!empty($message)) {
         if (!empty($message)) {

+ 47 - 13
tests/TestCase/Console/ConsoleOptionParserTest.php

@@ -29,18 +29,52 @@ class ConsoleOptionParserTest extends TestCase
     /**
     /**
      * test setting the console description
      * 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
+     *
      * @return void
      * @return void
      */
      */
     public function testDescription()
     public function testDescription()
     {
     {
         $parser = new ConsoleOptionParser('test', false);
         $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($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.');
+        });
     }
     }
 
 
     /**
     /**
@@ -51,13 +85,13 @@ class ConsoleOptionParserTest extends TestCase
     public function testEpilog()
     public function testEpilog()
     {
     {
         $parser = new ConsoleOptionParser('test', false);
         $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($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.');
     }
     }
 
 
     /**
     /**
@@ -789,7 +823,7 @@ TEXT;
     public function testHelpWithRootName()
     public function testHelpWithRootName()
     {
     {
         $parser = new ConsoleOptionParser('sample', false);
         $parser = new ConsoleOptionParser('sample', false);
-        $parser->description('A command!')
+        $parser->setDescription('A command!')
             ->setRootName('tool')
             ->setRootName('tool')
             ->addOption('test', ['help' => 'A test option.']);
             ->addOption('test', ['help' => 'A test option.']);
 
 
@@ -874,8 +908,8 @@ TEXT;
         ];
         ];
         $parser = ConsoleOptionParser::buildFromArray($spec);
         $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();
         $options = $parser->options();
         $this->assertTrue(isset($options['name']));
         $this->assertTrue(isset($options['name']));
@@ -897,7 +931,7 @@ TEXT;
     {
     {
         $parser = ConsoleOptionParser::create('factory', false);
         $parser = ConsoleOptionParser::create('factory', false);
         $this->assertInstanceOf('Cake\Console\ConsoleOptionParser', $parser);
         $this->assertInstanceOf('Cake\Console\ConsoleOptionParser', $parser);
-        $this->assertEquals('factory', $parser->command());
+        $this->assertEquals('factory', $parser->getCommand());
     }
     }
 
 
     /**
     /**
@@ -908,7 +942,7 @@ TEXT;
     public function testCommandInflection()
     public function testCommandInflection()
     {
     {
         $parser = new ConsoleOptionParser('CommandLine');
         $parser = new ConsoleOptionParser('CommandLine');
-        $this->assertEquals('command_line', $parser->command());
+        $this->assertEquals('command_line', $parser->getCommand());
     }
     }
 
 
     /**
     /**

+ 26 - 8
tests/TestCase/Console/ConsoleOutputTest.php

@@ -36,7 +36,7 @@ class ConsoleOutputTest extends TestCase
         $this->output = $this->getMockBuilder('Cake\Console\ConsoleOutput')
         $this->output = $this->getMockBuilder('Cake\Console\ConsoleOutput')
             ->setMethods(['_write'])
             ->setMethods(['_write'])
             ->getMock();
             ->getMock();
-        $this->output->outputAs(ConsoleOutput::COLOR);
+        $this->output->setOutputAs(ConsoleOutput::COLOR);
     }
     }
 
 
     /**
     /**
@@ -222,13 +222,31 @@ class ConsoleOutputTest extends TestCase
     }
     }
 
 
     /**
     /**
+     * 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.
      * test raw output not getting tags replaced.
      *
      *
      * @return void
      * @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')
         $this->output->expects($this->once())->method('_write')
             ->with('<error>Bad</error> Regular');
             ->with('<error>Bad</error> Regular');
 
 
@@ -240,9 +258,9 @@ class ConsoleOutputTest extends TestCase
      *
      *
      * @return void
      * @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')
         $this->output->expects($this->once())->method('_write')
             ->with('Bad Regular');
             ->with('Bad Regular');
 
 
@@ -254,7 +272,7 @@ class ConsoleOutputTest extends TestCase
      *
      *
      * @return void
      * @return void
      */
      */
-    public function testSetOutputAsPlain()
+    public function testSetSetOutputAsPlain()
     {
     {
         $this->output->setOutputAs(ConsoleOutput::PLAIN);
         $this->output->setOutputAs(ConsoleOutput::PLAIN);
         $this->output->expects($this->once())->method('_write')
         $this->output->expects($this->once())->method('_write')
@@ -279,9 +297,9 @@ class ConsoleOutputTest extends TestCase
      *
      *
      * @return void
      * @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')
         $this->output->expects($this->once())->method('_write')
             ->with('Bad Regular <b>Left</b> <i>behind</i> <name>');
             ->with('Bad Regular <b>Left</b> <i>behind</i> <name>');
 
 

+ 5 - 5
tests/TestCase/Console/HelpFormatterTest.php

@@ -34,7 +34,7 @@ class HelpFormatterTest extends TestCase
     public function testWidthFormatting()
     public function testWidthFormatting()
     {
     {
         $parser = new ConsoleOptionParser('test', false);
         $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'])
             ->addOption('four', ['help' => 'this is help text this is help text'])
             ->addArgument('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']);
             ->addSubcommand('four', ['help' => 'this is help text this is help text']);
@@ -115,8 +115,8 @@ txt;
     public function testHelpDescriptionAndEpilog()
     public function testHelpDescriptionAndEpilog()
     {
     {
         $parser = new ConsoleOptionParser('mycommand', false);
         $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.'])
             ->addOption('test', ['help' => 'A test option.'])
             ->addArgument('model', ['help' => 'The model to make.', 'required' => true]);
             ->addArgument('model', ['help' => 'The model to make.', 'required' => true]);
 
 
@@ -384,8 +384,8 @@ xml;
     public function testXmlHelpDescriptionAndEpilog()
     public function testXmlHelpDescriptionAndEpilog()
     {
     {
         $parser = new ConsoleOptionParser('mycommand', false);
         $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.'])
             ->addOption('test', ['help' => 'A test option.'])
             ->addArgument('model', ['help' => 'The model to make.', 'required' => true]);
             ->addArgument('model', ['help' => 'The model to make.', 'required' => true]);
 
 

+ 32 - 10
tests/TestCase/Console/ShellTest.php

@@ -157,7 +157,26 @@ class ShellTest extends TestCase
     public function testConstruct()
     public function testConstruct()
     {
     {
         $this->assertEquals('ShellTestShell', $this->Shell->name);
         $this->assertEquals('ShellTestShell', $this->Shell->name);
-        $this->assertInstanceOf('Cake\Console\ConsoleIo', $this->Shell->io());
+        $this->assertInstanceOf(ConsoleIo::class, $this->Shell->getIo());
+    }
+
+    /**
+     * test io method
+     *
+     * @group deprecated
+     * @return void
+     */
+    public function testIo()
+    {
+        $this->deprecated(function() {
+            $this->assertInstanceOf(ConsoleIo::class, $this->Shell->io());
+
+            $io = $this->getMockBuilder(ConsoleIo::class)
+                ->disableOriginalConstructor()
+                ->getMock();
+            $this->assertSame($io, $this->Shell->io($io));
+            $this->assertSame($io, $this->Shell->io());
+        });
     }
     }
 
 
     /**
     /**
@@ -438,6 +457,7 @@ class ShellTest extends TestCase
     /**
     /**
      * testError
      * testError
      *
      *
+     * @group deprecated
      * @return void
      * @return void
      */
      */
     public function testError()
     public function testError()
@@ -450,8 +470,10 @@ class ShellTest extends TestCase
             ->method('err')
             ->method('err')
             ->with('Searched all...');
             ->with('Searched all...');
 
 
-        $this->Shell->error('Foo Not Found', 'Searched all...');
-        $this->assertSame($this->Shell->stopped, 1);
+        $this->deprecated(function() {
+            $this->Shell->error('Foo Not Found', 'Searched all...');
+            $this->assertSame($this->Shell->stopped, 1);
+        });
     }
     }
 
 
     /**
     /**
@@ -1065,7 +1087,7 @@ TEXT;
             ->setMethods(['startup', 'getOptionParser', 'hr'])
             ->setMethods(['startup', 'getOptionParser', 'hr'])
             ->disableOriginalConstructor()
             ->disableOriginalConstructor()
             ->getMock();
             ->getMock();
-        $shell->io(
+        $shell->setIo(
             $this->getMockBuilder('Cake\Console\ConsoleIo')
             $this->getMockBuilder('Cake\Console\ConsoleIo')
             ->setMethods(['err'])
             ->setMethods(['err'])
             ->getMock()
             ->getMock()
@@ -1094,7 +1116,7 @@ TEXT;
             ->setMethods(['startup', 'getOptionParser', 'hr'])
             ->setMethods(['startup', 'getOptionParser', 'hr'])
             ->disableOriginalConstructor()
             ->disableOriginalConstructor()
             ->getMock();
             ->getMock();
-        $shell->io(
+        $shell->setIo(
             $this->getMockBuilder('Cake\Console\ConsoleIo')
             $this->getMockBuilder('Cake\Console\ConsoleIo')
             ->setMethods(['err'])
             ->setMethods(['err'])
             ->getMock()
             ->getMock()
@@ -1131,7 +1153,7 @@ TEXT;
             ->setMethods(['getOptionParser', 'out', 'startup', '_welcome'])
             ->setMethods(['getOptionParser', 'out', 'startup', '_welcome'])
             ->disableOriginalConstructor()
             ->disableOriginalConstructor()
             ->getMock();
             ->getMock();
-        $shell->io($this->getMockBuilder('Cake\Console\ConsoleIo')->getMock());
+        $shell->setIo($this->getMockBuilder('Cake\Console\ConsoleIo')->getMock());
         $shell->expects($this->once())->method('getOptionParser')
         $shell->expects($this->once())->method('getOptionParser')
             ->will($this->returnValue($parser));
             ->will($this->returnValue($parser));
         $shell->expects($this->once())->method('out');
         $shell->expects($this->once())->method('out');
@@ -1150,7 +1172,7 @@ TEXT;
             ->setMethods(['startup', 'hasTask'])
             ->setMethods(['startup', 'hasTask'])
             ->disableOriginalConstructor()
             ->disableOriginalConstructor()
             ->getMock();
             ->getMock();
-        $shell->io(
+        $shell->setIo(
             $this->getMockBuilder('Cake\Console\ConsoleIo')
             $this->getMockBuilder('Cake\Console\ConsoleIo')
             ->setMethods(['err'])
             ->setMethods(['err'])
             ->getMock()
             ->getMock()
@@ -1189,12 +1211,12 @@ TEXT;
             ->setMethods(['hasTask', 'startup', 'getOptionParser'])
             ->setMethods(['hasTask', 'startup', 'getOptionParser'])
             ->disableOriginalConstructor()
             ->disableOriginalConstructor()
             ->getMock();
             ->getMock();
-        $shell->io($io);
+        $shell->setIo($io);
         $task = $this->getMockBuilder('Cake\Console\Shell')
         $task = $this->getMockBuilder('Cake\Console\Shell')
             ->setMethods(['main', 'runCommand'])
             ->setMethods(['main', 'runCommand'])
             ->disableOriginalConstructor()
             ->disableOriginalConstructor()
             ->getMock();
             ->getMock();
-        $task->io($io);
+        $task->setIo($io);
         $task->expects($this->once())
         $task->expects($this->once())
             ->method('runCommand')
             ->method('runCommand')
             ->with(['one'], false, ['requested' => true]);
             ->with(['one'], false, ['requested' => true]);
@@ -1373,7 +1395,7 @@ TEXT;
         $this->Shell->plugin = 'plugin';
         $this->Shell->plugin = 'plugin';
         $parser = $this->Shell->getOptionParser();
         $parser = $this->Shell->getOptionParser();
 
 
-        $this->assertEquals('plugin.test', $parser->command());
+        $this->assertEquals('plugin.test', $parser->getCommand());
     }
     }
 
 
     /**
     /**

+ 2 - 2
tests/TestCase/Shell/I18nShellTest.php

@@ -78,10 +78,10 @@ class I18nShellTest extends TestCase
             unlink($deDir . 'cake.po');
             unlink($deDir . 'cake.po');
         }
         }
 
 
-        $this->shell->io()->expects($this->at(0))
+        $this->shell->getIo()->expects($this->at(0))
             ->method('ask')
             ->method('ask')
             ->will($this->returnValue('de_DE'));
             ->will($this->returnValue('de_DE'));
-        $this->shell->io()->expects($this->at(1))
+        $this->shell->getIo()->expects($this->at(1))
             ->method('ask')
             ->method('ask')
             ->will($this->returnValue($this->localeDir));
             ->will($this->returnValue($this->localeDir));