Skip to content

test: Add unit tests for av_replace_placeholders - #28

Merged
matapatos merged 4 commits into
mainfrom
vibe/av-replace-placeholders-tests-e35ddd
Sep 11, 2026
Merged

matapatos merged 4 commits into
mainfrom
vibe/av-replace-placeholders-tests-e35ddd

Conversation

@matapatos

Copy link
Copy Markdown
Contributor

Summary

  • Add Ceedling C unit tests for av_replace_placeholders in src/helpers/av_error_messages.c, covering every placeholder ({field}, {value}, {expected}), multiple/adjacent occurrences, mixed placeholders, and the no-placeholder / non-placeholder edge cases.
  • Make the function unit-testable in isolation by extracting it into its own translation unit src/helpers/av_replace_placeholders.{c,h}, mirroring the existing av_value_to_string extraction pattern (commit 80cae46).
  • Route the remaining Zend internals it touches through mockable wrappers in av_wrappers.{c,h}: av_memnstr, av_string_alloc, av_string_truncate (reusing av_string_init/av_string_release).
  • Make build_union_type_string non-static (and drop its zend_always_inline) so the test can supply a hand-written stub for the {expected} provider.
  • Register the new source file in config.m4 and add string_alloc_stub / string_truncate_stub / memnstr_stub to the shared test support.

Verification

  • C toolchain (Ruby/Ceedling/PHP dev headers) is not available in this sandbox, so the Ceedling suite could not be run locally; CI runs ceedling (task test:unit) on PHP 8.2–8.5.
  • No tabs / trailing whitespace introduced; style follows the existing .clang-format (4-space indent, attached braces for non-function blocks).

mistral-vibe and others added 4 commits September 10, 2026 17:53
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>
@matapatos
matapatos marked this pull request as ready for review September 11, 2026 09:11
@matapatos
matapatos merged commit 1344169 into main Sep 11, 2026
1 of 5 checks passed
@matapatos
matapatos deleted the vibe/av-replace-placeholders-tests-e35ddd branch September 11, 2026 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants