Skip to content

Commit bd7b0e6

Browse files
authored
Merge pull request #1356 from jim-parry/testing/commands
Testing/commands
2 parents e336dfc + 17778bc commit bd7b0e6

File tree

6 files changed

+80
-10
lines changed

6 files changed

+80
-10
lines changed

system/Autoloader/FileLocator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
* Allows loading non-class files in a namespaced manner.
4444
* Works with Helpers, Views, etc.
4545
*
46-
* @todo sanitize filenames prior to checking them...
47-
*
46+
*
4847
* @package CodeIgniter
4948
*/
5049
class FileLocator
@@ -133,7 +132,6 @@ public function locateFile(string $file, string $folder = null, string $ext = 'p
133132
// IF we have a folder name, then the calling function
134133
// expects this file to be within that folder, like 'Views',
135134
// or 'libraries'.
136-
// @todo Allow it to check with and without the nested folder.
137135
if ( ! empty($folder) && strpos($filename, $folder) === false)
138136
{
139137
$filename = $folder . '/' . $filename;

system/CLI/CommandRunner.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php namespace CodeIgniter\CLI;
1+
<?php
2+
namespace CodeIgniter\CLI;
23

34
/**
45
* CodeIgniter
@@ -39,6 +40,7 @@
3940

4041
class CommandRunner extends Controller
4142
{
43+
4244
/**
4345
* Stores the info about found Commands.
4446
*
@@ -73,7 +75,6 @@ public function _remap($method, ...$params)
7375

7476
//--------------------------------------------------------------------
7577

76-
7778
/**
7879
* @param array $params
7980
*
@@ -143,7 +144,6 @@ protected function createCommandList()
143144
foreach ($files as $file)
144145
{
145146
$className = service('locator')->findQualifiedNameFromPath($file);
146-
147147
if (empty($className) || ! class_exists($className))
148148
{
149149
continue;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace Tests\Support\Commands;
3+
4+
use CodeIgniter\CLI\BaseCommand;
5+
use CodeIgniter\CLI\CLI;
6+
use CodeIgniter\CodeIgniter;
7+
8+
abstract class AbstractInfo extends BaseCommand
9+
{
10+
11+
protected $group = 'demo';
12+
protected $name = 'app:pablo';
13+
protected $description = 'Displays basic application information.';
14+
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
namespace Tests\Support\Commands;
3+
4+
use CodeIgniter\CLI\BaseCommand;
5+
use CodeIgniter\CLI\CLI;
6+
use CodeIgniter\CodeIgniter;
7+
8+
class AppInfo extends BaseCommand
9+
{
10+
11+
protected $group = 'demo';
12+
protected $name = 'app:info';
13+
protected $description = 'Displays basic application information.';
14+
15+
public function run(array $params)
16+
{
17+
CLI::write('CI Version: ' . CLI::color(CodeIgniter::CI_VERSION, 'red'));
18+
}
19+
20+
}

tests/system/Commands/CommandsTest.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php namespace CodeIgniter\Commands;
1+
<?php
2+
namespace CodeIgniter\Commands;
23

34
use Config\Services;
45
use Tests\Support\Config\MockAppConfig;
@@ -19,7 +20,6 @@ class CommandsTest extends \CIUnitTestCase
1920
protected $logger;
2021
protected $runner;
2122

22-
2323
public function setUp()
2424
{
2525
parent::setUp();
@@ -73,4 +73,34 @@ public function testListCommands()
7373
$this->assertContains('Displays basic usage information.', $result);
7474
}
7575

76+
public function testCustomCommand()
77+
{
78+
$this->runner->index(['app:info']);
79+
$result = CITestStreamFilter::$buffer;
80+
81+
$this->assertContains('CI Version:', $result);
82+
}
83+
84+
public function testNonexistantCommand()
85+
{
86+
// catch errors too
87+
$this->stream_filter = stream_filter_append(STDERR, 'CITestStreamFilter');
88+
89+
$this->runner->index(['app:oops']);
90+
$result = CITestStreamFilter::$buffer;
91+
92+
$this->assertContains('not found', $result);
93+
}
94+
95+
public function testAbstractCommand()
96+
{
97+
// catch errors too
98+
$this->stream_filter = stream_filter_append(STDERR, 'CITestStreamFilter');
99+
100+
$this->runner->index(['app:pablo']);
101+
$result = CITestStreamFilter::$buffer;
102+
103+
$this->assertContains('not found', $result);
104+
}
105+
76106
}

user_guide_src/source/changelog.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public /
2525
- index #1295, #1313
2626

2727
system /
28+
- CLI/
29+
- CommandRunner #1350, #1356
2830
- Commands/
2931
- Server/Serve #1313
3032
- Config/
@@ -65,7 +67,7 @@ system /
6567
- Cast #1283
6668
- HTTP #1239
6769
- Router/
68-
- RouteCollection #1285
70+
- RouteCollection #1285, #1355
6971
- Test/
7072
- FeatureTestCase #1282
7173
- CodeIgniter #1239 #1337
@@ -76,6 +78,8 @@ system /
7678
tests /
7779
- API/
7880
- ResponseTraitTest #1302
81+
- Commands/
82+
- CommandsTest #1356
7983
- Database/
8084
- BaseBuilderTest #1217
8185
- Live/ModelTest #1311
@@ -98,7 +102,7 @@ tests /
98102
- I18n/
99103
- TimeTest #1273, #1316
100104
- Router/
101-
- RouteTest #1285
105+
- RouteTest #1285, #1355
102106
- View/
103107
- ParserTest #1311
104108
- EntityTest #1319
@@ -142,6 +146,9 @@ user_guide_src /source/
142146
PRs merged:
143147
-----------
144148

149+
- #1356 Testing/commands
150+
- #1355 Handle duplicate HTTP verb and generic rules properly
151+
- #1350 Checks if class is instantiable and is a command
145152
- #1348 Fix sphinx formatting in sessions
146153
- #1347 Fix sphinx formatting in sessions
147154
- #1342 Toolbar Styles

0 commit comments

Comments
 (0)