From d240bf25398af727947ab65ea65b27c9282d2717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Thu, 14 May 2015 17:04:39 +0200 Subject: [PATCH] All setters now return self to allow easy method chaining --- src/Readline.php | 16 ++++++++++++++++ tests/ReadlineTest.php | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 tests/ReadlineTest.php diff --git a/src/Readline.php b/src/Readline.php index afad1c4..0afc161 100644 --- a/src/Readline.php +++ b/src/Readline.php @@ -60,12 +60,15 @@ public function __construct($output) * Will redraw the current input prompt with the current input buffer. * * @param string $prompt + * @return self * @uses self::redraw() */ public function setPrompt($prompt) { $this->prompt = $prompt; $this->redraw(); + + return $this; } /** @@ -76,12 +79,15 @@ public function setPrompt($prompt) * the new setting. * * @param boolean $echo + * @return self * @uses self::redraw() */ public function setEcho($echo) { $this->echo = !!$echo; $this->redraw(); + + return $this; } /** @@ -91,6 +97,8 @@ public function setEcho($echo) * input buffer (if any). * * @param boolean $move + * @return self + * @uses self::redraw() */ public function setMove($move) { @@ -98,6 +106,8 @@ public function setMove($move) $this->linepos = $this->strlen($this->linebuffer); $this->redraw(); + + return $this; } /** @@ -107,10 +117,13 @@ public function setMove($move) * arrow keys. * * @param HistoryInterface|null $history + * @return self */ public function setHistory(HistoryInterface $history = null) { $this->history = $history; + + return $this; } /** @@ -120,10 +133,13 @@ public function setHistory(HistoryInterface $history = null) * key. * * @param AutocompleteInterface|null $autocomplete + * @return self */ public function setAutocomplete(AutocompleteInterface $autocomplete = null) { $this->autocomplete = $autocomplete; + + return $this; } /** diff --git a/tests/ReadlineTest.php b/tests/ReadlineTest.php new file mode 100644 index 0000000..7eb07ea --- /dev/null +++ b/tests/ReadlineTest.php @@ -0,0 +1,19 @@ +getMockBuilder('Clue\React\Stdio\Stdout')->disableOriginalConstructor()->getMock(); + $this->readline = new Readline($output); + } + + public function testSettersReturnSelf() + { + $this->assertSame($this->readline, $this->readline->setEcho(true)); + $this->assertSame($this->readline, $this->readline->setMove(true)); + $this->assertSame($this->readline, $this->readline->setPrompt('')); + } +}