From 0fdf7919980fff92d4952ff9c910c136c50ddc3e Mon Sep 17 00:00:00 2001 From: Andreas Leathley Date: Tue, 21 Jun 2022 10:30:26 +0200 Subject: [PATCH] More verbose deprecation messages Makes it easier to pinpoint the origin/cause of the deprecation. --- src/RepositoryReadOnly.php | 4 ++-- tests/RepositoryTest.php | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/RepositoryReadOnly.php b/src/RepositoryReadOnly.php index 674d1e0..d17f0b6 100644 --- a/src/RepositoryReadOnly.php +++ b/src/RepositoryReadOnly.php @@ -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': @@ -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), diff --git a/tests/RepositoryTest.php b/tests/RepositoryTest.php index 3ab5b09..e1db512 100644 --- a/tests/RepositoryTest.php +++ b/tests/RepositoryTest.php @@ -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], ); } @@ -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], ); } @@ -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], ); } @@ -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], ); } @@ -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], ); } @@ -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], ); } @@ -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], ); } @@ -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], ); }