diff --git a/composer.json b/composer.json index 4a3552b..fb021e0 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ }, "autoload-dev": { "psr-4": { - "DebugBar\\Bridge\\Symfony\\": "tests/" + "DebugBar\\Bridge\\Symfony\\Tests\\": "tests/" } }, "scripts": { diff --git a/src/SymfonyHttpDriver.php b/src/SymfonyHttpDriver.php new file mode 100644 index 0000000..4282746 --- /dev/null +++ b/src/SymfonyHttpDriver.php @@ -0,0 +1,88 @@ +session = $session; + $this->response = $response; + } + + public function setResponse(Response $response): void + { + $this->response = $response; + } + + /** + * {@inheritDoc} + */ + public function setHeaders(array $headers): void + { + if (!is_null($this->response)) { + $this->response->headers->add($headers); + } + } + + public function output(string $content): void + { + if (!is_null($this->response)) { + $existingContent = $this->response->getContent(); + $content = $existingContent ? $existingContent . $content : $content; + $this->response->setContent($content); + } + } + + public function isSessionStarted(): bool + { + if (!$this->session->isStarted()) { + $this->session->start(); + } + + return $this->session->isStarted(); + } + + public function setSessionValue(string $name, mixed $value): void + { + $this->session->set($name, $value); + } + + /** + * {@inheritDoc} + */ + public function hasSessionValue(string $name): bool + { + return $this->session->has($name); + } + + /** + * {@inheritDoc} + */ + public function getSessionValue(string $name): mixed + { + return $this->session->get($name); + } + + /** + * {@inheritDoc} + */ + public function deleteSessionValue(string $name): void + { + $this->session->remove($name); + } +} diff --git a/tests/Browser/AbstractBrowserTestcase.php b/tests/Browser/AbstractBrowserTestcase.php index 0545736..483f6fe 100644 --- a/tests/Browser/AbstractBrowserTestcase.php +++ b/tests/Browser/AbstractBrowserTestcase.php @@ -1,6 +1,6 @@ debugbar = new DebugBar(); + } + + public function assertJsonIsArray(string $json): void + { + $data = json_decode($json); + $this->assertIsArray($data); + } + + public function assertJsonIsObject(string $json): void + { + $data = json_decode($json); + $this->assertIsObject($data); + } + + public function assertJsonArrayNotEmpty(string $json): void + { + $data = json_decode($json, true); + $this->assertTrue(is_array($data) && !empty($data)); + } + + public function assertJsonHasProperty(string $json, string $property): void + { + $data = json_decode($json, true); + $this->assertArrayHasKey($property, $data); + } + + public function assertJsonPropertyEquals(string $json, string $property, mixed $expected): void + { + $data = json_decode($json, true); + $this->assertArrayHasKey($property, $data); + $this->assertEquals($expected, $data[$property]); + } +} diff --git a/tests/SymfonyRequestCollectorTest.php b/tests/SymfonyRequestCollectorTest.php new file mode 100644 index 0000000..49eca27 --- /dev/null +++ b/tests/SymfonyRequestCollectorTest.php @@ -0,0 +1,67 @@ +useHtmlVarDumper(false); + + $data = $collector->collect(); + + $this->assertEquals('/index.php', $data['data']['uri']); + $this->assertEquals('200 OK', $data['tooltip']['status']); + } + + public function testHideDefaultMasks(): void + { + $symfonyRequest = Request::create('/index.php', 'POST', [ + 'password' => 'secret', + 'foo' => 'bar', + 'masked' => 'masked', + 'auth' => [ + 'user' => 'barry', + 'password' => 'secret', + ], + ], [], [], [ + 'PHP_AUTH_PW' => 'secret', + ]); + + $collector = new SymfonyRequestCollector($symfonyRequest); + $collector->useHtmlVarDumper(false); + + $data = $collector->collect(); + + $this->assertStringNotContainsString('secret', $data['data']['request_request']); + $this->assertStringContainsString('masked', $data['data']['request_request']); + $this->assertStringContainsString('"PHP_AUTH_PW" => "se***"', $data['data']['request_server']); + $this->assertEquals('200 OK', $data['tooltip']['status']); + } + + public function testHideAddedMasks(): void + { + $symfonyRequest = Request::create('/index.php', 'POST', [ + 'foo' => 'bar', + 'masked' => 'my-masked-string', + ]); + + $collector = new SymfonyRequestCollector($symfonyRequest); + $collector->useHtmlVarDumper(false); + $collector->addMaskedKeys(['masked']); + + $data = $collector->collect(); + + $this->assertStringNotContainsString('my-masked-string', $data['data']['request_request']); + $this->assertStringContainsString('"foo" => "bar"', $data['data']['request_request']); + } + +}