From fd8404ed916cd137e92365d72182466050c336ad Mon Sep 17 00:00:00 2001 From: Marcel Hernandez Date: Fri, 21 Jun 2024 00:19:07 +0200 Subject: [PATCH] first web integration test --- autoload.php | 5 +++++ phpunit.xml | 11 ++++++---- tests/Integration/RPCClientTest.php | 9 +++++++- tests/Integration/WebTest.php | 32 +++++++++++++++++++++++++++++ web/index.php | 4 +--- 5 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 autoload.php create mode 100644 tests/Integration/WebTest.php diff --git a/autoload.php b/autoload.php new file mode 100644 index 0000000..f5667da --- /dev/null +++ b/autoload.php @@ -0,0 +1,5 @@ + - - - + + + + + + diff --git a/tests/Integration/RPCClientTest.php b/tests/Integration/RPCClientTest.php index 80682be..ce9e8f7 100644 --- a/tests/Integration/RPCClientTest.php +++ b/tests/Integration/RPCClientTest.php @@ -13,11 +13,18 @@ final class RPCClientTest extends TestCase protected function setUp(): void { - $this->sut = new RPCClient($_ENV['RPC_URL'], $_ENV['RPC_USER'], $_ENV['RPC_PASS'], 0, null); + $this->sut = new RPCClient( + $_ENV['FAUCET_BITCOIN_RPC_ENDPOINT'], + $_ENV['FAUCET_BITCOIN_RPC_USER'], + $_ENV['FAUCET_BITCOIN_RPC_PASS'], + 0, + null + ); } public function testValidateAddress(): void { + self::assertFalse($this->sut->validateAddress('nonsense!')); self::assertTrue($this->sut->validateAddress('mwxHTZVYD44DZSoqCNXGzeS2LMB9smqFG6')); self::assertFalse($this->sut->validateAddress('nwxHTZVYD44DZSoqCNXGzeS2LMB9smqFG6')); self::assertFalse($this->sut->validateAddress('32ixEdVJWo3kmvJGMTZq5jAQVZZeuwnqzo')); diff --git a/tests/Integration/WebTest.php b/tests/Integration/WebTest.php new file mode 100644 index 0000000..79d9a87 --- /dev/null +++ b/tests/Integration/WebTest.php @@ -0,0 +1,32 @@ +register(new Faucet()); + + $this->sut = $container->get(Faucet::class); + } + + public function testLandingPage(): void + { + $res = $this->sut->handle(new ServerRequest('GET', '/')); + + self::assertSame(200, $res->getStatusCode()); + self::assertStringContainsString('Testing Faucet', (string) $res->getBody()); + } +} diff --git a/web/index.php b/web/index.php index d3dbbd3..8b12d58 100644 --- a/web/index.php +++ b/web/index.php @@ -5,14 +5,12 @@ use BBO\Faucet\DI\Faucet; use UMA\DIC\Container; -define('__ROOT__', dirname(__DIR__)); - if (!extension_loaded('redis')) { http_response_code(500); exit('redis extension not enabled'); } -require __ROOT__.'/vendor/autoload.php'; +require __DIR__.'/../autoload.php'; $container = new Container(); $container->register(new Faucet());