ConnectionStub throws error when fetchAll is called on execute.

Created on 16 May 2024, 6 months ago
Updated 5 July 2024, 5 months ago

Problem/Motivation

I'm trying to test a service that uses the connection service.
Call:

$query->execute()->fetchAll();

Test

TestHelpers::service('database', (new ConnectionStub()));
    TestHelpers::service('cache.data', (new CacheBackendInterfaceStub()));
    $customColors = TestHelpers::service('custom_colors.get_colors', initService: TRUE);

Note that the cacheBackendInterfaceStub is a partial stub from πŸ“Œ What is the proper way to inject the cache backend? Needs review

Error

There was 1 error:

1) Drupal\Tests\custom_colors\Unit\customColorsTest::testGetColors
Error: Call to a member function fetchAll() on array

/var/www/html/web/modules/custom/custom_colors/src/customColors.php:70
/var/www/html/web/modules/custom/custom_colors/tests/src/Unit/customColorsTest.php:40
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:729
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php:685
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestSuite.php:685
/var/www/html/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:651
/var/www/html/vendor/phpunit/phpunit/src/TextUI/Command.php:146
/var/www/html/vendor/phpunit/phpunit/src/TextUI/Command.php:99
/var/www/html/vendor/bin/phpunit:122

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

1.4

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States nicxvan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024