Skip to content

Commit 0cd6eca

Browse files
committed
Add namespaces to tests
1 parent 206c865 commit 0cd6eca

29 files changed

+210
-212
lines changed

system/Common.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ function log_message(string $level, $message, array $context = [])
7676
// for asserting that logs were called in the test code.
7777
if (ENVIRONMENT == 'testing')
7878
{
79-
$logger = new TestLogger(new \Config\Logger());
79+
$logger = new \CodeIgniter\Log\TestLogger(new \Config\Logger());
8080
return $logger->log($level, $message, $context);
8181
}
8282

8383
return \Config\Services::logger(true)
84-
->log($level, $message, $context);
84+
->log($level, $message, $context);
8585
}
8686
}
8787

system/Config/AutoloadConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function __construct()
143143
'CodeIgniter\View\RenderableInterface' => BASEPATH.'View/RenderableInterface.php',
144144
'CodeIgniter\View\View' => BASEPATH.'View/View.php',
145145
'Zend\Escaper\Escaper' => BASEPATH.'View/Escaper.php',
146-
'TestLogger' => BASEPATH.'../tests/_support/Log/TestLogger.php',
146+
'CodeIgniter\Log\TestLogger' => BASEPATH.'../tests/_support/Log/TestLogger.php',
147147
];
148148
}
149149

tests/Autoloader/AutoloaderTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<?php
1+
<?php namespace CodeIgniter\Autoloader;
22

3-
class MockAutoloaderClass extends \CodeIgniter\Autoloader\Autoloader
3+
class MockAutoloaderClass extends Autoloader
44
{
55

66
protected $files = [];
@@ -24,6 +24,8 @@ protected function requireFile($file)
2424

2525
}
2626

27+
use Config\Autoload;
28+
2729
//--------------------------------------------------------------------
2830

2931
class AutoloaderTest extends \CIUnitTestCase
@@ -35,7 +37,7 @@ class AutoloaderTest extends \CIUnitTestCase
3537

3638
protected function setUp()
3739
{
38-
$config = new Config\Autoload();
40+
$config = new Autoload();
3941

4042
$config->classmap = [
4143
'FirstClass' => '/app/dir/First.php',

tests/Config/DotEnvTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
<?php
1+
<?php namespace CodeIgniter\Config;
22

33
//require_once 'system/Benchmark/Timer.php';
44

5-
use CodeIgniter\Config\DotEnv;
6-
7-
class DotEnvTest extends CIUnitTestCase {
5+
class DotEnvTest extends \CIUnitTestCase
6+
{
87

98
protected $fixturesFolder;
109

1110
//--------------------------------------------------------------------
1211

1312
public function setup()
1413
{
15-
$this->fixturesFolder = dirname(__FILE__).'/fixtures';
14+
$this->fixturesFolder = dirname(__FILE__).'/fixtures';
1615
}
1716

1817
//--------------------------------------------------------------------
1918

2019
public function testReturnsFalseIfCannotFindFile()
2120
{
22-
$dotenv = new DotEnv(__DIR__);
21+
$dotenv = new DotEnv(__DIR__);
2322
$this->assertFalse($dotenv->load());
2423
}
2524

tests/Config/MimesTest.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
<?php
1+
<?php namespace Config;
22

3-
4-
class MimesTest extends CIUnitTestCase
3+
class MimesTest extends \CIUnitTestCase
54
{
65
public function extensionsList()
76
{
8-
return [
9-
'null' => [null, 'xkadjflkjdsf'],
10-
'single' => ['cpt', 'application/mac-compactpro'],
11-
'trimmed' => ['cpt', ' application/mac-compactpro '],
12-
'manyMimes' => ['csv', 'text/csv'],
13-
'mixedCase' => ['csv', 'text/CSV'],
14-
];
7+
return [
8+
'null' => [null, 'xkadjflkjdsf'],
9+
'single' => ['cpt', 'application/mac-compactpro'],
10+
'trimmed' => ['cpt', ' application/mac-compactpro '],
11+
'manyMimes' => ['csv', 'text/csv'],
12+
'mixedCase' => ['csv', 'text/CSV'],
13+
];
1514
}
1615

1716
//--------------------------------------------------------------------
@@ -24,20 +23,20 @@ public function extensionsList()
2423
*/
2524
public function testGuessExtensionFromType($expected, $mime)
2625
{
27-
$this->assertEquals($expected, \Config\Mimes::guessExtensionFromType($mime));
26+
$this->assertEquals($expected, Mimes::guessExtensionFromType($mime));
2827
}
2928

3029
//--------------------------------------------------------------------
3130

3231
public function mimesList()
3332
{
34-
return [
35-
'null' => [null, 'xalkjdlfkj'],
36-
'single' => ['audio/midi', 'mid'],
37-
'many' => ['image/bmp', 'bmp'],
38-
'trimmed' => ['image/bmp', '.bmp'],
39-
'mixedCase' => ['image/bmp', 'BMP'],
40-
];
33+
return [
34+
'null' => [null, 'xalkjdlfkj'],
35+
'single' => ['audio/midi', 'mid'],
36+
'many' => ['image/bmp', 'bmp'],
37+
'trimmed' => ['image/bmp', '.bmp'],
38+
'mixedCase' => ['image/bmp', 'BMP'],
39+
];
4140
}
4241

4342
//--------------------------------------------------------------------
@@ -47,7 +46,7 @@ public function mimesList()
4746
*/
4847
public function testGuessTypeFromExtension($expected, $ext)
4948
{
50-
$this->assertEquals($expected, \Config\Mimes::guessTypeFromExtension($ext));
49+
$this->assertEquals($expected, Mimes::guessTypeFromExtension($ext));
5150
}
5251

5352
//--------------------------------------------------------------------

tests/Debug/TimerTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
<?php
1+
<?php namespace CodeIgniter\Debug;
22

3-
use CodeIgniter\Debug\Timer;
4-
5-
class TimerTest extends CIUnitTestCase {
3+
class TimerTest extends \CIUnitTestCase
4+
{
65

76
public function setUp() { }
87

@@ -19,7 +18,7 @@ public function tearDown() { }
1918
*/
2019
public function testStoresTimers()
2120
{
22-
$timer = new Timer();
21+
$timer = new Timer();
2322

2423
$timer->start('test1');
2524
sleep(1);
@@ -77,12 +76,12 @@ public function testElapsedTimeGivesSameResultAsTimersArray()
7776
*/
7877
public function testThrowsExceptionStoppingNonTimer()
7978
{
80-
$timer = new Timer();
79+
$timer = new Timer();
8180

8281
$timer->stop('test1');
8382
}
8483

8584
//--------------------------------------------------------------------
8685

8786

88-
}
87+
}

tests/HTTP/CURLRequestTest.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
<?php
1+
<?php namespace CodeIgniter\HTTP;
22

33
use Config\App;
4-
use CodeIgniter\HTTP\URI;
5-
use CodeIgniter\HTTP\Response;
64

75
/**
86
* Class MockCURLRequest
@@ -11,8 +9,8 @@
119
* test runs. Instead, we can set the desired output
1210
* and get back the set options.
1311
*/
14-
class MockCURLRequest extends \CodeIgniter\HTTP\CURLRequest {
15-
12+
class MockCURLRequest extends CURLRequest
13+
{
1614
public $curl_options;
1715

1816
protected $output = '';
@@ -43,7 +41,7 @@ protected function sendRequest(array $curl_options = []): string
4341
//--------------------------------------------------------------------
4442

4543

46-
class CURLRequestTest extends CIUnitTestCase
44+
class CURLRequestTest extends \CIUnitTestCase
4745
{
4846
protected $request;
4947

@@ -58,8 +56,8 @@ public function testSendReturnsResponse()
5856
{
5957
$output = "Howdy Stranger.";
6058

61-
$response = $this->request->setOutput($output)
62-
->send('get', 'http://example.com');
59+
$response = $this->request->setOutput($output)
60+
->send('get', 'http://example.com');
6361

6462
$this->assertInstanceOf('CodeIgniter\\HTTP\\Response', $response);
6563
$this->assertEquals($output, $response->getBody());
@@ -69,7 +67,7 @@ public function testSendReturnsResponse()
6967

7068
public function testGetSetsCorrectMethod()
7169
{
72-
$response = $this->request->get('http://example.com');
70+
$response = $this->request->get('http://example.com');
7371

7472
$this->assertEquals('get', $this->request->getMethod());
7573

tests/HTTP/Files/FileCollectionTest.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
<?php
1+
<?php namespace CodeIgniter\HTTP\Files;
22

3-
class FileCollectionTest extends CIUnitTestCase
3+
class FileCollectionTest extends \CIUnitTestCase
44
{
55
public function setUp()
66
{
7-
$_FILES = [];
7+
$_FILES = [];
88
}
99

1010
//--------------------------------------------------------------------
1111

1212
public function testAllReturnsNullWithNoFiles()
1313
{
14-
$files = new \CodeIgniter\HTTP\Files\FileCollection();
14+
$files = new FileCollection();
1515

1616
$this->assertNull($files->all());
1717
}
@@ -23,19 +23,19 @@ public function testAllReturnsValidSingleFile()
2323
$_FILES = [
2424
'userfile' => [
2525
'name' => 'someFile.txt',
26-
'type' => 'text/plain',
27-
'size' => '124',
28-
'tmp_name' => '/tmp/myTempFile.txt',
29-
'error' => 0
26+
'type' => 'text/plain',
27+
'size' => '124',
28+
'tmp_name' => '/tmp/myTempFile.txt',
29+
'error' => 0
3030
]
3131
];
3232

33-
$collection = new \CodeIgniter\HTTP\Files\FileCollection();
33+
$collection = new FileCollection();
3434
$files = $collection->all();
3535
$this->assertEquals(1, count($files));
3636

3737
$file = array_shift($files);
38-
$this->assertTrue($file instanceof \CodeIgniter\HTTP\Files\UploadedFile);
38+
$this->assertTrue($file instanceof UploadedFile);
3939

4040
$this->assertEquals('someFile.txt', $file->getName());
4141
$this->assertEquals(124, $file->getSize());
@@ -55,7 +55,7 @@ public function testAllReturnsValidMultipleFilesSameName()
5555
]
5656
];
5757

58-
$collection = new \CodeIgniter\HTTP\Files\FileCollection();
58+
$collection = new FileCollection();
5959
$files = $collection->all();
6060
$this->assertEquals(1, count($files));
6161
$this->assertEquals('userfile', key($files));
@@ -64,7 +64,7 @@ public function testAllReturnsValidMultipleFilesSameName()
6464
$this->assertEquals(2, count($files));
6565

6666
$file = $files[0];
67-
$this->assertTrue($file instanceof \CodeIgniter\HTTP\Files\UploadedFile);
67+
$this->assertTrue($file instanceof UploadedFile);
6868

6969
$this->assertEquals('fileA.txt', $file->getName());
7070
$this->assertEquals('/tmp/fileA.txt', $file->getTempName());
@@ -95,13 +95,13 @@ public function testAllReturnsValidMultipleFilesDifferentName()
9595
],
9696
];
9797

98-
$collection = new \CodeIgniter\HTTP\Files\FileCollection();
98+
$collection = new FileCollection();
9999
$files = $collection->all();
100100
$this->assertEquals(2, count($files));
101101
$this->assertEquals('userfile1', key($files));
102102

103103
$file = array_shift($files);
104-
$this->assertTrue($file instanceof \CodeIgniter\HTTP\Files\UploadedFile);
104+
$this->assertTrue($file instanceof UploadedFile);
105105

106106
$this->assertEquals('fileA.txt', $file->getName());
107107
$this->assertEquals('/tmp/fileA.txt', $file->getTempName());
@@ -110,7 +110,7 @@ public function testAllReturnsValidMultipleFilesDifferentName()
110110
$this->assertEquals(124, $file->getSize());
111111

112112
$file = array_pop($files);
113-
$this->assertTrue($file instanceof \CodeIgniter\HTTP\Files\UploadedFile);
113+
$this->assertTrue($file instanceof UploadedFile);
114114

115115
$this->assertEquals('fileB.txt', $file->getName());
116116
$this->assertEquals('/tmp/fileB.txt', $file->getTempName());
@@ -152,15 +152,15 @@ public function testAllReturnsValidSingleFileNestedName()
152152
]
153153
];
154154

155-
$collection = new \CodeIgniter\HTTP\Files\FileCollection();
155+
$collection = new FileCollection();
156156
$files = $collection->all();
157157
$this->assertEquals(1, count($files));
158158
$this->assertEquals('userfile', key($files));
159159

160160
$this->assertTrue(isset($files['userfile']['foo']['bar']));
161161

162162
$file = $files['userfile']['foo']['bar'];
163-
$this->assertTrue($file instanceof \CodeIgniter\HTTP\Files\UploadedFile);
163+
$this->assertTrue($file instanceof UploadedFile);
164164

165165
$this->assertEquals('fileA.txt', $file->getName());
166166
$this->assertEquals('/tmp/fileA.txt', $file->getTempName());
@@ -183,7 +183,7 @@ public function testHasFileWithSingleFile()
183183
]
184184
];
185185

186-
$collection = new \CodeIgniter\HTTP\Files\FileCollection();
186+
$collection = new FileCollection();
187187

188188
$this->assertTrue($collection->hasFile('userfile'));
189189
$this->assertFalse($collection->hasFile('foo'));
@@ -210,7 +210,7 @@ public function testHasFileWithMultipleFilesWithDifferentNames()
210210
],
211211
];
212212

213-
$collection = new \CodeIgniter\HTTP\Files\FileCollection();
213+
$collection = new FileCollection();
214214

215215
$this->assertTrue($collection->hasFile('userfile1'));
216216
$this->assertTrue($collection->hasFile('userfile2'));
@@ -249,7 +249,7 @@ public function testHasFileWithSingleFileNestedName()
249249
]
250250
];
251251

252-
$collection = new \CodeIgniter\HTTP\Files\FileCollection();
252+
$collection = new FileCollection();
253253

254254
$this->assertTrue($collection->hasFile('userfile'));
255255
$this->assertTrue($collection->hasFile('userfile.foo'));
@@ -272,7 +272,7 @@ public function testErrorString()
272272

273273
$expected = 'The file "someFile.txt" exceeds your upload_max_filesize ini directive.';
274274

275-
$collection = new \CodeIgniter\HTTP\Files\FileCollection();
275+
$collection = new FileCollection();
276276
$file = $collection->getFile('userfile');
277277

278278
$this->assertEquals($expected, $file->getErrorString());

tests/HTTP/HeaderTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
<?php
2-
3-
4-
class HeaderTest extends CIUnitTestCase {
1+
<?php namespace CodeIgniter\HTTP;
52

3+
class HeaderTest extends \CIUnitTestCase
4+
{
65
public function testHeaderStoresBasics()
76
{
87
$name = 'foo';
98
$value = 'bar';
109

11-
$header = new \CodeIgniter\HTTP\Header($name, $value);
10+
$header = new \CodeIgniter\HTTP\Header($name, $value);
1211

1312
$this->assertEquals($name, $header->getName());
1413
$this->assertEquals($value, $header->getValue());

0 commit comments

Comments
 (0)