Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
DatabaseHandler::push()assumed thatModel::insert()always returns a job ID. In realityModel::insert()returnsint|string|falseand returnsfalsewhen the insert cannot be performed (for example, when the statement fails or abeforeInsertcallback aborts it).Because the guard only checked
$jobId === 0, afalsereturn value fell through toQueuePushResult::success($jobId), whose parameter is declared asint. That raised aTypeErrorinstead of returning a proper failure result, and thequeue:jobPushedevent was emitted for a job that was never stored.Changes
src/Handlers/DatabaseHandler.phpfalse,0and non-numeric values as a failed insert: emitqueue:jobPushFailedand returnQueuePushResult::failure('Failed to insert job into the database.').intbefore assigning it to theQueueJobentity and before callingQueuePushResult::success(), so the value always matches the declared types.Testing
Added two cases to
tests/DatabaseHandlerTest.php:testPushWhenModelReturnsFalse()— afalsereturn from the model produces a failed result with the expected error message and no job ID, does not emitqueue:jobPushedand does emitqueue:jobPushFailed.testPushWhenModelReturnsZero()—0keeps the previous behaviour (failure result,jobPushFailedemitted, nojobPushed).Both tests use an event-listener reset in
tearDown()so the events of one test cannot leak into another.Verified locally on PHP 8.5 with PHPUnit 11.5: