Welcome Guest, Not a member yet? Register   Sign In
Issue with HTTP Feature Testing
#1

(This post was last modified: 05-26-2021, 11:58 AM by stopz.)

I'll try to be as short with this as i can: so I have a test file with contents:

PHP Code:
<?php

namespace MyName\MyPackage;

use 
CodeIgniter\Test\DatabaseTestTrait;
use 
CodeIgniter\Test\FeatureTestCase;
use 
CodeIgniter\Test\FeatureTestTrait;

class 
EndpointTest extends FeatureTestCase
{
    use DatabaseTestTrait;
    use FeatureTestTrait;

    protected $namespace 'MyName\MyPackage';
    protected $basePath VENDORPATH 'myname/mypackage/src/Database';

    public function testEndpoints()
    {
        $resp $this->get('mycontroller/amethod');
        $resp->assertStatus(200'Endpoint responds.'); // works

        $resp $this->get('mycontroller/amethod', [
            'token' => 'some-token'
        ]);

        // i have also tried:
        // $resp = $this->get('mycontroller/amethod?token=some-token'); // same exact result as above.

        die();
    }


Within the controller i have a simple check right now just to get parsed query string array:

PHP Code:
<?php

namespace MyName\MyPackage\Controllers;

use 
App\Controllers\BaseController;

class 
Mycontroller extends BaseController
{
    public function amethod()
    {
        if (! isset($_GET['token']))
        {
            print_r($_GET);
            var_dump($this->request);

            die(); // this triggers, thus i get no 'token' from my test.
        }
    }


Now i run tests via composer run-script test and results are:

Quote:Array() // this is the $_GET array.

object(CodeIgniter\HTTP\IncomingRequest)#103 (20) {
  ["enableCSRF":protected]=> bool(false)
  ["uri"]=> object(CodeIgniter\HTTP\URI)#105 (14) {
    ["uriString":protected]=> NULL
    ["segments":protected]=> array(2) {
      [0]=> string(8) "mycontroller"
      [1]=> string(7) "amethod"
    }
    ["scheme":protected]=> string(5) "https"
    ["user":protected]=> NULL
    ["password":protected]=> NULL
    ["host":protected]=> string(19) "localhost"
    ["port":protected]=> NULL
    ["path":protected]=> string(16) "mycontroller/amethod"
    ["fragment":protected]=> string(0) ""
    ["query":protected]=> array(0) {} // An empty query was sent?
...

Any ideas what i should try or is there a thing that you see right away that is wrong with my code? Any help Helps!
Reply


Messages In This Thread
Issue with HTTP Feature Testing - by stopz - 05-26-2021, 11:14 AM
RE: Issue with HTTP Feature Testing - by stopz - 05-27-2021, 03:40 AM
RE: Issue with HTTP Feature Testing - by MGatner - 05-27-2021, 08:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB