test: Add unit tests for av_replace_placeholders - #28
Merged
Merged
Conversation
Add Ceedling C unit tests covering av_replace_placeholders for every
placeholder ({field}, {value}, {expected}), multiple/adjacent occurrences,
mixed placeholders and the no-placeholder and non-placeholder edge cases.
To make the function unit-testable in isolation:
- Move av_replace_placeholders into its own translation unit
(src/helpers/av_replace_placeholders.{c,h}) so tests link only that
minimal file plus av_value_to_string instead of the full av_error_messages.c
dependency graph.
- Route the remaining Zend internals it touches through mockable wrappers in
av_wrappers.{c,h}: av_memnstr, av_string_alloc, av_string_truncate (reusing
the existing av_string_init/release).
- Make build_union_type_string non-static (and drop its always_inline) so the
test can supply a hand-written stub for the {expected} provider, mirroring
the av_value_to_string extraction pattern.
- Register the new source file in config.m4.
- Add string_alloc_stub / string_truncate_stub / memnstr_stub to the shared
test support.
Co-authored-by: matapatos <matapatos@users.noreply.github.com>
Address the two failures reported by CI on PR #28: 1. Link error: undefined reference to `ap_php_snprintf`. Including av_replace_placeholders.h (-> av_structs.h -> php.h) transitively pulls in php.h, which redefines snprintf to ap_php_snprintf, an unresolved symbol in the Ceedling unit-test build. Replace snprintf-based long/double stubs with manual conversions so the test object no longer references it. Also drop the now-unused <stdlib.h> include. 2. Extension build warning (implicit declaration of php_memnstr in av_wrappers.c): add #include "php.h" so the wrapper's php_memnstr call has a visible prototype across all supported PHP versions. Also fix a clang-format violation reported by the lint job (empty tearDown body must stay on one line). Co-authored-by: matapatos <matapatos@users.noreply.github.com>
Co-authored-by: matapatos <matapatos@users.noreply.github.com>
…ction) Co-authored-by: matapatos <matapatos@users.noreply.github.com>
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.
Summary
av_replace_placeholdersinsrc/helpers/av_error_messages.c, covering every placeholder ({field},{value},{expected}), multiple/adjacent occurrences, mixed placeholders, and the no-placeholder / non-placeholder edge cases.src/helpers/av_replace_placeholders.{c,h}, mirroring the existingav_value_to_stringextraction pattern (commit80cae46).av_wrappers.{c,h}:av_memnstr,av_string_alloc,av_string_truncate(reusingav_string_init/av_string_release).build_union_type_stringnon-static (and drop itszend_always_inline) so the test can supply a hand-written stub for the{expected}provider.config.m4and addstring_alloc_stub/string_truncate_stub/memnstr_stubto the shared test support.Verification
ceedling(tasktest:unit) on PHP 8.2–8.5..clang-format(4-space indent, attached braces for non-function blocks).