Skip to content

Commit 3e91955

Browse files
committed
remove replaced integration test cases
1 parent 1e6f064 commit 3e91955

File tree

1 file changed

+0
-163
lines changed

1 file changed

+0
-163
lines changed

src/Instrumentation/Laravel/tests/Integration/LaravelInstrumentationTest.php

Lines changed: 0 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -85,148 +85,6 @@ public function test_cache_log_db(): void
8585
$this->assertSame(json_encode(['test' => true]), $logRecord->getAttributes()->toArray()['context']);
8686
}
8787

88-
public function test_eloquent_operations(): void
89-
{
90-
// Assert storage is empty before interacting with the database
91-
$this->assertCount(0, $this->storage);
92-
93-
// Create the test_models table
94-
DB::statement('CREATE TABLE IF NOT EXISTS test_models (
95-
id INTEGER PRIMARY KEY AUTOINCREMENT,
96-
name TEXT,
97-
created_at DATETIME,
98-
updated_at DATETIME
99-
)');
100-
101-
$this->router()->get('/eloquent', function () {
102-
try {
103-
// Test create
104-
$created = TestModel::create(['name' => 'test']);
105-
106-
// Test find
107-
$found = TestModel::find($created->id);
108-
109-
// Test update
110-
$found->update(['name' => 'updated']);
111-
112-
// Test delete
113-
$found->delete();
114-
115-
return response()->json(['status' => 'ok']);
116-
} catch (\Exception $e) {
117-
return response()->json([
118-
'error' => $e->getMessage(),
119-
'trace' => $e->getTraceAsString(),
120-
], 500);
121-
}
122-
});
123-
124-
$response = $this->call('GET', '/eloquent');
125-
if ($response->status() !== 200) {
126-
$this->fail('Request failed: ' . $response->content());
127-
}
128-
$this->assertEquals(200, $response->status());
129-
130-
$eloquentSpans = $this->resolveEloquentOperationSpans();
131-
132-
// Sort spans by operation type to ensure consistent order
133-
usort($eloquentSpans, function ($a, $b) {
134-
$operations = ['create' => 0, 'find' => 1, 'update' => 2, 'delete' => 3];
135-
$aOp = $a->getAttributes()->get('laravel.eloquent.operation');
136-
$bOp = $b->getAttributes()->get('laravel.eloquent.operation');
137-
138-
return ($operations[$aOp] ?? 999) <=> ($operations[$bOp] ?? 999);
139-
});
140-
141-
// Create span
142-
$createSpan = array_values(array_filter($eloquentSpans, function ($span) {
143-
return $span->getAttributes()->get('laravel.eloquent.operation') === 'create';
144-
}))[0];
145-
$this->assertSame('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel::create', $createSpan->getName());
146-
$this->assertSame('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel', $createSpan->getAttributes()->get('laravel.eloquent.model'));
147-
$this->assertSame('test_models', $createSpan->getAttributes()->get('laravel.eloquent.table'));
148-
$this->assertSame('create', $createSpan->getAttributes()->get('laravel.eloquent.operation'));
149-
150-
// Find span
151-
$findSpan = array_values(array_filter($eloquentSpans, function ($span) {
152-
return $span->getAttributes()->get('laravel.eloquent.operation') === 'find';
153-
}))[0];
154-
$this->assertSame('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel::find', $findSpan->getName());
155-
$this->assertSame('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel', $findSpan->getAttributes()->get('laravel.eloquent.model'));
156-
$this->assertSame('test_models', $findSpan->getAttributes()->get('laravel.eloquent.table'));
157-
$this->assertSame('find', $findSpan->getAttributes()->get('laravel.eloquent.operation'));
158-
159-
// Update span
160-
$updateSpan = array_values(array_filter($eloquentSpans, function ($span) {
161-
return $span->getAttributes()->get('laravel.eloquent.operation') === 'update';
162-
}))[0];
163-
$this->assertSame('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel::update', $updateSpan->getName());
164-
$this->assertSame('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel', $updateSpan->getAttributes()->get('laravel.eloquent.model'));
165-
$this->assertSame('test_models', $updateSpan->getAttributes()->get('laravel.eloquent.table'));
166-
$this->assertSame('update', $updateSpan->getAttributes()->get('laravel.eloquent.operation'));
167-
168-
// Delete span
169-
$deleteSpan = array_values(array_filter($eloquentSpans, function ($span) {
170-
return $span->getAttributes()->get('laravel.eloquent.operation') === 'delete';
171-
}))[0];
172-
$this->assertSame('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel::delete', $deleteSpan->getName());
173-
$this->assertSame('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel', $deleteSpan->getAttributes()->get('laravel.eloquent.model'));
174-
$this->assertSame('test_models', $deleteSpan->getAttributes()->get('laravel.eloquent.table'));
175-
$this->assertSame('delete', $deleteSpan->getAttributes()->get('laravel.eloquent.operation'));
176-
}
177-
178-
public function test_eloquent_static_operations(): void
179-
{
180-
// Assert storage is empty before interacting with the database
181-
$this->assertCount(0, $this->storage);
182-
183-
// Create the test_models table
184-
DB::statement('CREATE TABLE IF NOT EXISTS test_models (
185-
id INTEGER PRIMARY KEY AUTOINCREMENT,
186-
name TEXT,
187-
created_at DATETIME,
188-
updated_at DATETIME
189-
)');
190-
191-
$this->router()->get('/eloquent', function () {
192-
try {
193-
// create record for Test destroy
194-
$created = TestModel::create(['name' => 'test']);
195-
196-
// Test destroy
197-
TestModel::destroy([$created->id]);
198-
199-
return response()->json(['status' => 'ok']);
200-
} catch (\Exception $e) {
201-
return response()->json([
202-
'error' => $e->getMessage(),
203-
'trace' => $e->getTraceAsString(),
204-
], 500);
205-
}
206-
});
207-
208-
$response = $this->call('GET', '/eloquent');
209-
if ($response->status() !== 200) {
210-
$this->fail('Request failed: ' . $response->content());
211-
}
212-
$this->assertEquals(200, $response->status());
213-
214-
$eloquentSpans = $this->resolveEloquentOperationSpans();
215-
216-
// Destroy span
217-
$destroySpans = array_values(array_filter($eloquentSpans, function ($span) {
218-
return $span->getAttributes()->get('laravel.eloquent.operation') === 'destroy';
219-
}));
220-
221-
$this->assertCount(1, $destroySpans);
222-
223-
$destroySpan = $destroySpans[0];
224-
$this->assertSame('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel::destroy', $destroySpan->getName());
225-
$this->assertSame('OpenTelemetry\Tests\Contrib\Instrumentation\Laravel\Fixtures\Models\TestModel', $destroySpan->getAttributes()->get('laravel.eloquent.model'));
226-
$this->assertSame('test_models', $destroySpan->getAttributes()->get('laravel.eloquent.table'));
227-
$this->assertSame('destroy', $destroySpan->getAttributes()->get('laravel.eloquent.operation'));
228-
}
229-
23088
public function test_low_cardinality_route_span_name(): void
23189
{
23290
$this->router()->get('/hello/{name}', fn () => null)->name('hello-name');
@@ -254,25 +112,4 @@ private function router(): Router
254112
/** @psalm-suppress PossiblyNullReference */
255113
return $this->app->make(Router::class);
256114
}
257-
258-
/**
259-
* @return array<int, \OpenTelemetry\SDK\Trace\ImmutableSpan>
260-
*/
261-
private function resolveEloquentOperationSpans(): array
262-
{
263-
// Verify spans for each Eloquent operation
264-
/** @var array<int, \OpenTelemetry\SDK\Trace\ImmutableSpan> $spans */
265-
$spans = array_values(array_filter(
266-
iterator_to_array($this->storage),
267-
fn ($item) => $item instanceof \OpenTelemetry\SDK\Trace\ImmutableSpan
268-
));
269-
270-
// Filter out SQL spans and keep only Eloquent spans
271-
$eloquentSpans = array_values(array_filter(
272-
$spans,
273-
fn ($span) => str_contains($span->getName(), '::')
274-
));
275-
276-
return $eloquentSpans;
277-
}
278115
}

0 commit comments

Comments
 (0)