Open
Description
Describe the bug
In Distributor, I am attempting to mock a function to return an empty array:
However, the return value is coming back as NULL
.
As an alternative approach, I've tried setting the return
attribute as a callable function(){ return []; }
but the same issue occurs.
To Reproduce
- As a reduced test case, create the test:
public function test_return_empty_array() { $post_id = 1; \WP_Mock::userFunction( '\Distributor\Utils\peters_test_function', [ 'return' => [], ] ); $this->assertSame( [], \Distributor\Utils\peters_test_function( $post_id ) ); }
- Run
phpunit --filter test_return_empty_array
- PHP Unit will throw a failure:
PHPUnit 8.5.26 #StandWithUkraine F 1 / 1 (100%) Time: 2.11 seconds, Memory: 18.00 MB There was 1 failure: 1) Distributor\SubscriptionsTest::test_return_empty_array Failed asserting that null is identical to Array &0 (). /vagrant/content/plugins/distributor/tests/php/SubscriptionsTest.php:18 /vagrant/content/plugins/distributor/vendor/10up/wp_mock/php/WP_Mock/Tools/TestCase.php:307 phpvfscomposer:///vagrant/content/plugins/distributor/vendor/phpunit/phpunit/phpunit:97
Expected behavior
Returned values retain type.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- PHPUnit 8.5.26
- PHP 7.4.30
- OS: Ubuntu 22.04 LTS
Additional context
Metadata
Metadata
Assignees
Labels
No labels