Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

travis ci - Class 'PHPUnit_Framework_TestCase' not found

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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('PHPUnitFrameworkTestCase') &&
    class_exists('PHPUnit_Framework_TestCase')) {
    class_alias('PHPUnit_Framework_TestCase', 'PHPUnitFrameworkTestCase');
}

The old PHPUnit versions use PHPUnit_Framework_TestCase but the new one uses PHPUnitFrameworkTestCase. With the backward compatibility applied you can use the class name that is compatible with the new version of PHPUnit (i.e. PHPUnitFrameworkTestCase) 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', 'PHPUnitFrameworkTestCase');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...