Nebojsa Nebojsa
Nebojsa Nebojsa

Reputation: 1459

CakePHP2-PHP8 - Tests with PHPUnit ^9.5

I'm using CakePHP2-PHP8 version of this framework, which can be found on this github

If someone can help me, I have problems with PHPUnit testing. Please correct me if I am doing something wrong, but when i try to run Cake tests I found several problems. Let's use command from CakePHP Doc:

Console/cake test app AllTests

Issue 1.
First I receive an error from main test dispatcher file /cakephp2-php8/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php method loadTestFramework. Problem is that method try to check does class exist with old PHPUnit namespace in class name with underscores PHPUnit_Framework_TestCase. That is for older versions of PHPUnit (such as 4.*)

line 152 - if (class_exists('PHPUnit_Framework_TestCase')) {...

It is working when i replace old classname with this PHPUnit\Framework\TestCase. That is the problem in multiple files, and on some places PHPUnit classnames are written ok with new namespace. So problem is in that mix where some files use new namespace with class name and some files use old style I needed to replace all old namespaces with new one (approximate 65 times inside 13 files) Here is the list of files: enter image description here

Issue 2.
After all replaces, I found that some CakeTest classes extends final PHPUnit classes which cause an error. Than I edited my vendor/phpunit I removed final prefix in these classes:

Class CakeTestLoader cannot extend final class PHPUnit\Runner\StandardTestSuiteLoader in lib/Cake/TestSuite/CakeTestLoader.php

Class CakeTestRunner cannot extend final class PHPUnit\TextUI\TestRunner in lib/Cake/TestSuite/CakeTestCase.php

Issue 3.
Than I get error for method declaration which is not compatible with extended PHPUnit class methods inside Cake/TestSuite/CakeTestCase.php:

Declaration of CakeTestCase::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp()

Declaration of CakeTestCase::tearDown() must be compatible with PHPUnit\Framework\TestCase::tearDown()

Here I also fix PHPUnit\Framework\TestCase instde vendor/phpunit.


After I fix all 3 issues my command for testing is working now Console/cake test app AllTests.

I think that this is not the right way to do because i made changes inside core framework files, and also changes inside vendor/phpunit directory.

Is there another way to run cake tests inside this framework?

Upvotes: 0

Views: 120

Answers (0)

Related Questions