Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class 'PHPUnit_Framework_TestCase' not found

Tags:

travis-ci

This error occurs on my public build project: https://travis-ci.org/byjg/authuser/jobs/211336643

I ran locally using php 7.0 and php 7.1 on my Ubuntu and this problem does not occur.

Travis runs successful on PHP 5.6

Could you help me?

like image 502
Joao Gilberto Magalhaes Avatar asked Mar 15 '17 13:03

Joao Gilberto Magalhaes


1 Answers

There is a difference between namespace structure between PHPUnit <6 and PHPUnit 6.

You may consider the following solution for backward compatibility:

// backward compatibility
if (!class_exists('\PHPUnit\Framework\TestCase') &&
    class_exists('\PHPUnit_Framework_TestCase')) {
    class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase');
}

The old PHPUnit versions use \PHPUnit_Framework_TestCase but the new one uses \PHPUnit\Framework\TestCase. With the backward compatibility applied you can use the class name that is compatible with the new version of PHPUnit (i.e. \PHPUnit\Framework\TestCase) and it is going to work also with older versions.

Update In order to cover support for PHP 5.3 you have to remove a \ character before the alias class, i.e.

class_alias('\PHPUnit_Framework_TestCase', 'PHPUnit\Framework\TestCase');
like image 142
Robson Avatar answered Sep 23 '22 11:09

Robson