Skip to content

Commit

Permalink
some update, will add testing methods
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Nov 18, 2017
1 parent 80c98af commit f329357
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Base/AbstractApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function run($exit = true)
$returnCode = $this->dispatch($command);
} catch (\Throwable $e) {
self::fire(self::ON_RUN_ERROR, [$e, $this]);
$returnCode = $e->getCode() === 0 ? __LINE__ : $e->getCode();
$returnCode = $e->getCode() === 0 ? $e->getLine() : $e->getCode();
$this->handleException($e);
}

Expand Down Expand Up @@ -231,7 +231,7 @@ public function handleException($e)
<danger>$title</danger>
Message <magenta>%s</magenta>
At File <cyan>%s</cyan> line <cyan>%d</cyan>
At File <cyan>%s</cyan> line <cyan>%d</cyan>
Catch by %s()\n
Code Trace:\n%s\n
ERR;
Expand Down
6 changes: 3 additions & 3 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Inhere\Console\Utils\Annotation;

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

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

if ($similar) {
$this->write(sprintf('Maybe what you mean is: <info>%s</info>', implode(', ', $similar)));
$output->liteWarning(sprintf("Maybe what you mean is:\n\t <info>%s</info>", implode(', ', $similar)));
} else {
$this->showCommandList();
}
Expand Down
13 changes: 13 additions & 0 deletions src/IO/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ class Output implements OutputInterface
*/
protected $style;

/**
* Output constructor.
* @param null|resource $outputStream
*/
public function __construct($outputStream = null)
{
if ($outputStream) {
$this->outputStream = $outputStream;
}

$this->getStyle();
}

/////////////////////////////////////////////////////////////////
/// Output Message
/////////////////////////////////////////////////////////////////
Expand Down
12 changes: 12 additions & 0 deletions tests/ApplicationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

use PHPUnit\Framework\TestCase;
use Inhere\Console\Application;

/**
* @covers Application
*/
class ApplicationTest extends TestCase
{

}
12 changes: 12 additions & 0 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

use PHPUnit\Framework\TestCase;
use Inhere\Console\Command;

/**
* @covers Command
*/
class CommandTest extends TestCase
{

}
12 changes: 12 additions & 0 deletions tests/ControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

use PHPUnit\Framework\TestCase;
use Inhere\Console\Controller;

/**
* @covers Controller
*/
class ControllerTest extends TestCase
{

}
6 changes: 6 additions & 0 deletions tests/bootstap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
/**
* phpunit6.phar --bootstrap tests/bootstap.php tests
*/

require dirname(__DIR__) . '/examples/s-autoload.php';
4 changes: 4 additions & 0 deletions tests/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# phpunit6.phar --colors --coverage-html ./coverage/
phpunit6.phar --colors --bootstrap tests/bootstap.php tests

0 comments on commit f329357

Please sign in to comment.