-
Couldn't load subscription status.
- Fork 117
chore: init test-utils #343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #343 +/- ##
============================================
- Coverage 80.83% 79.36% -1.47%
- Complexity 1502 1737 +235
============================================
Files 128 133 +5
Lines 6183 7203 +1020
============================================
+ Hits 4998 5717 +719
- Misses 1185 1486 +301 Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
|
LGTM! One thing you'll need to do is add it to the gitsplit file. I'll then create a destination repo in opentelemetry-php we can point packagist to. |
|
@brettmc added a pointer to |
OpenTelemetry Test Utilities
This package provides testing utilities for OpenTelemetry PHP instrumentations. It includes tools to help test and validate trace structures, span relationships, and other OpenTelemetry-specific functionality.
Features
TraceStructureAssertionTrait
The
TraceStructureAssertionTraitprovides methods to assess if spans match an expected trace structure. It's particularly useful for testing complex trace hierarchies and relationships between spans.Key features:
Requirements
Usage
TraceStructureAssertionTrait
Add the trait to your test class:
Array-Based Interface
Use the
assertTraceStructuremethod to verify trace structures using an array-based approach:The
assertTraceStructuremethod takes the following parameters:$spans: An array or ArrayObject of spans (typically from an InMemoryExporter)$expectedStructure: An array defining the expected structure of the trace$strict(optional): Whether to perform strict matching (all attributes must match)Fluent Interface
Use the
assertTracemethod to verify trace structures using a fluent, chainable interface:The fluent interface provides the following methods:
TraceAssertion:
hasRootSpan(string|Constraint $name): Assert that the trace has a root span with the given namehasRootSpans(int $count): Assert that the trace has the expected number of root spansinStrictMode(): Enable strict mode for all assertionsSpanAssertion:
withKind(int|Constraint $kind): Assert that the span has the expected kindwithAttribute(string $key, mixed|Constraint $value): Assert that the span has an attribute with the expected key and valuewithAttributes(array $attributes): Assert that the span has the expected attributeswithStatus(int|Constraint $code, string|Constraint|null $description = null): Assert that the span has the expected statushasEvent(string|Constraint $name): Assert that the span has an event with the expected namehasChild(string|Constraint $name): Assert that the span has a child span with the expected namehasChildren(int $count): Assert that the span has the expected number of childrenend(): Return to the parent assertionSpanEventAssertion:
withAttribute(string $key, mixed|Constraint $value): Assert that the event has an attribute with the expected key and valuewithAttributes(array $attributes): Assert that the event has the expected attributesend(): Return to the parent span assertionUsing PHPUnit Matchers
You can use PHPUnit constraints/matchers for more flexible assertions with both interfaces:
Array-Based Interface with Matchers
Fluent Interface with Matchers
Supported PHPUnit matchers include:
StringContainsfor partial string matchingRegularExpressionfor pattern matchingIsIdenticalfor strict equalityIsEqualfor loose equalityIsTypefor type checkingCallbackfor custom validation logic