diff --git a/system/Common.php b/system/Common.php index 92cc9f641dbd..fa596c38843a 100644 --- a/system/Common.php +++ b/system/Common.php @@ -76,12 +76,12 @@ function log_message(string $level, $message, array $context = []) // for asserting that logs were called in the test code. if (ENVIRONMENT == 'testing') { - $logger = new TestLogger(new \Config\Logger()); + $logger = new \CodeIgniter\Log\TestLogger(new \Config\Logger()); return $logger->log($level, $message, $context); } return \Config\Services::logger(true) - ->log($level, $message, $context); + ->log($level, $message, $context); } } diff --git a/system/Config/AutoloadConfig.php b/system/Config/AutoloadConfig.php index 449e01848d37..881e4b3be6d5 100644 --- a/system/Config/AutoloadConfig.php +++ b/system/Config/AutoloadConfig.php @@ -143,7 +143,7 @@ public function __construct() 'CodeIgniter\View\RenderableInterface' => BASEPATH.'View/RenderableInterface.php', 'CodeIgniter\View\View' => BASEPATH.'View/View.php', 'Zend\Escaper\Escaper' => BASEPATH.'View/Escaper.php', - 'TestLogger' => BASEPATH.'../tests/_support/Log/TestLogger.php', + 'CodeIgniter\Log\TestLogger' => BASEPATH.'../tests/_support/Log/TestLogger.php', ]; } diff --git a/tests/Autoloader/AutoloaderTest.php b/tests/Autoloader/AutoloaderTest.php index a72d4e02eb25..b0d725ddbf2a 100644 --- a/tests/Autoloader/AutoloaderTest.php +++ b/tests/Autoloader/AutoloaderTest.php @@ -1,6 +1,6 @@ -classmap = [ 'FirstClass' => '/app/dir/First.php', diff --git a/tests/Config/DotEnvTest.php b/tests/Config/DotEnvTest.php index ac9b329d674d..d19b32298636 100644 --- a/tests/Config/DotEnvTest.php +++ b/tests/Config/DotEnvTest.php @@ -1,10 +1,9 @@ -fixturesFolder = dirname(__FILE__).'/fixtures'; + $this->fixturesFolder = dirname(__FILE__).'/fixtures'; } //-------------------------------------------------------------------- public function testReturnsFalseIfCannotFindFile() { - $dotenv = new DotEnv(__DIR__); + $dotenv = new DotEnv(__DIR__); $this->assertFalse($dotenv->load()); } diff --git a/tests/Config/MimesTest.php b/tests/Config/MimesTest.php index 24e6c7a55583..b4c5f6eabb4e 100644 --- a/tests/Config/MimesTest.php +++ b/tests/Config/MimesTest.php @@ -1,17 +1,16 @@ - [null, 'xkadjflkjdsf'], - 'single' => ['cpt', 'application/mac-compactpro'], - 'trimmed' => ['cpt', ' application/mac-compactpro '], - 'manyMimes' => ['csv', 'text/csv'], - 'mixedCase' => ['csv', 'text/CSV'], - ]; + return [ + 'null' => [null, 'xkadjflkjdsf'], + 'single' => ['cpt', 'application/mac-compactpro'], + 'trimmed' => ['cpt', ' application/mac-compactpro '], + 'manyMimes' => ['csv', 'text/csv'], + 'mixedCase' => ['csv', 'text/CSV'], + ]; } //-------------------------------------------------------------------- @@ -24,20 +23,20 @@ public function extensionsList() */ public function testGuessExtensionFromType($expected, $mime) { - $this->assertEquals($expected, \Config\Mimes::guessExtensionFromType($mime)); + $this->assertEquals($expected, Mimes::guessExtensionFromType($mime)); } //-------------------------------------------------------------------- public function mimesList() { - return [ - 'null' => [null, 'xalkjdlfkj'], - 'single' => ['audio/midi', 'mid'], - 'many' => ['image/bmp', 'bmp'], - 'trimmed' => ['image/bmp', '.bmp'], - 'mixedCase' => ['image/bmp', 'BMP'], - ]; + return [ + 'null' => [null, 'xalkjdlfkj'], + 'single' => ['audio/midi', 'mid'], + 'many' => ['image/bmp', 'bmp'], + 'trimmed' => ['image/bmp', '.bmp'], + 'mixedCase' => ['image/bmp', 'BMP'], + ]; } //-------------------------------------------------------------------- @@ -47,7 +46,7 @@ public function mimesList() */ public function testGuessTypeFromExtension($expected, $ext) { - $this->assertEquals($expected, \Config\Mimes::guessTypeFromExtension($ext)); + $this->assertEquals($expected, Mimes::guessTypeFromExtension($ext)); } //-------------------------------------------------------------------- diff --git a/tests/Debug/TimerTest.php b/tests/Debug/TimerTest.php index c61a382cdaf6..28852debf0c0 100644 --- a/tests/Debug/TimerTest.php +++ b/tests/Debug/TimerTest.php @@ -1,8 +1,7 @@ -start('test1'); sleep(1); @@ -77,7 +76,7 @@ public function testElapsedTimeGivesSameResultAsTimersArray() */ public function testThrowsExceptionStoppingNonTimer() { - $timer = new Timer(); + $timer = new Timer(); $timer->stop('test1'); } @@ -85,4 +84,4 @@ public function testThrowsExceptionStoppingNonTimer() //-------------------------------------------------------------------- -} \ No newline at end of file +} diff --git a/tests/HTTP/CURLRequestTest.php b/tests/HTTP/CURLRequestTest.php index 3e2cd2d089e8..7f75cb1f3eec 100644 --- a/tests/HTTP/CURLRequestTest.php +++ b/tests/HTTP/CURLRequestTest.php @@ -1,8 +1,6 @@ -request->setOutput($output) - ->send('get', 'http://example.com'); + $response = $this->request->setOutput($output) + ->send('get', 'http://example.com'); $this->assertInstanceOf('CodeIgniter\\HTTP\\Response', $response); $this->assertEquals($output, $response->getBody()); @@ -69,7 +67,7 @@ public function testSendReturnsResponse() public function testGetSetsCorrectMethod() { - $response = $this->request->get('http://example.com'); + $response = $this->request->get('http://example.com'); $this->assertEquals('get', $this->request->getMethod()); diff --git a/tests/HTTP/Files/FileCollectionTest.php b/tests/HTTP/Files/FileCollectionTest.php index 1bd584f06abf..b62f0c19f9ac 100644 --- a/tests/HTTP/Files/FileCollectionTest.php +++ b/tests/HTTP/Files/FileCollectionTest.php @@ -1,17 +1,17 @@ -assertNull($files->all()); } @@ -23,19 +23,19 @@ public function testAllReturnsValidSingleFile() $_FILES = [ 'userfile' => [ 'name' => 'someFile.txt', - 'type' => 'text/plain', - 'size' => '124', - 'tmp_name' => '/tmp/myTempFile.txt', - 'error' => 0 + 'type' => 'text/plain', + 'size' => '124', + 'tmp_name' => '/tmp/myTempFile.txt', + 'error' => 0 ] ]; - $collection = new \CodeIgniter\HTTP\Files\FileCollection(); + $collection = new FileCollection(); $files = $collection->all(); $this->assertEquals(1, count($files)); $file = array_shift($files); - $this->assertTrue($file instanceof \CodeIgniter\HTTP\Files\UploadedFile); + $this->assertTrue($file instanceof UploadedFile); $this->assertEquals('someFile.txt', $file->getName()); $this->assertEquals(124, $file->getSize()); @@ -55,7 +55,7 @@ public function testAllReturnsValidMultipleFilesSameName() ] ]; - $collection = new \CodeIgniter\HTTP\Files\FileCollection(); + $collection = new FileCollection(); $files = $collection->all(); $this->assertEquals(1, count($files)); $this->assertEquals('userfile', key($files)); @@ -64,7 +64,7 @@ public function testAllReturnsValidMultipleFilesSameName() $this->assertEquals(2, count($files)); $file = $files[0]; - $this->assertTrue($file instanceof \CodeIgniter\HTTP\Files\UploadedFile); + $this->assertTrue($file instanceof UploadedFile); $this->assertEquals('fileA.txt', $file->getName()); $this->assertEquals('/tmp/fileA.txt', $file->getTempName()); @@ -95,13 +95,13 @@ public function testAllReturnsValidMultipleFilesDifferentName() ], ]; - $collection = new \CodeIgniter\HTTP\Files\FileCollection(); + $collection = new FileCollection(); $files = $collection->all(); $this->assertEquals(2, count($files)); $this->assertEquals('userfile1', key($files)); $file = array_shift($files); - $this->assertTrue($file instanceof \CodeIgniter\HTTP\Files\UploadedFile); + $this->assertTrue($file instanceof UploadedFile); $this->assertEquals('fileA.txt', $file->getName()); $this->assertEquals('/tmp/fileA.txt', $file->getTempName()); @@ -110,7 +110,7 @@ public function testAllReturnsValidMultipleFilesDifferentName() $this->assertEquals(124, $file->getSize()); $file = array_pop($files); - $this->assertTrue($file instanceof \CodeIgniter\HTTP\Files\UploadedFile); + $this->assertTrue($file instanceof UploadedFile); $this->assertEquals('fileB.txt', $file->getName()); $this->assertEquals('/tmp/fileB.txt', $file->getTempName()); @@ -152,7 +152,7 @@ public function testAllReturnsValidSingleFileNestedName() ] ]; - $collection = new \CodeIgniter\HTTP\Files\FileCollection(); + $collection = new FileCollection(); $files = $collection->all(); $this->assertEquals(1, count($files)); $this->assertEquals('userfile', key($files)); @@ -160,7 +160,7 @@ public function testAllReturnsValidSingleFileNestedName() $this->assertTrue(isset($files['userfile']['foo']['bar'])); $file = $files['userfile']['foo']['bar']; - $this->assertTrue($file instanceof \CodeIgniter\HTTP\Files\UploadedFile); + $this->assertTrue($file instanceof UploadedFile); $this->assertEquals('fileA.txt', $file->getName()); $this->assertEquals('/tmp/fileA.txt', $file->getTempName()); @@ -183,7 +183,7 @@ public function testHasFileWithSingleFile() ] ]; - $collection = new \CodeIgniter\HTTP\Files\FileCollection(); + $collection = new FileCollection(); $this->assertTrue($collection->hasFile('userfile')); $this->assertFalse($collection->hasFile('foo')); @@ -210,7 +210,7 @@ public function testHasFileWithMultipleFilesWithDifferentNames() ], ]; - $collection = new \CodeIgniter\HTTP\Files\FileCollection(); + $collection = new FileCollection(); $this->assertTrue($collection->hasFile('userfile1')); $this->assertTrue($collection->hasFile('userfile2')); @@ -249,7 +249,7 @@ public function testHasFileWithSingleFileNestedName() ] ]; - $collection = new \CodeIgniter\HTTP\Files\FileCollection(); + $collection = new FileCollection(); $this->assertTrue($collection->hasFile('userfile')); $this->assertTrue($collection->hasFile('userfile.foo')); @@ -272,7 +272,7 @@ public function testErrorString() $expected = 'The file "someFile.txt" exceeds your upload_max_filesize ini directive.'; - $collection = new \CodeIgniter\HTTP\Files\FileCollection(); + $collection = new FileCollection(); $file = $collection->getFile('userfile'); $this->assertEquals($expected, $file->getErrorString()); diff --git a/tests/HTTP/HeaderTest.php b/tests/HTTP/HeaderTest.php index 6b209ddb9a0e..cdc5fcd7652d 100644 --- a/tests/HTTP/HeaderTest.php +++ b/tests/HTTP/HeaderTest.php @@ -1,14 +1,13 @@ -assertEquals($name, $header->getName()); $this->assertEquals($value, $header->getValue()); diff --git a/tests/HTTP/IncomingRequestTest.php b/tests/HTTP/IncomingRequestTest.php index c77337023ac3..26d914d6ec04 100644 --- a/tests/HTTP/IncomingRequestTest.php +++ b/tests/HTTP/IncomingRequestTest.php @@ -1,9 +1,8 @@ -request = new \CodeIgniter\HTTP\IncomingRequest(new App(), new URI()); + $this->request = new IncomingRequest(new App(), new URI()); $_POST = $_GET = $_SERVER = $_REQUEST = $_ENV = $_COOKIE = $_SESSION = []; } @@ -21,7 +20,7 @@ public function setUp() public function testCanGrabGetVars() { - $_GET['TEST'] = 5; + $_GET['TEST'] = 5; $this->assertEquals(5, $this->request->getGet('TEST')); $this->assertEquals(null, $this->request->getGEt('TESTY')); diff --git a/tests/HTTP/MessageTest.php b/tests/HTTP/MessageTest.php index 3ef33cbf7ee4..539df568bf0c 100644 --- a/tests/HTTP/MessageTest.php +++ b/tests/HTTP/MessageTest.php @@ -1,6 +1,6 @@ -message = new \CodeIgniter\HTTP\Message(); + $this->message = new Message(); } //-------------------------------------------------------------------- @@ -17,7 +17,7 @@ public function setUp() public function tearDown() { $this->message = null; - unset($this->message); + unset($this->message); } //-------------------------------------------------------------------- @@ -47,8 +47,8 @@ public function testCanGrabSingleHeader() $header = $this->message->getHeader('Host'); - $this->assertTrue($header instanceof \CodeIgniter\HTTP\Header); - $this->assertEquals('daisyduke.com', $header->getValue()); + $this->assertTrue($header instanceof Header); + $this->assertEquals('daisyduke.com', $header->getValue()); } //-------------------------------------------------------------------- @@ -65,7 +65,7 @@ public function testCaseInsensitveGetHeader() public function testCanSetHeaders() { - $this->message->setHeader('first', 'kiss'); + $this->message->setHeader('first', 'kiss'); $this->message->setHeader('second', ['black', 'book']); $this->assertEquals('kiss', $this->message->getHeader('FIRST')->getValue()); @@ -98,7 +98,7 @@ public function testCanRemoveHeader() public function testCanAppendHeader() { - $this->message->setHeader('accept', ['json', 'html']); + $this->message->setHeader('accept', ['json', 'html']); $this->message->appendHeader('Accept', 'xml'); @@ -120,7 +120,7 @@ public function testCanPrependHeader() public function testSetProtocolWorks() { - $this->message->setProtocolVersion('1.1'); + $this->message->setProtocolVersion('1.1'); $this->assertEquals('1.1', $this->message->getProtocolVersion()); } @@ -130,7 +130,7 @@ public function testSetProtocolWorks() public function testSetProtocolThrowsExceptionWithInvalidProtocol() { $this->setExpectedException('InvalidArgumentException'); - $this->message->setProtocolVersion('1.2'); + $this->message->setProtocolVersion('1.2'); } //-------------------------------------------------------------------- @@ -139,7 +139,7 @@ public function testBodyBasics() { $body = 'a strange little fellow.'; - $this->message->setBody($body); + $this->message->setBody($body); $this->assertEquals($body, $this->message->getBody()); } @@ -155,8 +155,8 @@ public function testCanHaveMultipleHeadersWithSameName() $this->assertTrue(is_array($headers)); $this->assertEquals(2, count($headers)); - $this->assertTrue($headers[0] instanceof \CodeIgniter\HTTP\Header); - $this->assertTrue($headers[1] instanceof \CodeIgniter\HTTP\Header); + $this->assertTrue($headers[0] instanceof Header); + $this->assertTrue($headers[1] instanceof Header); $this->assertEquals('foo1', $headers[0]->getValueLine()); $this->assertEquals('foo2', $headers[1]->getValueLine()); } diff --git a/tests/HTTP/NegotiateTest.php b/tests/HTTP/NegotiateTest.php index 8e4e9b52edbf..a4bdc6d7e5d5 100644 --- a/tests/HTTP/NegotiateTest.php +++ b/tests/HTTP/NegotiateTest.php @@ -1,6 +1,8 @@ -request = new \CodeIgniter\HTTP\Request(new \Config\App()); + $this->request = new Request(new App()); - $this->negotiate = new \CodeIgniter\HTTP\Negotiate($this->request); + $this->negotiate = new Negotiate($this->request); } //-------------------------------------------------------------------- @@ -130,4 +132,4 @@ public function testAcceptLanguageBasics() } //-------------------------------------------------------------------- -} \ No newline at end of file +} diff --git a/tests/HTTP/RequestTest.php b/tests/HTTP/RequestTest.php index b3fb6e2cef6f..05a9a0e6e18a 100644 --- a/tests/HTTP/RequestTest.php +++ b/tests/HTTP/RequestTest.php @@ -1,6 +1,8 @@ -request = new \CodeIgniter\HTTP\Request(new \Config\App()); + $this->request = new Request(new App()); } //-------------------------------------------------------------------- public function ipAddressChecks() { - return [ - 'empty' => [false, ''], - 'zero' => [false , 0], - 'large_ipv4' => [false, '256.256.256.999', 'ipv4'], - 'good_ipv4' => [true, '100.100.100.0', 'ipv4'], - 'good_default' => [true, '100.100.100.0'], - 'zeroed_ipv4' => [true, '0.0.0.0'], - 'large_ipv6' => [false, 'h123:0000:0000:0000:0000:0000:0000:0000', 'ipv6'], - 'good_ipv6' => [true, '2001:0db8:85a3:0000:0000:8a2e:0370:7334'], - 'confused_ipv6' => [false, '255.255.255.255', 'ipv6'], - ]; + return [ + 'empty' => [false, ''], + 'zero' => [false , 0], + 'large_ipv4' => [false, '256.256.256.999', 'ipv4'], + 'good_ipv4' => [true, '100.100.100.0', 'ipv4'], + 'good_default' => [true, '100.100.100.0'], + 'zeroed_ipv4' => [true, '0.0.0.0'], + 'large_ipv6' => [false, 'h123:0000:0000:0000:0000:0000:0000:0000', 'ipv6'], + 'good_ipv6' => [true, '2001:0db8:85a3:0000:0000:8a2e:0370:7334'], + 'confused_ipv6' => [false, '255.255.255.255', 'ipv6'], + ]; } //-------------------------------------------------------------------- @@ -43,7 +45,7 @@ public function testValidIPAddress($expected, $address, $type=null) public function testMethodReturnsRightStuff() { - $this->assertEquals('', $this->request->getMethod()); + $this->assertEquals('', $this->request->getMethod()); $_SERVER['REQUEST_METHOD'] = 'GET'; diff --git a/tests/HTTP/ResponseTest.php b/tests/HTTP/ResponseTest.php index 368200360d5d..584f0093e5d9 100644 --- a/tests/HTTP/ResponseTest.php +++ b/tests/HTTP/ResponseTest.php @@ -1,12 +1,14 @@ -setStatusCode(200); @@ -17,7 +19,7 @@ public function testCanSetStatusCode() public function testSetStatusCodeThrowsExceptionForBadCodes() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $this->setExpectedException('InvalidArgumentException'); $response->setStatusCode(54322); @@ -28,7 +30,7 @@ public function testSetStatusCodeThrowsExceptionForBadCodes() public function testSetStatusCodeSetsReason() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $response->setStatusCode(200); @@ -39,7 +41,7 @@ public function testSetStatusCodeSetsReason() public function testCanSetCustomReasonCode() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $response->setStatusCode(200, 'Not the mama'); @@ -50,7 +52,7 @@ public function testCanSetCustomReasonCode() public function testRequiresMessageWithUnknownStatusCode() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $this->setExpectedException('InvalidArgumentException', 'Unknown HTTP status code provided with no message'); $response->setStatusCode(115); @@ -60,7 +62,7 @@ public function testRequiresMessageWithUnknownStatusCode() public function testRequiresMessageWithSmallStatusCode() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $this->setExpectedException('InvalidArgumentException', '95 is not a valid HTTP return status code'); $response->setStatusCode(95); @@ -70,7 +72,7 @@ public function testRequiresMessageWithSmallStatusCode() public function testRequiresMessageWithLargeStatusCode() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $this->setExpectedException('InvalidArgumentException', '695 is not a valid HTTP return status code'); $response->setStatusCode(695); @@ -80,7 +82,7 @@ public function testRequiresMessageWithLargeStatusCode() public function testExceptionThrownWhenNoStatusCode() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $this->setExpectedException('BadMethodCallException', 'HTTP Response is missing a status code'); $response->getStatusCode(); @@ -90,7 +92,7 @@ public function testExceptionThrownWhenNoStatusCode() public function testSetStatusCodeInterpretsReason() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $response->setStatusCode(300); @@ -101,7 +103,7 @@ public function testSetStatusCodeInterpretsReason() public function testSetStatusCodeSavesCustomReason() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $response->setStatusCode(300, 'My Little Pony'); @@ -112,7 +114,7 @@ public function testSetStatusCodeSavesCustomReason() public function testGetReasonReturnsEmptyStringWithNoStatus() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $this->assertEquals('', $response->getReason()); } @@ -121,12 +123,12 @@ public function testGetReasonReturnsEmptyStringWithNoStatus() public function testSetDateRemembersDateInUTC() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $response->setDate(DateTime::createFromFormat('Y-m-d', '2000-03-10')); $date = DateTime::createFromFormat('Y-m-d', '2000-03-10'); - $date->setTimezone(new \DateTimeZone('UTC')); + $date->setTimezone(new DateTimeZone('UTC')); $header = $response->getHeaderLine('Date'); @@ -137,7 +139,7 @@ public function testSetDateRemembersDateInUTC() public function testSetContentType() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $response->setContentType('text/json'); @@ -148,7 +150,7 @@ public function testSetContentType() public function testNoCache() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $response->noCache(); @@ -159,15 +161,15 @@ public function testNoCache() public function testSetCache() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $date = date('r'); $options = [ 'etag' => '12345678', - 'last-modified' => $date, - 'max-age' => 300, - 'must-revalidate' + 'last-modified' => $date, + 'max-age' => 300, + 'must-revalidate' ]; $response->setCache($options); @@ -181,12 +183,12 @@ public function testSetCache() public function testSetLastModifiedWithDateTimeObject() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $response->setLastModified(DateTime::createFromFormat('Y-m-d', '2000-03-10')); $date = DateTime::createFromFormat('Y-m-d', '2000-03-10'); - $date->setTimezone(new \DateTimeZone('UTC')); + $date->setTimezone(new DateTimeZone('UTC')); $header = $response->getHeaderLine('Last-Modified'); @@ -197,7 +199,7 @@ public function testSetLastModifiedWithDateTimeObject() public function testRedirectSetsDefaultCodeAndLocationHeader() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $response->redirect('example.com'); @@ -210,7 +212,7 @@ public function testRedirectSetsDefaultCodeAndLocationHeader() public function testRedirectSetsCode() { - $response = new Response(new \Config\App()); + $response = new Response(new App()); $response->redirect('example.com', 'auto', 307); diff --git a/tests/HTTP/URITest.php b/tests/HTTP/URITest.php index 6c123652b787..ed0b0050b3f3 100644 --- a/tests/HTTP/URITest.php +++ b/tests/HTTP/URITest.php @@ -1,8 +1,6 @@ - ['./path/to/nowhere', '/path/to/nowhere'], 'start-double' => ['../path/to/nowhere', '/path/to/nowhere'], 'decoded' => ['../%41path', '/Apath'], - 'encoded' => ['/path^here', '/path%5Ehere'], + 'encoded' => ['/path^here', '/path%5Ehere'], ]; } @@ -318,7 +316,7 @@ public function testAuthorityRemovesDefaultPorts($scheme, $port) public function testSetAuthorityReconstitutes() { - $authority = 'me@foo.com:3000'; + $authority = 'me@foo.com:3000'; $uri = new URI(); $uri->setAuthority($authority); @@ -367,9 +365,9 @@ public function defaultResolutions() { return [ ['g', 'http://a/b/c/g'], - ['g/', 'http://a/b/c/g/'], - ['/g', 'http://a/g'], - ['#s', 'http://a/b/c/d#s'], + ['g/', 'http://a/b/c/g/'], + ['/g', 'http://a/g'], + ['#s', 'http://a/b/c/d#s'], ]; } @@ -382,7 +380,7 @@ public function testResolveRelativeURI($rel, $expected) { $base = 'http://a/b/c/d'; - $uri = new URI($base); + $uri = new URI($base); $new = $uri->resolveRelativeURI($rel); diff --git a/tests/Hooks/HooksTest.php b/tests/Hooks/HooksTest.php index b9075ac1f9d2..2c66001a11b8 100644 --- a/tests/Hooks/HooksTest.php +++ b/tests/Hooks/HooksTest.php @@ -1,6 +1,4 @@ -psr4 = [ 'App\Libraries' => '/application/somewhere', 'App' => '/application', - 'Blog' => '/modules/blog' + 'Blog' => '/modules/blog' ]; - $this->loader = new MockLoader($config); + $this->loader = new MockLoader($config); $this->loader->setFiles([ APPPATH.'index.php', APPPATH.'Views/index.php', - APPPATH.'Views/admin/users/create.php', - '/modules/blog/Views/index.php', - '/modules/blog/Views/admin/posts.php' + APPPATH.'Views/admin/users/create.php', + '/modules/blog/Views/index.php', + '/modules/blog/Views/admin/posts.php' ]); } @@ -91,7 +93,7 @@ public function testLocateFileReplacesFolderNameLegacy() public function testLocateFileCanFindNamespacedView() { - $file = '\Blog\index'; + $file = '\Blog\index'; $expected = '/modules/blog/Views/index.php'; @@ -120,4 +122,3 @@ public function testLocateFileReturnsEmptyWithBadNamespace() //-------------------------------------------------------------------- } - diff --git a/tests/Log/LoggerTest.php b/tests/Log/LoggerTest.php index 568a0dd70711..0acf15e40f17 100644 --- a/tests/Log/LoggerTest.php +++ b/tests/Log/LoggerTest.php @@ -1,24 +1,23 @@ -handlers = null; $this->setExpectedException('RuntimeException', 'LoggerConfig must provide at least one Handler.'); @@ -75,7 +74,7 @@ public function testLogActuallyLogs() public function testLogDoesnotLogUnhandledLevels() { $config = new LoggerConfig(); - $config->handlers['TestHandler']['handles'] = ['critical']; + $config->handlers['CodeIgniter\Log\Handlers\TestHandler']['handles'] = ['critical']; $logger = new Logger($config); @@ -210,7 +209,7 @@ public function testLogInterpolatesFileAndLine() $_ENV['foo'] = 'bar'; // For whatever reason, this will often be the class/function instead of file and line. - $expected = 'DEBUG - '.date('Y-m-d').' --> Test message LoggerTest testLogInterpolatesFileAndLine'; + $expected = 'DEBUG - '.date('Y-m-d').' --> Test message CodeIgniter\Log\LoggerTest testLogInterpolatesFileAndLine'; $logger->log('debug', 'Test message {file} {line}'); diff --git a/tests/Router/RouteCollectionTest.php b/tests/Router/RouteCollectionTest.php index 7201d3403243..714798d6d7a2 100644 --- a/tests/Router/RouteCollectionTest.php +++ b/tests/Router/RouteCollectionTest.php @@ -1,8 +1,6 @@ -setDefaultController('godzilla'); $this->assertEquals('godzilla', $routes->getDefaultController()); @@ -196,7 +194,7 @@ public function testSetDefaultMethodStoresIt() public function testTranslateURIDashesWorks() { - $routes = new RouteCollection(); + $routes = new RouteCollection(); $routes->setTranslateURIDashes(true); $this->assertEquals(true, $routes->shouldTranslateURIDashes()); @@ -216,7 +214,7 @@ public function testAutoRouteStoresIt() public function testGroupingWorks() { - $routes = new RouteCollection(); + $routes = new RouteCollection(); $routes->group('admin', function($routes) { @@ -270,7 +268,7 @@ public function testGroupSetsOptions() public function testHostnameOption() { - $_SERVER['HTTP_HOST'] = 'example.com'; + $_SERVER['HTTP_HOST'] = 'example.com'; $routes = new RouteCollection(); @@ -297,7 +295,7 @@ public function testResourcesScaffoldsCorrectly() $expected = [ 'photos' => '\Photos::listAll', - 'photos/(.*)' => '\Photos::show/$1' + 'photos/(.*)' => '\Photos::show/$1' ]; $this->assertEquals($expected, $routes->getRoutes()); @@ -595,7 +593,7 @@ public function testReverseRoutingThrowsExceptionWithBadParamTypes() public function testNamedRoutes() { - $routes = new RouteCollection(); + $routes = new RouteCollection(); $routes->add('users', 'Users::index', ['as' => 'namedRoute']); @@ -619,7 +617,7 @@ public function testNamedRoutesFillInParams() public function testAddRedirect() { - $routes = new RouteCollection(); + $routes = new RouteCollection(); $routes->addRedirect('users', 'Users::index', 307); @@ -635,4 +633,4 @@ public function testAddRedirect() //-------------------------------------------------------------------- -} \ No newline at end of file +} diff --git a/tests/Router/RouterTest.php b/tests/Router/RouterTest.php index fa53e4c73fdd..b1bab84fe816 100644 --- a/tests/Router/RouterTest.php +++ b/tests/Router/RouterTest.php @@ -1,9 +1,6 @@ -collection = new \CodeIgniter\Router\RouteCollection(); + $this->collection = new RouteCollection(); $routes = [ 'users' => 'Users::index', @@ -181,4 +178,4 @@ public function testAutoRouteFindsControllerWithSubfolder() } //-------------------------------------------------------------------- -} \ No newline at end of file +} diff --git a/tests/Security/SecurityTest.php b/tests/Security/SecurityTest.php index 7ebe3fa985be..d76cf2d53695 100644 --- a/tests/Security/SecurityTest.php +++ b/tests/Security/SecurityTest.php @@ -1,6 +1,4 @@ -CSRFHash; - return $this; + return $this; } //-------------------------------------------------------------------- @@ -18,9 +16,14 @@ public function CSRFSetCookie(\CodeIgniter\HTTP\RequestInterface $request) } +use Config\MockAppConfig; +use CodeIgniter\HTTP\IncomingRequest; +use CodeIgniter\HTTP\Request; +use CodeIgniter\HTTP\URI; + //-------------------------------------------------------------------- -class SecurityTest extends CIUnitTestCase { +class SecurityTest extends \CIUnitTestCase { public function setUp() { @@ -60,7 +63,7 @@ public function testCSRFVerifySetsCookieWhenNotPOST() $_SERVER['REQUEST_METHOD'] = 'GET'; - $security->CSRFVerify(new \CodeIgniter\HTTP\Request(new MockAppConfig())); + $security->CSRFVerify(new Request(new MockAppConfig())); $this->assertEquals($_COOKIE['csrf_cookie_name'], $security->getCSRFHash()); } @@ -72,7 +75,7 @@ public function testCSRFVerifyAllowsWhitelistedURLs() $white_uri = 'http://example.com'; $security = new MockSecurity(new MockAppConfig()); - $request = new \CodeIgniter\HTTP\IncomingRequest(new MockAppConfig(), new \CodeIgniter\HTTP\URI($white_uri)); + $request = new IncomingRequest(new MockAppConfig(), new URI($white_uri)); // Post will get us to the check. // Invalid matching fields should throw error or return false. @@ -89,7 +92,7 @@ public function testCSRFVerifyAllowsWhitelistedURLs() public function testCSRFVerifyThrowsExceptionOnNoMatch() { $security = new MockSecurity(new MockAppConfig()); - $request = new \CodeIgniter\HTTP\IncomingRequest(new MockAppConfig(), new \CodeIgniter\HTTP\URI('http://badurl.com')); + $request = new IncomingRequest(new MockAppConfig(), new URI('http://badurl.com')); $_SERVER['REQUEST_METHOD'] = 'POST'; $_POST['csrf_test_name'] = '8b9218a55906f9dcc1dc263dce7f005a'; @@ -106,7 +109,7 @@ public function testCSRFVerifyThrowsExceptionOnNoMatch() public function testCSRFVerifyReturnsSelfOnMatch() { $security = new MockSecurity(new MockAppConfig()); - $request = new \CodeIgniter\HTTP\IncomingRequest(new MockAppConfig(), new \CodeIgniter\HTTP\URI('http://badurl.com')); + $request = new IncomingRequest(new MockAppConfig(), new URI('http://badurl.com')); $_SERVER['REQUEST_METHOD'] = 'POST'; $_POST['csrf_test_name'] = '8b9218a55906f9dcc1dc263dce7f005a'; @@ -132,4 +135,4 @@ public function testSanitizeFilename() //-------------------------------------------------------------------- -} \ No newline at end of file +} diff --git a/tests/View/ViewTest.php b/tests/View/ViewTest.php index e4e7a6a312fe..f7ed83b39378 100644 --- a/tests/View/ViewTest.php +++ b/tests/View/ViewTest.php @@ -2,7 +2,7 @@ use CodeIgniter\View\View; -class ViewTest extends CIUnitTestCase +class ViewTest extends \CIUnitTestCase { protected $loader; protected $viewsDir; diff --git a/tests/_support/CIUnitTestCase.php b/tests/_support/CIUnitTestCase.php index e13a4b5f10be..cf523e2d1af0 100644 --- a/tests/_support/CIUnitTestCase.php +++ b/tests/_support/CIUnitTestCase.php @@ -1,5 +1,7 @@ [ + 'CodeIgniter\Log\Handlers\TestHandler' => [ /* * The log levels that this handler will handle. diff --git a/tests/_support/Config/MockAppConfig.php b/tests/_support/Config/MockAppConfig.php index be5149fd7df4..4280562559e0 100644 --- a/tests/_support/Config/MockAppConfig.php +++ b/tests/_support/Config/MockAppConfig.php @@ -1,4 +1,4 @@ -