2

I have set up the PHPunit Framework for testing and upon running a simple test I am getting a TypeError below:

SampleTest::testTrueAssertsToTrue
TypeError: Argument 3 passed to 
SebastianBergmann\GlobalState\Snapshot::__construct() must be of the type boolean, null given, called in /usr/share/php/PHPUnit/Framework/TestCase.php on line 2412

My test case is below:

class SampleTest extends \PHPUnit_Framework_TestCase
{

  public function testTrueAssertsToTrue()
  {
    $this->assertTrue(true);
  }

}

The PHPunit version is ^6.2 and below is the configuration XML file:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
         colors="true"
         verbose="true"
         stopOnFailure="false">
      <testsuites>
        <testsuite name ="Test suite">
          <directory>tests</directory>
        </testsuite>
      </testsuites>
</phpunit>

Please help I have searched online whole day and I cant find a solution.

2
  • 1
    Please, share with us your PHPUnit version and OS... I wasn't able to reproduce your error, maybe a misconfiguration? Commented Jun 14, 2017 at 13:45
  • hi. I am using linux and I have edited my question and added the xml configuration file, the PHPUnit version is 6.2 Commented Jun 14, 2017 at 14:00

1 Answer 1

3

Because you're using phpunit 6.2, \PHPUnit_Framework_TestCase has been removed and you should be instead extending the namespaced PHPUnit\Framework\TestCase

<?php

use PHPUnit\Framework\TestCase;

class SampleTest extends TestCase
{

  public function testTrueAssertsToTrue()
  {
    $this->assertTrue(true);
  }

}

You can verify the successful build here on travis-ci:

https://travis-ci.org/scratchers/phpunit6truetest/builds/242989226

Sign up to request clarification or add additional context in comments.

2 Comments

thanx. it worked. i had actually gone back to using the prev version. After your solution the error is gone but its now saying "No tests executed!"...its like its not recognizing my test files. how can i fix this?
Hmm sounds like you either moved it out of the tests folder, changed your phpunit.xml, or function name doesn't start with test

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.