output = $this->getMockBuilder('Cake\Console\ConsoleOutput') ->setMethods(['_write']) ->getMock(); $this->output->outputAs(ConsoleOutput::COLOR); } /** * tearDown * * @return void */ public function tearDown() { parent::tearDown(); unset($this->output); } /** * test writing with no new line * * @return void */ public function testWriteNoNewLine() { $this->output->expects($this->once())->method('_write') ->with('Some output'); $this->output->write('Some output', false); } /** * test writing with no new line * * @return void */ public function testWriteNewLine() { $this->output->expects($this->once())->method('_write') ->with('Some output' . PHP_EOL); $this->output->write('Some output'); } /** * test write() with multiple new lines * * @return void */ public function testWriteMultipleNewLines() { $this->output->expects($this->once())->method('_write') ->with('Some output' . PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL); $this->output->write('Some output', 4); } /** * test writing an array of messages. * * @return void */ public function testWriteArray() { $this->output->expects($this->once())->method('_write') ->with('Line' . PHP_EOL . 'Line' . PHP_EOL . 'Line' . PHP_EOL); $this->output->write(['Line', 'Line', 'Line']); } /** * test getting a style. * * @return void */ public function testStylesGet() { $result = $this->output->styles('error'); $expected = ['text' => 'red']; $this->assertEquals($expected, $result); $this->assertNull($this->output->styles('made_up_goop')); $result = $this->output->styles(); $this->assertNotEmpty($result, 'Error is missing'); $this->assertNotEmpty($result, 'Warning is missing'); } /** * test adding a style. * * @return void */ public function testStylesAdding() { $this->output->styles('test', ['text' => 'red', 'background' => 'black']); $result = $this->output->styles('test'); $expected = ['text' => 'red', 'background' => 'black']; $this->assertEquals($expected, $result); $this->assertTrue($this->output->styles('test', false), 'Removing a style should return true.'); $this->assertNull($this->output->styles('test'), 'Removed styles should be null.'); } /** * test formatting text with styles. * * @return void */ public function testFormattingSimple() { $this->output->expects($this->once())->method('_write') ->with("\033[31mError:\033[0m Something bad"); $this->output->write('Error: Something bad', false); } /** * test that formatting doesn't eat tags it doesn't know about. * * @return void */ public function testFormattingNotEatingTags() { $this->output->expects($this->once())->method('_write') ->with(' Something bad'); $this->output->write(' Something bad', false); } /** * test formatting with custom styles. * * @return void */ public function testFormattingCustom() { $this->output->styles('annoying', [ 'text' => 'magenta', 'background' => 'cyan', 'blink' => true, 'underline' => true ]); $this->output->expects($this->once())->method('_write') ->with("\033[35;46;5;4mAnnoy:\033[0m Something bad"); $this->output->write('Annoy: Something bad', false); } /** * test formatting text with missing styles. * * @return void */ public function testFormattingMissingStyleName() { $this->output->expects($this->once())->method('_write') ->with('Error: Something bad'); $this->output->write('Error: Something bad', false); } /** * test formatting text with multiple styles. * * @return void */ public function testFormattingMultipleStylesName() { $this->output->expects($this->once())->method('_write') ->with("\033[31mBad\033[0m \033[33mWarning\033[0m Regular"); $this->output->write('Bad Warning Regular', false); } /** * test that multiple tags of the same name work in one string. * * @return void */ public function testFormattingMultipleSameTags() { $this->output->expects($this->once())->method('_write') ->with("\033[31mBad\033[0m \033[31mWarning\033[0m Regular"); $this->output->write('Bad Warning Regular', false); } /** * test raw output not getting tags replaced. * * @return void */ public function testOutputAsRaw() { $this->output->outputAs(ConsoleOutput::RAW); $this->output->expects($this->once())->method('_write') ->with('Bad Regular'); $this->output->write('Bad Regular', false); } /** * test plain output. * * @return void */ public function testOutputAsPlain() { $this->output->outputAs(ConsoleOutput::PLAIN); $this->output->expects($this->once())->method('_write') ->with('Bad Regular'); $this->output->write('Bad Regular', false); } /** * test set plain output. * * @return void */ public function testSetOutputAsPlain() { $this->output->setOutputAs(ConsoleOutput::PLAIN); $this->output->expects($this->once())->method('_write') ->with('Bad Regular'); $this->output->write('Bad Regular', false); } /** * test set wrong type. * */ public function testSetOutputWrongType() { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid output type "Foo".'); $this->output->setOutputAs('Foo'); } /** * test plain output only strips tags used for formatting. * * @return void */ public function testOutputAsPlainSelectiveTagRemoval() { $this->output->outputAs(ConsoleOutput::PLAIN); $this->output->expects($this->once())->method('_write') ->with('Bad Regular Left behind '); $this->output->write('Bad Regular Left behind ', false); } }