-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add better coercion with deprecations
Emit a deprecation notice if a suspect value is being coerced for a known type. This will be escalated to an exception in v2.
- Loading branch information
Showing
9 changed files
with
633 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Squirrel\Entities\Tests; | ||
|
||
trait ErrorHandlerTrait | ||
{ | ||
protected mixed $phpunitErrorHandler = null; | ||
protected array $listOfDeprecations = []; | ||
|
||
protected function allowDeprecations(): void | ||
{ | ||
$this->listOfDeprecations = []; | ||
|
||
$this->phpunitErrorHandler = \set_error_handler(function (int $severity, string $message, string $filepath, int $line): bool { | ||
if ($severity === E_USER_DEPRECATED) { | ||
$this->listOfDeprecations[] = $message; | ||
} else { | ||
return ($this->phpunitErrorHandler)($severity, $message, $filepath, $line); | ||
} | ||
|
||
return true; | ||
}); | ||
} | ||
|
||
protected function getDeprecationList(): array | ||
{ | ||
return $this->listOfDeprecations; | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
if ($this->phpunitErrorHandler !== null) { | ||
\restore_error_handler(); | ||
} | ||
|
||
parent::tearDown(); | ||
} | ||
} |
Oops, something went wrong.