-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a trait that checks to see if $this->exporter()->export() is avai…
…lable before trying to use it
- Loading branch information
1 parent
f85fca4
commit 0d6a9cd
Showing
5 changed files
with
42 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace SteveGrunwell\PHPUnit_Markup_Assertions\Constraints; | ||
|
||
/** | ||
* Trait that exposes an exportValue method that will attempt to use | ||
* {@see SebastianBergmann\Exporter\Exporter} when available. | ||
*/ | ||
trait ExporterTrait | ||
{ | ||
/** | ||
* Export a value to include it in error messages. | ||
* | ||
* If {@see SebastianBergmann\Exporter\Exporter} is available (as it is in modern versions of | ||
* PHPUnit), then it will be used. Otherwise, we'll do a simple var_export(). | ||
* | ||
* @param mixed $value The value to be exported. | ||
* | ||
* @return string A string representation of the value. | ||
*/ | ||
private function exportValue($value): string | ||
{ | ||
if (method_exists($this, 'exporter')) { | ||
return $this->exporter()->export($value); | ||
} | ||
|
||
return var_export($value, true); | ||
} | ||
} |
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