Unit testing with PHPUnit: Testing a Calculator: Addition (8/10)

preview_player
Показать описание

Official site

Twitter
Рекомендации по теме
Комментарии
Автор

In version 7.2 or later of php, the argument to the count function must be arrays or implement the Countable Interface.
So you can do following.
- if (count($this->operands) === 0)
+ if ($this->operands === null)

TheTakahiro
Автор

If you are facing this issue
count(): Parameter must be an array or an object that implements Countable
add this to the test => $addition->setOperands([]);

acehanks
Автор

The errorchecking fom php7.4 onwards are much stricter than it was, errors that maybe were catchable back in the day, aren't anymore, or the error checking for unintialized types have been much stricter. I have pondered this piece of code for at least 20 minutes, (maybe an hour, it was fun!), to make it work. For any reason, I think the correct declaration of the $operands array in the Additon class to be:

protected array $operands = [] ;


That way, you actually fix any uninitialized errors, and you know you have something that is countable to relate to, and the test will still succeed, without any unmaskable run-time error comes through with a higher priority before the exception is sent, and received.

tommybollman
Автор

Your lessons are awesome. Thank you very much.

СергейБайдуж
Автор

hello i'm getting Fatal error: Call to undefined method i'm still using php 5.6 any suggestion?

aditiarahman
Автор

i am getting error undefined method
additionTest:expectException method

konarchprasad
Автор

Your lessons actually very useful and easy to understand, thanks, but I'm wondering why you do not using autocomplete of your IDE? I mean you can write only "pubf {methodName}" and press "tab" and IDE will generate all words for you, same with namespaces and class names

valentinsaik