Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHPUnit] migrate ./tests source from PHPUnit 3.x to PHPUnit 9.5 vs Add PHPUnit 9 to Github actions tests (test success on php 8.0, comment on php 8.1) #240

Merged
merged 82 commits into from
Nov 1, 2022

Conversation

hungtrinh
Copy link

@hungtrinh hungtrinh commented Jul 8, 2022

Work done

  1. Use rector/rector + manual to migrate PHPUnit from 3.6 -> 9.5
  2. Temporarily disable some test suite not compatible with PHPUnit 9
  3. Apply PSR12 coding standard to ./tests folder
  4. Add PHPunit 9 job to Github actions tests

Testing

  1. on Docker env
docker run -e CI=true -t --rm -v $(pwd):/app jakzal/phpqa:php8.0-alpine phpunit --bootstrap /app/tests/TestHelper.php /app/tests/Zend/AllTests.php
  1. on localhost with php 8 - composer
composer install 
composer test

What next

  1. After merged this PR, i will make other PR - Add PHPUnit 9 run on php 8.1 to Github actions, that will show many deprecated message when run unit test on php 8.1
  2. Next i will make other PR to fix all depricated message showed when run phpunit 9.5 on php 8.1

@hungtrinh
Copy link
Author

@Shardj how do you think about this PR ?

@Shardj
Copy link
Owner

Shardj commented Jul 19, 2022

Upgrading PHPUnit is a slightly tricky one, might be time to bite the bullet on that though. What an immense PR

@kaktusas2598 thoughts?

@develart-projects
Copy link
Collaborator

+1, as tests are not working at all now.

@Shardj
Copy link
Owner

Shardj commented Oct 4, 2022

@develart-projects not sure what you mean, which bit is broken for you?

@develart-projects
Copy link
Collaborator

@develart-projects not sure what you mean, which bit is broken for you?

Run failed on PHP 8.1

@Shardj
Copy link
Owner

Shardj commented Oct 5, 2022

@develart-projects are you talking about your own tests or zf1-future's tests? What error are you getting?

@Jimbolino
Copy link
Collaborator

I think we should merge this.
There are currently no working automated unit tests on this project. (except for some basic linting)
This would be a good starting point.

phpunit 9 has a minimum requirement for php 7.3
So I ran it locally (via docker) on php 7.3 / 7.4 / 8.0 / 8.1 / 8.2 and results are as expected.


docker run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:7.3-cli php -d memory_limit=256M ./bin/phpunit --bootstrap tests/TestHelper.php tests/Zend/AllTests.php
Tests: 9275, Assertions: 39550, Errors: 4, Failures: 4, Skipped: 488, Incomplete: 9, Risky: 1.

docker run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:7.4-cli php -d memory_limit=256M ./bin/phpunit --bootstrap tests/TestHelper.php tests/Zend/AllTests.php
Tests: 9275, Assertions: 39550, Errors: 4, Failures: 4, Skipped: 488, Incomplete: 9, Risky: 1.

docker run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:8.0-cli php -d memory_limit=256M ./bin/phpunit --bootstrap tests/TestHelper.php tests/Zend/AllTests.php
Tests: 9275, Assertions: 39589, Failures: 1, Skipped: 489, Incomplete: 12.

docker run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:8.1-cli php -d memory_limit=256M ./bin/phpunit --bootstrap tests/TestHelper.php tests/Zend/AllTests.php
Tests: 9275, Assertions: 39312, Errors: 124, Failures: 1, Skipped: 490, Incomplete: 12.

docker run -it --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp phpdaily/php:8.2 php -d memory_limit=256M ./bin/phpunit --bootstrap tests/TestHelper.php tests/Zend/AllTests.php
Tests: 9275, Assertions: 30608, Errors: 2955, Failures: 4, Skipped: 448, Incomplete: 8.

So still some work to do, but at least we have something usable and future proof

@kaktusas2598
Copy link
Collaborator

I am currently testing this on our own platform, will come back with the results.

@Jimbolino
Copy link
Collaborator

kaktusas2598 any update on this?
php 8.2 is ready in a couple days, so it would be great if we have some future proof tests before that day

@kaktusas2598
Copy link
Collaborator

@Jimbolino I ran the builds on our private servers and they are passing for us, but I can't guarantee this will work for everyone though, do you have any resources available to this for yourself as well?

I think I will probably merge this anyway, agreed @Shardj ?

@Shardj
Copy link
Owner

Shardj commented Oct 31, 2022

@kaktusas2598 go for it

@kaktusas2598 kaktusas2598 merged commit 25e64b6 into Shardj:master Nov 1, 2022
@develart-projects
Copy link
Collaborator

develart-projects commented Nov 1, 2022

PHP8 - related problems are gone, getting this now:

"/usr/bin/php" "/usr/bin/phpunit" "--colors" "--log-junit" "/tmp/nb-phpunit-log.xml" "--configuration" "/usr/share/NetBeansProjects/ZF1-Future/tests/phpunit.xml" "/var/lib/snapd/snap/netbeans/69/netbeans/php/phpunit/NetBeansSuite.php"

PHP Fatal error:  Uncaught Error: Class "PHPUnit\Runner\Version" not found in /usr/share/NetBeansProjects/ZF1-Future/tests/TestHelper.php:29
Stack trace:
Fatal error: Uncaught Error: Class "PHPUnit\Runner\Version" not found in /usr/share/NetBeansProjects/ZF1-Future/tests/TestHelper.php on line 29

#0 /usr/share/php/PHPUnit/Util/Fileloader.php(52): include_once()
Error: Class "PHPUnit\Runner\Version" not found in /usr/share/NetBeansProjects/ZF1-Future/tests/TestHelper.php on line 29

Call Stack:
    0.0003     361416   1. {main}() /usr/bin/phpunit:0
    0.0075     377040   2. PHPUnit_TextUI_Command::main($exit = ???) /usr/bin/phpunit:50
#1 /usr/share/php/PHPUnit/Util/Fileloader.php(36): PHPUnit_Util_Fileloader::load('/usr/share/NetB...')
#2 /usr/share/php/PHPUnit/TextUI/Command.php(914): PHPUnit_Util_Fileloader::checkAndLoad('/usr/share/NetB...')
    0.0075     377152   3. PHPUnit_TextUI_Command->run($argv = [0 => '/usr/bin/phpunit', 1 => '--colors', 2 => '--log-junit', 3 => '/tmp/nb-phpunit-log.xml', 4 => '--configuration', 5 => '/usr/share/NetBeansProjects/ZF1-Future/tests/phpunit.xml', 6 => '/var/lib/snapd/snap/netbeans/69/netbeans/php/phpunit/NetBeansSuite.php'], $exit = TRUE) /usr/share/php/PHPUnit/TextUI/Command.php:116
    0.0075     377152   4. PHPUnit_TextUI_Command->handleArguments($argv = [0 => '/usr/bin/phpunit', 1 => '--colors', 2 => '--log-junit', 3 => '/tmp/nb-phpunit-log.xml', 4 => '--configuration', 5 => '/usr/share/NetBeansProjects/ZF1-Future/tests/phpunit.xml', 6 => '/var/lib/snapd/snap/netbeans/69/netbeans/php/phpunit/NetBeansSuite.php']) /usr/share/php/PHPUnit/TextUI/Command.php:127
#3 /usr/share/php/PHPUnit/TextUI/Command.php(739): PHPUnit_TextUI_Command->handleBootstrap('/usr/share/NetB...')
    0.0141     384080   5. PHPUnit_TextUI_Command->handleBootstrap($filename = '/usr/share/NetBeansProjects/ZF1-Future/tests/./TestHelper.php') /usr/share/php/PHPUnit/TextUI/Command.php:739
    0.0143     384160   6. PHPUnit_Util_Fileloader::checkAndLoad($filename = '/usr/share/NetBeansProjects/ZF1-Future/tests/./TestHelper.php') /usr/share/php/PHPUnit/TextUI/Command.php:914
#4 /usr/share/php/PHPUnit/TextUI/Command.php(127): PHPUnit_TextUI_Command->handleArguments(Array)
    0.0143     384256   7. PHPUnit_Util_Fileloader::load($filename = '/usr/share/NetBeansProjects/ZF1-Future/tests/TestHelper.php') /usr/share/php/PHPUnit/Util/Fileloader.php:36
#5 /usr/share/php/PHPUnit/TextUI/Command.php(116): PHPUnit_TextUI_Command->run(Array, true)
#6 /usr/bin/phpunit(50): PHPUnit_TextUI_Command::main()
#7 {main}
  thrown in /usr/share/NetBeansProjects/ZF1-Future/tests/TestHelper.php on line 29
    0.0145     385432   8. include_once('/usr/share/NetBeansProjects/ZF1-Future/tests/TestHelper.php') /usr/share/php/PHPUnit/Util/Fileloader.php:52


Variables in local scope (#8):
  $path = *uninitialized*
  $phpunitVersion = *uninitialized*
  $zfCoreLibrary = *uninitialized*
  $zfCoreTests = *uninitialized*
  $zfRoot = *uninitialized*

Done.

@hungtrinh
Copy link
Author

hungtrinh commented Nov 1, 2022

@develart-projects It's about to autoload problem, so please set phpunit binary path on netbean point to path_to_zf1_future/bin/phpunit or point to PHPUnit 9.5.21.phar downloaded on your computer

So result look like that

"/usr/bin/php8.0" "/home/trinhhung/Projects/zf1-future/bin/phpunit" "--colors" "--log-junit" "/tmp/nb-phpunit-log.xml" "--configuration" "/home/trinhhung/Projects/zf1-future/tests/phpunit.xml" "/home/trinhhung/Projects/zf1-future/tests/AllTests.php"

PHPUnit 9.5.21 #StandWithUkraine

.S.SSSSSSS...................................................   61 / 9281 (  0%)
.............................................................  122 / 9281 (  1%)
................S............................................  183 / 9281 (  1%)
.......................................................S.....  244 / 9281 (  2%)

But i think this way it's better

cd path_to_zf1_future
./bin/phpunit -c tests/phpunit.xml tests/Zend/AllTests.php

@develart-projects
Copy link
Collaborator

Finally got it running, thanks:
"/usr/bin/php" "/usr/share/NetBeansProjects/ZF1-Future/bin/phpunit" "--colors" "--log-junit" "/tmp/nb-phpunit-log.xml" "--configuration" "/usr/share/NetBeansProjects/ZF1-Future/tests/phpunit.xml" "/usr/share/NetBeansProjects/ZF1-Future/tests/AllTests.php"

Now I need to strip deprecation messages :)
PHP Deprecated: Function mcrypt_module_close() is deprecated in /usr/share/NetBeansProjects/ZF1-Future/library/Zend/Filter/Encrypt/Mcrypt.php on line 311

..writing that down here, so if anyone run into same troubles, google will help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants