Skip to content

Commit

Permalink
first web integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
1ma committed Jun 20, 2024
1 parent fe9e265 commit fd8404e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
5 changes: 5 additions & 0 deletions autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

const __ROOT__ = __DIR__;

require_once __ROOT__.'/vendor/autoload.php';
11 changes: 7 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
bootstrap="vendor/autoload.php"
bootstrap="autoload.php"
cacheResult="false"
executionOrder="depends,defects"
failOnRisky="true"
Expand All @@ -22,9 +22,12 @@
</source>

<php>
<env name="RPC_PASS" value="knots"/>
<env name="RPC_URL" value="http://knots:18443"/>
<env name="RPC_USER" value="knots"/>
<env force="true" name="FAUCET_BITCOIN_RPC_ENDPOINT" value="http://knots:18443"/>
<env force="true" name="FAUCET_BITCOIN_RPC_PASS" value="knots"/>
<env force="true" name="FAUCET_BITCOIN_RPC_USER" value="knots"/>
<env force="true" name="FAUCET_NAME" value="Testing Faucet"/>
<env force="true" name="FAUCET_REDIS_ENDPOINT" value="redis:6379"/>
<env force="true" name="FAUCET_REDIS_PREFIX" value="testing:"/>
</php>

<coverage>
Expand Down
9 changes: 8 additions & 1 deletion tests/Integration/RPCClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
32 changes: 32 additions & 0 deletions tests/Integration/WebTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace BBO\Faucet\Tests\Integration;

use BBO\Faucet\DI\Faucet;
use Nyholm\Psr7\ServerRequest;
use PHPUnit\Framework\TestCase;
use Slim\App;
use UMA\DIC\Container;

final class WebTest extends TestCase
{
private App $sut;

protected function setUp(): void
{
$container = new Container();
$container->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('<title>Testing Faucet</title>', (string) $res->getBody());
}
}
4 changes: 1 addition & 3 deletions web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit fd8404e

Please sign in to comment.