Skip to content

Commit 16c7de6

Browse files
committed
Fixed MySli tests
1 parent fae2f7d commit 16c7de6

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Instrumentation/MySqli/src/MySqliTracker.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ private function splitQueries(string $sql)
165165
{
166166
// Normalize line endings to \n
167167
$sql = preg_replace("/\r\n|\n\r|\r/", "\n", $sql);
168+
if ($sql === null) {
169+
return [];
170+
}
168171

169172
$queries = [];
170173
$buffer = '';
@@ -174,6 +177,10 @@ private function splitQueries(string $sql)
174177
$singleQuotes = 0;
175178
$doubleQuotes = 0;
176179

180+
if (empty($tokens)) {
181+
return [];
182+
}
183+
177184
foreach ($tokens as $token) {
178185
if ($token === '') {
179186
continue;

src/Instrumentation/MySqli/tests/Integration/MySqliInstrumentationTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ public function test_mysqli_query_procedural(): void
310310

311311
}
312312

313+
/**
314+
* @requires PHP >= 8.2
315+
*/
313316
public function test_mysqli_execute_query_objective(): void
314317
{
315318
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
@@ -368,12 +371,17 @@ public function test_mysqli_execute_query_objective(): void
368371
$this->assertDatabaseAttributesForAllSpans($offset);
369372
}
370373

374+
/**
375+
* @requires PHP >= 8.2
376+
*/
371377
public function test_mysqli_execute_query_procedural(): void
372378
{
373379
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
374380

375381
$mysqli = mysqli_connect($this->mysqlHost, $this->user, $this->passwd, $this->database);
376382

383+
$this->assertInstanceOf(mysqli::class, $mysqli);
384+
377385
$offset = 0;
378386
$this->assertSame('mysqli_connect', $this->storage->offsetGet($offset)->getName());
379387

@@ -542,6 +550,7 @@ public function test_mysqli_multi_query_procedural(): void
542550
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
543551

544552
$mysqli = mysqli_connect($this->mysqlHost, $this->user, $this->passwd, $this->database);
553+
$this->assertInstanceOf(mysqli::class, $mysqli);
545554

546555
$offset = 0;
547556
$this->assertSame('mysqli_connect', $this->storage->offsetGet($offset)->getName());
@@ -709,12 +718,14 @@ public function test_mysqli_prepare_procedural(): void
709718
mysqli_report(MYSQLI_REPORT_ERROR);
710719

711720
$mysqli = new mysqli($this->mysqlHost, $this->user, $this->passwd, $this->database);
721+
$this->assertInstanceOf(mysqli::class, $mysqli);
712722

713723
$offset = 0;
714724
$this->assertSame('mysqli::__construct', $this->storage->offsetGet($offset)->getName());
715725

716726
try {
717727
$stmt = mysqli_prepare($mysqli, 'SELECT * FROM otel_db.users');
728+
$this->assertInstanceOf(mysqli_stmt::class, $stmt);
718729

719730
$offset++;
720731
$this->assertSame('mysqli_prepare', $this->storage->offsetGet($offset)->getName());
@@ -833,6 +844,7 @@ public function test_mysqli_transaction_rollback_procedural(): void
833844
mysqli_report(MYSQLI_REPORT_ERROR);
834845

835846
$mysqli = mysqli_connect($this->mysqlHost, $this->user, $this->passwd, $this->database);
847+
$this->assertInstanceOf(mysqli::class, $mysqli);
836848

837849
$offset = 0;
838850
$this->assertSame('mysqli_connect', $this->storage->offsetGet($offset)->getName());
@@ -865,6 +877,8 @@ public function test_mysqli_transaction_rollback_procedural(): void
865877
$language_code = 'FR';
866878
$native_speakers = 'Unknown';
867879
$stmt = mysqli_prepare($mysqli, 'INSERT INTO language(Code, Speakers) VALUES (?,?)');
880+
$this->assertInstanceOf(mysqli_stmt::class, $stmt);
881+
868882
$offset++;
869883
$this->assertSame('mysqli_prepare', $this->storage->offsetGet($offset)->getName());
870884
$this->assertAttributes($offset, [
@@ -976,6 +990,7 @@ public function test_mysqli_transaction_commit_procedural(): void
976990
mysqli_report(MYSQLI_REPORT_ERROR);
977991

978992
$mysqli = mysqli_connect($this->mysqlHost, $this->user, $this->passwd, $this->database);
993+
$this->assertInstanceOf(mysqli::class, $mysqli);
979994

980995
$offset = 0;
981996
$this->assertSame('mysqli_connect', $this->storage->offsetGet($offset)->getName());
@@ -1008,6 +1023,8 @@ public function test_mysqli_transaction_commit_procedural(): void
10081023
$language_code = 'FR';
10091024
$native_speakers = 66000002;
10101025
$stmt = mysqli_prepare($mysqli, 'INSERT INTO language(Code, Speakers) VALUES (?,?)');
1026+
$this->assertInstanceOf(mysqli_stmt::class, $stmt);
1027+
10111028
$offset++;
10121029
$this->assertSame('mysqli_prepare', $this->storage->offsetGet($offset)->getName());
10131030
$this->assertAttributes($offset, [

0 commit comments

Comments
 (0)