Closed minchao closed 2 years ago
I installed ubuntu somehow and now I can enter PHPUnit commands. But I'm still not sure about Linux commands. It will take a long time to understand. I hope I can check it with GitHub action for the time being.
@satopian This is the convenience brought by Continuous Integration (GitHub Actions).
@minchao
./vendor/bin/phpunit
PHPUnit 9.5.20
Runtime: PHP 8.1.6
Configuration: /mnt/c/~/220607/Petit_Note/phpunit.xml
.............. 14 / 14 (100%)
Time: 00:00.167, Memory: 6.00 MB
OK (14 tests, 14 assertions)
I managed to test it locally. Thank you.
@minchao I was researching the test method for the time being, and somehow I understood it. But maybe it's time to rewrite the function. At that time, if I can't rewrite the phpunit test description myself, I may not be able to maintain this test. I'm still investigating, so maybe I'm just bearish, but I'll tell you.
@satopian Please let me know if there is anything you do not understand. 😃
@minchao I add functions, exchange arguments, increase / decrease. At that time, I am not confident that I will properly investigate and rewrite the relevant part. Sometimes I don't know the code I wrote myself, but if a third party writes the code, it's more likely to be even more incomprehensible. I can get a rough understanding from the PHPUnit manual. However, I'm not sure if phpUnit can be used for future development. Maintenance seems to be more difficult than I expected. The biggest problem is my poor development ability.
@minchao If I can't maintain it myself, I might discard this test. Or I may continue to use it. Can you accept it? I can try using what I can, but I can't maintain PHPUnit test if that can be a burden to me.
@satopian Sure! Please feel free to use them.
@minchao Thank you for understanding. is this all of it? If so, merge.
@satopian Yes! with the basic tests, we can start refactoring with a safety net.
@minchao I didn't know what to do when the error handling in functions.php came in, so I asked in the code review. I'm sorry to have just told you, but please tell me if it is within the range you can understand. If it's a problem that can't be helped, please let me know. thank you.
when the error handling in functions.php came in
@satopian I don't understand the meaning of the paragraph. Could you please provide more detailed information?
@minchao
//縮小表示
function image_reduction_display($w,$h,$max_w,$max_h){
if(!is_numeric($w)||!is_numeric($h)){
return error('失敗しました');//Rewrite; from return to error ('失敗しました')l
}
Rewrite the function to. The return value is not returned and an error message is displayed by echo.
ob_start();
~
$buf = ob_get_contents();
ob_end_clean();
It may be possible to use these to prevent echo, but if you assume that an echo error is included in the return value at the same time as other reduced display test patterns, how can you fix it? The question is whether it can be determined that the expected value has returned.
@satopian The error() uses the exit() function, which means script will terminate immediately, so we can't test it. Usually I would use trigger_error() to trigger a user error and handle by set_error_handler().
@minchao I decided to avoid putting error () in the function tested by PHPUnit Test. All I have to do is look at the return value and write the error error () in index.php ... Thank you.
THIS PR IS WORKING IN THE PROCESS.
Running PHPUnit in local development environment
Install PHPUnit 9.5 by composer (requires PHP 7.3+):
Run tests:
[Optional] Run tests with code coverage report (requires Xdebug extension):
You will find the HTML report in the
code-coverage-report
folder.Open the
code-coverage-report/index.html
file with a browser and you will see:Click
functions.php
link for more detailed report.The green lines mean this line was executed in a test.
References