Currently I need to place at the beginning of the every test cases
<?php declare(strict_types=1);
Are there better place to auto set this when running Phpunit
Unfortunately, there is no way to set this directive globally or per directory. You have to add this line at the begining of each file.
See this rfc for more details on why there is no global option https://wiki.php.net/rfc/scalar_type_hints_v5#strict_types_declare_directive
By default (as answered already and as well in the duplicate Q&A material on the topic) strict types are disabled and you need to enable them.
With vanilla PHP this needs to be done on the per file level.
Utilities like PHP-CS-Fixer or nikic/TypeUtil can do the heavy lifting for you if you don't want to edit all files manually.
That default behavior could be changed by modifying the PHP core (or by using the php-strict
PHP extension which makes enabled the default, which is what you ask for - but that extension does not compile right now for 7.0 - 7.2 b/c it is incompatible and requires heavier fixing).
So a practical way right now is perhaps to go with tooling. And perhaps monkey patching a la Patchwork2 works, but I never tried it w/ declare(...)
.