Skip to content

Commit

Permalink
Merge pull request #104 from buggregator/mainenance/var-dumper-tests
Browse files Browse the repository at this point in the history
Covers var-dumper handler with tests
  • Loading branch information
butschster authored Dec 2, 2023
2 parents 96b7ae1 + badad66 commit 85c72d3
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 8 deletions.
6 changes: 0 additions & 6 deletions tests/Feature/Interfaces/Http/ControllerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tests\Feature\Interfaces\Http;

use App\Application\Domain\ValueObjects\Uuid;
use Tests\App\Http\HttpFaker;
use Tests\TestCase;

Expand All @@ -18,9 +17,4 @@ protected function setUp(): void

$this->http = new HttpFaker($this->fakeHttp(), $this);
}

protected function randomUuid(): Uuid
{
return Uuid::generate();
}
}
12 changes: 12 additions & 0 deletions tests/Feature/Interfaces/TCP/TCPTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Tests\Feature\Interfaces\TCP;

use Tests\TestCase;

abstract class TCPTestCase extends TestCase
{

}
48 changes: 48 additions & 0 deletions tests/Feature/Interfaces/TCP/VarDumper/SymfonyV6Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Interfaces\TCP\VarDumper;

use Modules\VarDumper\Interfaces\TCP\Service;
use Spiral\RoadRunner\Tcp\Request;
use Spiral\RoadRunner\Tcp\TcpEvent;
use Tests\Feature\Interfaces\TCP\TCPTestCase;

final class SymfonyV6Test extends TCPTestCase
{
public function testSendDump(): void
{
dump('foo');

$payload = 'YToyOntpOjA7TzozOToiU3ltZm9ueVxDb21wb25lbnRcVmFyRHVtcGVyXENsb25lclxEYXRhIjo3OntzOjQ1OiIAU3ltZm9ueVxDb21wb25lbnRcVmFyRHVtcGVyXENsb25lclxEYXRhAGRhdGEiO2E6MTp7aTowO2E6MTp7aTowO3M6MzoiZm9vIjt9fXM6NDk6IgBTeW1mb255XENvbXBvbmVudFx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jY6InNvdXJjZSI7YTo0OntzOjQ6Im5hbWUiO3M6MTc6IlN5bWZvbnlWNlRlc3QucGhwIjtzOjQ6ImZpbGUiO3M6OTE6Ii9yb290L3JlcG9zL2J1Z2dyZWFndG9yL3NwaXJhbC1hcHAvdGVzdHMvRmVhdHVyZS9JbnRlcmZhY2VzL1RDUC9WYXJEdW1wZXIvU3ltZm9ueVY2VGVzdC5waHAiO3M6NDoibGluZSI7aToxMztzOjEyOiJmaWxlX2V4Y2VycHQiO2I6MDt9fX0=';

$service = $this->get(Service::class);

$service->handle(
new Request(
remoteAddr: '127.0.0.1',
event: TcpEvent::Data,
body: $payload,
connectionUuid: (string)$this->randomUuid(),
server: 'local',
),
);

$this->broadcastig->assertPushed('events', function (array $data) {
$this->assertSame('event.received', $data['event']);
$this->assertSame('var-dump', $data['data']['type']);

$this->assertSame([
'type' => 'string',
'value' => 'foo',
], $data['data']['payload']['payload']);

$this->assertNotEmpty($data['data']['uuid']);
$this->assertNotEmpty($data['data']['timestamp']);


return true;
});
}
}
46 changes: 46 additions & 0 deletions tests/Feature/Interfaces/TCP/VarDumper/SymfonyV7Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Interfaces\TCP\VarDumper;

use Modules\VarDumper\Interfaces\TCP\Service;
use Spiral\RoadRunner\Tcp\Request;
use Spiral\RoadRunner\Tcp\TcpEvent;
use Tests\Feature\Interfaces\TCP\TCPTestCase;

final class SymfonyV7Test extends TCPTestCase
{
public function testSendDump(): void
{
$payload = 'YToyOntpOjA7TzozOToiU3ltZm9ueVxDb21wb25lbnRcVmFyRHVtcGVyXENsb25lclxEYXRhIjo3OntzOjQ1OiIAU3ltZm9ueVxDb21wb25lbnRcVmFyRHVtcGVyXENsb25lclxEYXRhAGRhdGEiO2E6MTp7aTowO2E6MTp7aTowO3M6MzoiZm9vIjt9fXM6NDk6IgBTeW1mb255XENvbXBvbmVudFxWYXJEdW1wZXJcQ2xvbmVyXERhd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6Im5hbWUiO3M6MTc6IlN5bWZvbnlWNlRlc3QucGhwIjtzOjQ6ImZpbGUiO3M6OTE6Ii9yb290L3JlcG9zL2J1Z2dyZWFndG9yL3NwaXJhbC1hcHAvdGVzdHMvRmVhdHVyZS9JbnRlcmZhY2VzL1RDUC9WYXJEdW1wZXIvU3ltZm9ueVY2VGVzdC5waHAiO3M6NDoibGluZSI7aToxNjtzOjEyOiJmaWxlX2V4Y2VycHQiO2I6MDt9fX0=';

$service = $this->get(Service::class);

$service->handle(
new Request(
remoteAddr: '127.0.0.1',
event: TcpEvent::Data,
body: $payload,
connectionUuid: (string)$this->randomUuid(),
server: 'local',
),
);

$this->broadcastig->assertPushed('events', function (array $data) {
$this->assertSame('event.received', $data['event']);
$this->assertSame('var-dump', $data['data']['type']);

$this->assertSame([
'type' => 'string',
'value' => 'foo',
], $data['data']['payload']['payload']);

$this->assertNotEmpty($data['data']['uuid']);
$this->assertNotEmpty($data['data']['timestamp']);


return true;
});
}
}
8 changes: 6 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

namespace Tests;

use App\Application\Domain\ValueObjects\Uuid;
use App\Application\Service\ErrorHandler\Handler;
use Modules\Events\Domain\EventRepositoryInterface;
use Psr\SimpleCache\CacheInterface;
use Spiral\Cache\Storage\ArrayStorage;
use Spiral\Core\Container;
use Spiral\Core\ContainerScope;
use Spiral\Testing\TestableKernelInterface;
Expand Down Expand Up @@ -91,4 +90,9 @@ public function fakeEvents(): EventsMocker

return $this->events;
}

protected function randomUuid(): Uuid
{
return Uuid::generate();
}
}

0 comments on commit 85c72d3

Please sign in to comment.