ソースを参照

Split Shell::io() into getter/setter

Michael Hoffmann 9 年 前
コミット
a4a97d2c7f
3 ファイル変更34 行追加1 行削除
  1. 22 0
      src/Console/Shell.php
  2. 1 1
      src/Console/TaskRegistry.php
  3. 11 0
      tests/TestCase/Console/ShellTest.php

+ 22 - 0
src/Console/Shell.php

@@ -191,8 +191,30 @@ class Shell
     }
 
     /**
+     * Get the io object for this shell.
+     *
+     * @return \Cake\Console\ConsoleIo The current ConsoleIo object.
+     */
+    public function getIo()
+    {
+        return $this->_io;
+    }
+
+    /**
+     * Set the io object for this shell.
+     *
+     * @param \Cake\Console\ConsoleIo $io The ConsoleIo object to use.
+     * @return void
+     */
+    public function setIo(ConsoleIo $io)
+    {
+        $this->_io = $io;
+    }
+
+    /**
      * Get/Set the io object for this shell.
      *
+     * @deprecated 3.5.0 Use getIo()/setIo() instead.
      * @param \Cake\Console\ConsoleIo|null $io The ConsoleIo object to use.
      * @return \Cake\Console\ConsoleIo The current ConsoleIo object.
      */

+ 1 - 1
src/Console/TaskRegistry.php

@@ -86,6 +86,6 @@ class TaskRegistry extends ObjectRegistry
      */
     protected function _create($class, $alias, $settings)
     {
-        return new $class($this->_Shell->io());
+        return new $class($this->_Shell->getIo());
     }
 }

+ 11 - 0
tests/TestCase/Console/ShellTest.php

@@ -1330,6 +1330,17 @@ TEXT;
     }
 
     /**
+     * Test getIo() and setIo() methods
+     *
+     * @return void
+     */
+    public function testGetSetIo()
+    {
+        $this->Shell->setIo($this->io);
+        $this->assertSame($this->Shell->getIo(), $this->io);
+    }
+
+    /**
      * Tests __debugInfo
      *
      * @return void