Skip to content

Commit f329357

Browse files
committed
some update, will add testing methods
1 parent 80c98af commit f329357

File tree

8 files changed

+64
-5
lines changed

8 files changed

+64
-5
lines changed

src/Base/AbstractApplication.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function run($exit = true)
140140
$returnCode = $this->dispatch($command);
141141
} catch (\Throwable $e) {
142142
self::fire(self::ON_RUN_ERROR, [$e, $this]);
143-
$returnCode = $e->getCode() === 0 ? __LINE__ : $e->getCode();
143+
$returnCode = $e->getCode() === 0 ? $e->getLine() : $e->getCode();
144144
$this->handleException($e);
145145
}
146146

@@ -231,7 +231,7 @@ public function handleException($e)
231231
<danger>$title</danger>
232232
233233
Message <magenta>%s</magenta>
234-
At File <cyan>%s</cyan> line <cyan>%d</cyan>
234+
At File <cyan>%s</cyan> line <cyan>%d</cyan>
235235
Catch by %s()\n
236236
Code Trace:\n%s\n
237237
ERR;

src/Controller.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Inhere\Console\Utils\Annotation;
1717

1818
/**
19-
* Class Command
19+
* Class Controller
2020
* @package Inhere\Console
2121
*/
2222
abstract class Controller extends AbstractCommand implements ControllerInterface
@@ -88,7 +88,7 @@ protected function execute($input, $output)
8888
} else {
8989
$group = static::getName();
9090
$status = -1;
91-
$this->output->liteError("Sorry, The command '$action' not exist of the group '{$group}'!");
91+
$output->liteError("Sorry, The command '$action' not exist of the group '{$group}'!");
9292

9393
// find similar command names by similar_text()
9494
$similar = [];
@@ -102,7 +102,7 @@ protected function execute($input, $output)
102102
}
103103

104104
if ($similar) {
105-
$this->write(sprintf('Maybe what you mean is: <info>%s</info>', implode(', ', $similar)));
105+
$output->liteWarning(sprintf("Maybe what you mean is:\n\t <info>%s</info>", implode(', ', $similar)));
106106
} else {
107107
$this->showCommandList();
108108
}

src/IO/Output.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ class Output implements OutputInterface
4040
*/
4141
protected $style;
4242

43+
/**
44+
* Output constructor.
45+
* @param null|resource $outputStream
46+
*/
47+
public function __construct($outputStream = null)
48+
{
49+
if ($outputStream) {
50+
$this->outputStream = $outputStream;
51+
}
52+
53+
$this->getStyle();
54+
}
55+
4356
/////////////////////////////////////////////////////////////////
4457
/// Output Message
4558
/////////////////////////////////////////////////////////////////

tests/ApplicationTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use Inhere\Console\Application;
5+
6+
/**
7+
* @covers Application
8+
*/
9+
class ApplicationTest extends TestCase
10+
{
11+
12+
}

tests/CommandTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use Inhere\Console\Command;
5+
6+
/**
7+
* @covers Command
8+
*/
9+
class CommandTest extends TestCase
10+
{
11+
12+
}

tests/ControllerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use Inhere\Console\Controller;
5+
6+
/**
7+
* @covers Controller
8+
*/
9+
class ControllerTest extends TestCase
10+
{
11+
12+
}

tests/bootstap.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
/**
3+
* phpunit6.phar --bootstrap tests/bootstap.php tests
4+
*/
5+
6+
require dirname(__DIR__) . '/examples/s-autoload.php';

tests/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
# phpunit6.phar --colors --coverage-html ./coverage/
4+
phpunit6.phar --colors --bootstrap tests/bootstap.php tests

0 commit comments

Comments
 (0)