The BookModerationSyncTest::testModerationStateSync
test is failing with a TypeError:
TypeError: Drupal\book\BookOutlineStorage::loadBookChildren(): Argument #1 ($pid) must be of type int, null given, called in /builds/project/book_moderation_sync/src/Hook/BookModerationHooks.php on line 64
This error occurs when the loadBookChildren()
method is called with a null
value for the $pid
parameter, which expects an integer.
Steps to Reproduce
- Run the
BookModerationSyncTest
test suite.
- Observe the failure in the
testModerationStateSync
test.
Expected Behavior
The test should pass, and the moderation states of books and chapters should be synchronized correctly.
Actual Behavior
The test fails with a TypeError
because the $pid
argument passed to loadBookChildren()
is null
.
Proposed Solution
The issue likely stems from the book or chapter not being properly registered in the book structure, resulting in a null
book ID. Possible fixes include:
- Adding validation to ensure the book ID is not
null
before calling loadBookChildren()
.
- Ensuring the book and chapter are correctly created and linked in the test setup.
- Adding debugging logs to trace the source of the
null
value.
Additional Information
- Drupal Version: 11.1.0
- PHP Version: 8.3.15
- Module Version: book_moderation_sync (1.0.x)
- Relevant Files:
tests/src/Functional/BookModerationSyncTest.php
src/Hook/BookModerationHooks.php
- Error Logs: Available in the CI artifacts (junit.xml, Apache logs).
Workaround
As a temporary workaround, you can add a check in BookModerationHooks.php
to ensure the book ID is not null
:
if ($bookId === null) {
throw new \InvalidArgumentException('Book ID cannot be null.');
}
$children = $bookOutlineStorage->loadBookChildren($bookId);
Related Issues
None found at this time.