9 Commits

Author SHA1 Message Date
dd1741a930 Broker test 2025-04-29 23:21:19 -04:00
ad0fd82a9e Assert nuevo 2025-04-29 23:21:13 -04:00
bae5c1740d No mas require 2025-04-29 23:19:05 -04:00
f5f1482b7a Autoload para pruebas 2025-04-29 23:18:55 -04:00
4bd5fe16df Comandos para correr pruebas y consola 2025-04-29 23:18:18 -04:00
61845fbd05 Ignorar datos de pruebas 2025-04-29 22:26:26 -04:00
f8ac0f14f0 Abstracts 2025-04-29 22:25:32 -04:00
acb7a1336d Coverage lento e innecesario 2025-04-29 22:25:11 -04:00
8af56137a8 Seeds al migrar 2025-04-29 21:51:19 -04:00
13 changed files with 111 additions and 21 deletions

1
app/.gitignore vendored
View File

@ -1 +1,2 @@
**/bin
**/public/tests

3
app/bin/console Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/bash
php -d auto_prepend_file=test.bootstrap.php -a

View File

@ -0,0 +1,3 @@
#!/usr/bin/bash
bin/phpunit --testsuite acceptance $@

View File

@ -0,0 +1,3 @@
#!/usr/bin/bash
bin/phpunit --testsuite performance $@

3
app/bin/unit_tests Normal file
View File

@ -0,0 +1,3 @@
#!/usr/bin/bash
./bin/phpunit --testsuite unit $@

View File

@ -28,16 +28,15 @@
<directory>common</directory>
</include>
</source>
<coverage pathCoverage="false" ignoreDeprecatedCodeUnits="true" disableCodeCoverageIgnore="true">
<!--<coverage pathCoverage="false" ignoreDeprecatedCodeUnits="true" disableCodeCoverageIgnore="true">
<report>
<!--<html outputDirectory="/code/public/coverage/html"/>-->
<php outputFile="/code/public/coverage/coverage.php"/>
<html outputDirectory="/code/public/coverage/html"/>
</report>
</coverage>
</coverage>-->
<logging>
<junit outputFile="/code/cache/tests/junit.xml"/>
<teamcity outputFile="/code/cache/tests/teamcity.txt"/>
<testdoxHtml outputFile="/code/cache/tests/testdox.html"/>
<testdoxHtml outputFile="/code/public/tests/testdox.html"/>
<testdoxText outputFile="/code/cache/tests/testdox.txt"/>
</logging>
</phpunit>

View File

@ -74,8 +74,12 @@ class TestBootstrap
public function migrate(): void
{
$cmd = "{$this->baseCommand} migrate -e testing";
$status = shell_exec($cmd);
if ($status !== false and $status !== null) {
$cmd = "{$this->baseCommand} seed:run -e testing";
shell_exec($cmd);
}
}
public function resetDatabase(): void
{
@ -143,6 +147,21 @@ class TestBootstrap
}
}
spl_autoload_register(function($className) {
$baseTestPath = __DIR__ . "/tests";
$namespaceMap = [
"ProVM\\Integration\\" => "{$baseTestPath}/integration",
"ProVM\\Unit\\" => "{$baseTestPath}/unit/src",
"ProVM\\Performance\\" => "{$baseTestPath}/performance",
];
foreach ($namespaceMap as $namespace => $path) {
if (str_starts_with($className, $namespace)) {
require str_replace($namespace, "{$path}/", $className) . ".php";
return;
}
}
});
$bootstrap = new TestBootstrap($_ENV);
Benchmark::execute([$bootstrap, 'run']);
Benchmark::print();

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,8 @@
<?php
namespace ProVM\Integration;
use PHPUnit\Framework\TestCase;
use GuzzleHttp\Client;
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,9 @@
<?php
namespace ProVM\Performance;
use PHPUnit\Framework;
use GuzzleHttp\Client;
class HomeTest extends Framework\TestCase
class HomeTest extends AbstractPerformance
{
protected Client $client;
protected function setUp(): void
@ -14,9 +13,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);
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace ProVM\Unit\Model\Proyecto;
use Incoviba\Model\Proyecto\Broker;
use PHPUnit\Framework\TestCase;
use ProVM\Unit\ObjectHasMethodTrait;
class BrokerTest extends TestCase
{
use ObjectHasMethodTrait;
public function testAttributes(): void
{
$broker = new Broker();
$this->assertObjectHasProperty('rut', $broker);
$this->assertObjectHasProperty('digit', $broker);
$this->assertObjectHasProperty('name', $broker);
}
public function testRelations(): void
{
$broker = new Broker();
$this->assertObjectHasMethod('data', $broker);
$this->assertObjectHasMethod('contracts', $broker);
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace ProVM\Unit;
trait ObjectHasMethodTrait
{
public function assertObjectHasMethod(string $method, object $object): void
{
$this->assertTrue(method_exists($object, $method), sprintf('The object %s does not have the method %s', get_class($object), $method));
}
}