Skip to content

Commit

Permalink
Merge pull request #1356 from jim-parry/testing/commands
Browse files Browse the repository at this point in the history
Testing/commands
  • Loading branch information
jim-parry authored Oct 25, 2018
2 parents e336dfc + 17778bc commit bd7b0e6
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 10 deletions.
4 changes: 1 addition & 3 deletions system/Autoloader/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
* Allows loading non-class files in a namespaced manner.
* Works with Helpers, Views, etc.
*
* @todo sanitize filenames prior to checking them...
*
*
* @package CodeIgniter
*/
class FileLocator
Expand Down Expand Up @@ -133,7 +132,6 @@ public function locateFile(string $file, string $folder = null, string $ext = 'p
// IF we have a folder name, then the calling function
// expects this file to be within that folder, like 'Views',
// or 'libraries'.
// @todo Allow it to check with and without the nested folder.
if ( ! empty($folder) && strpos($filename, $folder) === false)
{
$filename = $folder . '/' . $filename;
Expand Down
6 changes: 3 additions & 3 deletions system/CLI/CommandRunner.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php namespace CodeIgniter\CLI;
<?php
namespace CodeIgniter\CLI;

/**
* CodeIgniter
Expand Down Expand Up @@ -39,6 +40,7 @@

class CommandRunner extends Controller
{

/**
* Stores the info about found Commands.
*
Expand Down Expand Up @@ -73,7 +75,6 @@ public function _remap($method, ...$params)

//--------------------------------------------------------------------


/**
* @param array $params
*
Expand Down Expand Up @@ -143,7 +144,6 @@ protected function createCommandList()
foreach ($files as $file)
{
$className = service('locator')->findQualifiedNameFromPath($file);

if (empty($className) || ! class_exists($className))
{
continue;
Expand Down
15 changes: 15 additions & 0 deletions tests/_support/Commands/AbstractInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace Tests\Support\Commands;

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CodeIgniter;

abstract class AbstractInfo extends BaseCommand
{

protected $group = 'demo';
protected $name = 'app:pablo';
protected $description = 'Displays basic application information.';

}
20 changes: 20 additions & 0 deletions tests/_support/Commands/AppInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
namespace Tests\Support\Commands;

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\CodeIgniter;

class AppInfo extends BaseCommand
{

protected $group = 'demo';
protected $name = 'app:info';
protected $description = 'Displays basic application information.';

public function run(array $params)
{
CLI::write('CI Version: ' . CLI::color(CodeIgniter::CI_VERSION, 'red'));
}

}
34 changes: 32 additions & 2 deletions tests/system/Commands/CommandsTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php namespace CodeIgniter\Commands;
<?php
namespace CodeIgniter\Commands;

use Config\Services;
use Tests\Support\Config\MockAppConfig;
Expand All @@ -19,7 +20,6 @@ class CommandsTest extends \CIUnitTestCase
protected $logger;
protected $runner;


public function setUp()
{
parent::setUp();
Expand Down Expand Up @@ -73,4 +73,34 @@ public function testListCommands()
$this->assertContains('Displays basic usage information.', $result);
}

public function testCustomCommand()
{
$this->runner->index(['app:info']);
$result = CITestStreamFilter::$buffer;

$this->assertContains('CI Version:', $result);
}

public function testNonexistantCommand()
{
// catch errors too
$this->stream_filter = stream_filter_append(STDERR, 'CITestStreamFilter');

$this->runner->index(['app:oops']);
$result = CITestStreamFilter::$buffer;

$this->assertContains('not found', $result);
}

public function testAbstractCommand()
{
// catch errors too
$this->stream_filter = stream_filter_append(STDERR, 'CITestStreamFilter');

$this->runner->index(['app:pablo']);
$result = CITestStreamFilter::$buffer;

$this->assertContains('not found', $result);
}

}
11 changes: 9 additions & 2 deletions user_guide_src/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public /
- index #1295, #1313

system /
- CLI/
- CommandRunner #1350, #1356
- Commands/
- Server/Serve #1313
- Config/
Expand Down Expand Up @@ -65,7 +67,7 @@ system /
- Cast #1283
- HTTP #1239
- Router/
- RouteCollection #1285
- RouteCollection #1285, #1355
- Test/
- FeatureTestCase #1282
- CodeIgniter #1239 #1337
Expand All @@ -76,6 +78,8 @@ system /
tests /
- API/
- ResponseTraitTest #1302
- Commands/
- CommandsTest #1356
- Database/
- BaseBuilderTest #1217
- Live/ModelTest #1311
Expand All @@ -98,7 +102,7 @@ tests /
- I18n/
- TimeTest #1273, #1316
- Router/
- RouteTest #1285
- RouteTest #1285, #1355
- View/
- ParserTest #1311
- EntityTest #1319
Expand Down Expand Up @@ -142,6 +146,9 @@ user_guide_src /source/
PRs merged:
-----------

- #1356 Testing/commands
- #1355 Handle duplicate HTTP verb and generic rules properly
- #1350 Checks if class is instantiable and is a command
- #1348 Fix sphinx formatting in sessions
- #1347 Fix sphinx formatting in sessions
- #1342 Toolbar Styles
Expand Down

0 comments on commit bd7b0e6

Please sign in to comment.