CodeIgniter Forums
Problem with HTTP Feature Testing - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Problem with HTTP Feature Testing (/showthread.php?tid=74802)



Problem with HTTP Feature Testing - Poetawd - 11-07-2019

Hello All !

I found a really annoying problem... I don´t know if it is a BUG or a problem with my code.

I followed everything from the manual and made the following code :

PHP Code:
<?php namespace App\CI4\Controllers;

use 
CodeIgniter\Test\FeatureTestCase;


class 
HomeControllerTest extends FeatureTestCase
{

    public function 
setUp(): void
    
{
        
parent::setUp();
    }
    
    
public function tearDown(): void
    
{
        parent::tearDown();
    }

    public function 
testSimple()
    {
        
$test defined('APPPATH');
        
$this->assertTrue($test);
    }

    public function testShowHomeIndex()
    {

        $result $this->get('I/Page/Home/Index');            

        $this
->assertTrue($result->isOK());
    }

    public function testShowHomePage()
    {

        $result $this->get('I/Page/Home/Page');                

        $this
->assertTrue($result->isOK());
    }

    public function testShowHomeMain()
    {

        $result $this->get('home/main');        

        $this
->assertTrue($result->isOK());
    }

 
For this example my "Home" controller is located at app/i/page/Home.php  and it is acessible using the URL http://localhost:8080/i/page/home/index 

The problem is when running multiple tests ! Only the first one validates ! Just the first one. If I change the methods order, the first one will pass, the others wont.

Weird right ?

Code:
There were 2 errors:

1) App\HomeControllerTest::testShowHomePage
CodeIgniter\Exceptions\PageNotFoundException: Controller or its method is not found: App\Controllers\I\Page\::home

C:\Users\gabri\Documents\asist.com.br\system\Exceptions\PageNotFoundException.php:14
C:\Users\gabri\Documents\asist.com.br\system\CodeIgniter.php:911
C:\Users\gabri\Documents\asist.com.br\system\CodeIgniter.php:262
C:\Users\gabri\Documents\asist.com.br\system\Test\FeatureTestCase.php:173
C:\Users\gabri\Documents\asist.com.br\system\Test\FeatureTestCase.php:208
C:\Users\gabri\Documents\asist.com.br\tests\app\CodeIt4Me\Candidates\Controllers\candidatesHtmlControllerTest.php:36

2) App\HomeControllerTest::testShowHomeMain
CodeIgniter\Exceptions\PageNotFoundException: Controller or its method is not found: App\Controllers\I\Page\::home

C:\Users\gabri\Documents\asist.com.br\system\Exceptions\PageNotFoundException.php:14
C:\Users\gabri\Documents\asist.com.br\system\CodeIgniter.php:911
C:\Users\gabri\Documents\asist.com.br\system\CodeIgniter.php:262
C:\Users\gabri\Documents\asist.com.br\system\Test\FeatureTestCase.php:173
C:\Users\gabri\Documents\asist.com.br\system\Test\FeatureTestCase.php:208
C:\Users\gabri\Documents\asist.com.br\tests\app\CodeIt4Me\Candidates\Controllers\candidatesHtmlControllerTest.php:48


And If I change the order of the methods I have:

Code:
There were 2 errors:

1) App\HomeControllerTest::testShowHomeIndex
CodeIgniter\Exceptions\PageNotFoundException: Controller or its method is not found: App\Controllers\I\Page\::I

C:\Users\gabri\Documents\asist.com.br\system\Exceptions\PageNotFoundException.php:14
C:\Users\gabri\Documents\asist.com.br\system\CodeIgniter.php:911
C:\Users\gabri\Documents\asist.com.br\system\CodeIgniter.php:262
C:\Users\gabri\Documents\asist.com.br\system\Test\FeatureTestCase.php:173
C:\Users\gabri\Documents\asist.com.br\system\Test\FeatureTestCase.php:208
C:\Users\gabri\Documents\asist.com.br\tests\app\HomeControllerTest.php:37

2) App\HomeControllerTest::testShowHomeMain
CodeIgniter\Exceptions\PageNotFoundException: Controller or its method is not found: App\Controllers\I\Page\::home

C:\Users\gabri\Documents\asist.com.br\system\Exceptions\PageNotFoundException.php:14
C:\Users\gabri\Documents\asist.com.br\system\CodeIgniter.php:911
C:\Users\gabri\Documents\asist.com.br\system\CodeIgniter.php:262
C:\Users\gabri\Documents\asist.com.br\system\Test\FeatureTestCase.php:173
C:\Users\gabri\Documents\asist.com.br\system\Test\FeatureTestCase.php:208
C:\Users\gabri\Documents\asist.com.br\tests\app\HomeControllerTest.php:46



RE: Problem with HTTP Feature Testing - Poetawd - 11-07-2019

By the way... It works just fine if the Home.php controller is under the "Controller" folder....