Abstracts

This commit is contained in:
Juan Pablo Vial
2025-04-29 22:25:32 -04:00
parent acb7a1336d
commit f8ac0f14f0
4 changed files with 40 additions and 14 deletions

View File

@ -0,0 +1,15 @@
<?php
namespace ProVM\Integration;
use Psr\Http\Client\ClientInterface;
use GuzzleHttp\Client;
use PHPUnit\Framework\TestCase;
abstract class AbstractIntegration extends TestCase
{
protected ClientInterface $client;
protected function setUp(): void
{
$this->client = new Client(['base_uri' => $_ENV['APP_URL']]);
}
}

View File

@ -1,17 +1,10 @@
<?php
namespace ProVM\Integration;
use PHPUnit\Framework\TestCase;
use GuzzleHttp\Client;
require __DIR__ . '/AbstractIntegration.php';
class HomeTest extends TestCase
class HomeTest extends AbstractIntegration
{
protected Client $client;
protected function setUp(): void
{
$this->client = new Client(['base_uri' => $_ENV['APP_URL']]);
}
public function testLoad(): void
{
$response = $this->client->get('/');

View File

@ -0,0 +1,17 @@
<?php
namespace ProVM\Performance;
use PHPUnit\Framework\TestCase;
abstract class AbstractPerformance extends TestCase
{
protected float $startTime;
protected function start(): void
{
$this->startTime = microtime(true);
}
protected function end(): float
{
return microtime(true) - $this->startTime;
}
}

View File

@ -1,10 +1,11 @@
<?php
namespace ProVM\Performance;
use PHPUnit\Framework;
use GuzzleHttp\Client;
class HomeTest extends Framework\TestCase
require __DIR__ . '/AbstractPerformance.php';
class HomeTest extends AbstractPerformance
{
protected Client $client;
protected function setUp(): void
@ -14,9 +15,9 @@ class HomeTest extends Framework\TestCase
public function testLoad(): void
{
$start = microtime(true);
$this->start();
$this->client->get('/');
$end = microtime(true);
$this->assertLessThanOrEqual(1000, $end - $start);
$time = $this->end();
$this->assertLessThanOrEqual(1000, $time);
}
}