Skip to content

Commit

Permalink
More verbose deprecation messages
Browse files Browse the repository at this point in the history
Makes it easier to pinpoint the origin/cause of the
deprecation.
  • Loading branch information
iquito committed Jun 21, 2022
1 parent 79f11e7 commit 0fdf791
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/RepositoryReadOnly.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ protected function castOneTableVariable(mixed $value, ?string $fieldName = null,
return Coerce::toString($value);
}
} catch (\TypeError $e) {
\trigger_error('Wrong type for ' . $fieldName . ' in query: ' . $e->getMessage(), E_USER_DEPRECATED);
\trigger_error('Wrong type for ' . $fieldName . ' in query for table ' . $this->config->getTableName() . ': ' . $e->getMessage(), E_USER_DEPRECATED);

switch ($this->objectTypes[$fieldName]) {
case 'int':
Expand Down Expand Up @@ -749,7 +749,7 @@ protected function castObjVariable(mixed $value, string $fieldName): bool|int|fl
),
};
} catch (\TypeError $e) {
\trigger_error('Wrong type for ' . $fieldName . ' in result: ' . $e->getMessage(), E_USER_DEPRECATED);
\trigger_error('Wrong type for ' . $fieldName . ' in result for table ' . $this->config->getTableName() . ': ' . $e->getMessage(), E_USER_DEPRECATED);

return match ($this->objectTypes[$fieldName]) {
'int' => \intval($value),
Expand Down
16 changes: 8 additions & 8 deletions tests/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2138,7 +2138,7 @@ public function testWrongTypeForStringInQuery(): void

$this->assertCount(1, $deprecationList);
$this->assertSame(
'Wrong type for lastName in query: Only integers and floats are alternative coerceable values for a string, given value: true',
'Wrong type for lastName in query for table example: Only integers and floats are alternative coerceable values for a string, given value: true',
$deprecationList[0],
);
}
Expand Down Expand Up @@ -2178,7 +2178,7 @@ public function testWrongTypeForIntInQuery(): void

$this->assertCount(1, $deprecationList);
$this->assertSame(
'Wrong type for number in query: Only numbers with no fractional part can be coerced from a string to an integer, given value: \'hello\'',
'Wrong type for number in query for table example: Only numbers with no fractional part can be coerced from a string to an integer, given value: \'hello\'',
$deprecationList[0],
);
}
Expand Down Expand Up @@ -2218,7 +2218,7 @@ public function testWrongTypeForFloatInQuery(): void

$this->assertCount(1, $deprecationList);
$this->assertSame(
'Wrong type for floatVal in query: Only numbers with no fractional part can be coerced from a string to a float, given value: \'hello\'',
'Wrong type for floatVal in query for table example: Only numbers with no fractional part can be coerced from a string to a float, given value: \'hello\'',
$deprecationList[0],
);
}
Expand Down Expand Up @@ -2258,7 +2258,7 @@ public function testWrongTypeForBoolInQuery(): void

$this->assertCount(1, $deprecationList);
$this->assertSame(
'Wrong type for isGreat in query: Only 0 and 1 are alternative coerceable values for a boolean, given value: \'hello\'',
'Wrong type for isGreat in query for table example: Only 0 and 1 are alternative coerceable values for a boolean, given value: \'hello\'',
$deprecationList[0],
);
}
Expand Down Expand Up @@ -2302,7 +2302,7 @@ public function testWrongTypeForStringInResult(): void

$this->assertCount(1, $deprecationList);
$this->assertSame(
'Wrong type for lastName in result: Only integers and floats are alternative coerceable values for a string, given value: true',
'Wrong type for lastName in result for table example: Only integers and floats are alternative coerceable values for a string, given value: true',
$deprecationList[0],
);
}
Expand Down Expand Up @@ -2346,7 +2346,7 @@ public function testWrongTypeForIntInResult(): void

$this->assertCount(1, $deprecationList);
$this->assertSame(
'Wrong type for number in result: Only numbers with no fractional part can be coerced from a string to an integer, given value: \'hello\'',
'Wrong type for number in result for table example: Only numbers with no fractional part can be coerced from a string to an integer, given value: \'hello\'',
$deprecationList[0],
);
}
Expand Down Expand Up @@ -2390,7 +2390,7 @@ public function testWrongTypeForFloatInResult(): void

$this->assertCount(1, $deprecationList);
$this->assertSame(
'Wrong type for floatVal in result: Only numbers with no fractional part can be coerced from a string to a float, given value: \'hello\'',
'Wrong type for floatVal in result for table example: Only numbers with no fractional part can be coerced from a string to a float, given value: \'hello\'',
$deprecationList[0],
);
}
Expand Down Expand Up @@ -2434,7 +2434,7 @@ public function testWrongTypeForBoolInResult(): void

$this->assertCount(1, $deprecationList);
$this->assertSame(
'Wrong type for isGreat in result: Only 0 and 1 are alternative coerceable values for a boolean, given value: \'hello\'',
'Wrong type for isGreat in result for table example: Only 0 and 1 are alternative coerceable values for a boolean, given value: \'hello\'',
$deprecationList[0],
);
}
Expand Down

0 comments on commit 0fdf791

Please sign in to comment.