-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31: Fix Client helpers bugs and add tests
- Loading branch information
Showing
11 changed files
with
291 additions
and
53 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
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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Buggregator\Trap\Client\TrapHandle; | ||
|
||
/** | ||
* @internal | ||
* @psalm-internal Buggregator\Trap\Client | ||
* @psalm-import-type SimpleStackTrace from StackTrace | ||
* @psalm-import-type StackTraceWithObjects from StackTrace | ||
*/ | ||
final class StaticState | ||
{ | ||
/** | ||
* @param SimpleStackTrace $stackTrace Simple stack trace without arguments and objects. | ||
* @param StackTraceWithObjects $stackTraceWithObjects Stack trace without arguments but with objects. | ||
*/ | ||
private function __construct( | ||
public array $stackTrace = [], | ||
public array $stackTraceWithObjects = [], | ||
) { | ||
} | ||
|
||
private static ?StaticState $value = null; | ||
|
||
/** | ||
* @param SimpleStackTrace|null $stackTrace | ||
* @param StackTraceWithObjects|null $stackTraceWithObjects | ||
*/ | ||
public static function new( | ||
array $stackTrace = null, | ||
array $stackTraceWithObjects = null, | ||
): self | ||
{ | ||
$new = new self( | ||
$stackTrace ?? StackTrace::stackTrace(provideObjects: false), | ||
$stackTraceWithObjects ?? StackTrace::stackTrace(provideObjects: true), | ||
); | ||
self::setState($new); | ||
return $new; | ||
} | ||
|
||
public static function setState(?self $state): void | ||
{ | ||
self::$value = $state; | ||
} | ||
|
||
public static function getValue(): ?StaticState | ||
{ | ||
return self::$value; | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Buggregator\Trap\Tests\Unit\Client; | ||
|
||
use Buggregator\Trap\Client\TrapHandle\Dumper; | ||
use Closure; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\VarDumper\Caster\ReflectionCaster; | ||
use Symfony\Component\VarDumper\Cloner\Data; | ||
use Symfony\Component\VarDumper\Cloner\VarCloner; | ||
use Symfony\Component\VarDumper\Dumper\DataDumperInterface; | ||
|
||
class Base extends TestCase | ||
{ | ||
protected static Data $lastData; | ||
protected static ?Closure $handler = null; | ||
|
||
protected function setUp(): void | ||
{ | ||
$cloner = new VarCloner(); | ||
/** @psalm-suppress InvalidArgument */ | ||
$cloner->addCasters(ReflectionCaster::UNSET_CLOSURE_FILE_INFO); | ||
$dumper = $this->getMockBuilder(DataDumperInterface::class) | ||
->getMock(); | ||
$dumper->expects($this->once()) | ||
->method('dump') | ||
->with( | ||
$this->callback(static function (Data $data): bool { | ||
static::$lastData = $data; | ||
return true; | ||
}) | ||
) | ||
->willReturnArgument(1); | ||
|
||
Dumper::setDumper($dumper); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
Dumper::setDumper(null); | ||
parent::tearDown(); | ||
} | ||
} |
Oops, something went wrong.