Welcome Guest, Not a member yet? Register   Sign In
Unit testing issue
#1

I'm exploring unit testing with CI4 and have run into a problem. I can test controllers without problem but any attempt to test a model or the database throws an 'headers already sent by (output started at /var/vendor/phpunit/phpunit/src/Util/Printer.php'.

I've done some digging and nothing I've found online seems applicable. I'm using the \CIDatabaseTestCase as descrideb in https://codeigniter4.github.io/userguide...abase.html, and nothing seems to be working. Any ideas?
Reply
#2

The actual code I'm running, if it helps:

PHP Code:
namespace App\Models;

use 
CodeIgniter\Test\CIDatabaseTestCase;
use 
CodeIgniter\Test\ControllerTester;

class 
GroupClassesTest extends CIDatabaseTestCase{
  use 
ControllerTester;
  public function setup():void{
    parent::setUp();
  }
  public function tearDown():void{
    parent::tearDown();
  }
  /**
   * Test the database.
   * This is throwing the 'headers already sent' error
   */
  public function testTheDatabase(){
    $this->seeInDatabase('classes', [
      'id' => 3
    
]);
  }

Reply
#3

I have same error in featuretest but cant find any solution Sad
Reply
#4

What version of the framework are both of you using? Are you running just the test in question, or a suite that includes this one? How are you bootstrapping your tests?

If you haven’t already I highly recommend checking out codeigniter4projects/ProjectTests and ModuleTests for unit testing with the framework.
Reply
#5

(01-29-2020, 06:02 PM)MGatner Wrote: What version of the framework are both of you using? Are you running just the test in question, or a suite that includes this one? How are you bootstrapping your tests?

If you haven’t already I highly recommend checking out codeigniter4projects/ProjectTests and ModuleTests for unit testing with the framework.

For me, I'm using 4.0.0-rc.3 and yes, that is the only test I'm running right now. Bootstrapping-wise I'm using the default phpunit.xml.dist unless I made a change I've forgotten about. I'll check again first thing tomorrow and post here if I've updated.

Thanks for the pointers - I'd not seen the link to the projects repository in the user guide source installation directory repositories file. I'll definitely check those out!
Reply
#6

(This post was last modified: 01-31-2020, 09:54 AM by hatsat32.)

(01-29-2020, 06:02 PM)MGatner Wrote: What version of the framework are both of you using? Are you running just the test in question, or a suite that includes this one? How are you bootstrapping your tests?

If you haven’t already I highly recommend checking out codeigniter4projects/ProjectTests and ModuleTests for unit testing with the framework.

4.0.0-rc.3

I am tryint test my controllers with featuretest.
Reply
#7

(01-29-2020, 06:02 PM)MGatner Wrote: If you haven’t already I highly recommend checking out codeigniter4projects/ProjectTests and ModuleTests for unit testing with the framework.
Thanks for the pointer - I pulled down the repo and looked through it and I've get everything up and running now! I appreciate the help.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB