Skip to content

Commit

Permalink
Fixed bug when trap()->return() function sent dumps twice
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Feb 16, 2024
1 parent 8817c0a commit f86fac5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/Client/TrapHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ public function once(): self
*/
public function return(int|string $key = 0): mixed
{
$this->haveToSend() and $this->sendDump();

if (\count($this->values) === 0) {
throw new \InvalidArgumentException('No values to return.');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Info
{
public const NAME = 'Buggregator Trap';
public const VERSION = '1.4.1';
public const VERSION = '1.4.3';
public const LOGO_CLI_COLOR = <<<CONSOLE
\e[44;97;1m \e[0m
\e[44;97;1m ▄█▀ ▀█▄ \e[0m
Expand Down
17 changes: 17 additions & 0 deletions tests/Unit/Client/TrapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

namespace Buggregator\Trap\Tests\Unit\Client;

use Buggregator\Trap\Client\TrapHandle\Counter;
use Buggregator\Trap\Client\TrapHandle\Dumper;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Dumper\DataDumperInterface;

final class TrapTest extends Base
{
public function testLabel(): void
Expand Down Expand Up @@ -74,6 +79,18 @@ public function testReturn(): void
$this->assertSame(42, \trap(42, 43)->return(10));
}

public function testReturnSendsDumpOnce(): void
{
$dumper = $this->getMockBuilder(DataDumperInterface::class)
->getMock();
$dumper->expects($this->once())
->method('dump')
->willReturnArgument(1);
Dumper::setDumper($dumper);

$this->assertSame(42, \trap(42)->return());
}

public static function provideTrapTimes(): iterable
{
yield 'no limit' => [0, [false, false, false, false, false]];
Expand Down

0 comments on commit f86fac5

Please sign in to comment.