Compare commits
9 Commits
c3247838b3
...
dd1741a930
Author | SHA1 | Date | |
---|---|---|---|
dd1741a930 | |||
ad0fd82a9e | |||
bae5c1740d | |||
f5f1482b7a | |||
4bd5fe16df | |||
61845fbd05 | |||
f8ac0f14f0 | |||
acb7a1336d | |||
8af56137a8 |
1
app/.gitignore
vendored
1
app/.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
**/bin
|
**/bin
|
||||||
|
**/public/tests
|
||||||
|
3
app/bin/console
Normal file
3
app/bin/console
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
php -d auto_prepend_file=test.bootstrap.php -a
|
3
app/bin/integration_tests
Normal file
3
app/bin/integration_tests
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
bin/phpunit --testsuite acceptance $@
|
3
app/bin/performance_tests
Normal file
3
app/bin/performance_tests
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
bin/phpunit --testsuite performance $@
|
3
app/bin/unit_tests
Normal file
3
app/bin/unit_tests
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
./bin/phpunit --testsuite unit $@
|
@ -28,16 +28,15 @@
|
|||||||
<directory>common</directory>
|
<directory>common</directory>
|
||||||
</include>
|
</include>
|
||||||
</source>
|
</source>
|
||||||
<coverage pathCoverage="false" ignoreDeprecatedCodeUnits="true" disableCodeCoverageIgnore="true">
|
<!--<coverage pathCoverage="false" ignoreDeprecatedCodeUnits="true" disableCodeCoverageIgnore="true">
|
||||||
<report>
|
<report>
|
||||||
<!--<html outputDirectory="/code/public/coverage/html"/>-->
|
<html outputDirectory="/code/public/coverage/html"/>
|
||||||
<php outputFile="/code/public/coverage/coverage.php"/>
|
|
||||||
</report>
|
</report>
|
||||||
</coverage>
|
</coverage>-->
|
||||||
<logging>
|
<logging>
|
||||||
<junit outputFile="/code/cache/tests/junit.xml"/>
|
<junit outputFile="/code/cache/tests/junit.xml"/>
|
||||||
<teamcity outputFile="/code/cache/tests/teamcity.txt"/>
|
<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"/>
|
<testdoxText outputFile="/code/cache/tests/testdox.txt"/>
|
||||||
</logging>
|
</logging>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
@ -74,7 +74,11 @@ class TestBootstrap
|
|||||||
public function migrate(): void
|
public function migrate(): void
|
||||||
{
|
{
|
||||||
$cmd = "{$this->baseCommand} migrate -e testing";
|
$cmd = "{$this->baseCommand} migrate -e testing";
|
||||||
shell_exec($cmd);
|
$status = shell_exec($cmd);
|
||||||
|
if ($status !== false and $status !== null) {
|
||||||
|
$cmd = "{$this->baseCommand} seed:run -e testing";
|
||||||
|
shell_exec($cmd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function resetDatabase(): void
|
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);
|
$bootstrap = new TestBootstrap($_ENV);
|
||||||
Benchmark::execute([$bootstrap, 'run']);
|
Benchmark::execute([$bootstrap, 'run']);
|
||||||
Benchmark::print();
|
Benchmark::print();
|
||||||
|
15
app/tests/integration/AbstractIntegration.php
Normal file
15
app/tests/integration/AbstractIntegration.php
Normal 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']]);
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace ProVM\Integration;
|
namespace ProVM\Integration;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
class HomeTest extends AbstractIntegration
|
||||||
use GuzzleHttp\Client;
|
|
||||||
|
|
||||||
class HomeTest extends TestCase
|
|
||||||
{
|
{
|
||||||
protected Client $client;
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
$this->client = new Client(['base_uri' => $_ENV['APP_URL']]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testLoad(): void
|
public function testLoad(): void
|
||||||
{
|
{
|
||||||
$response = $this->client->get('/');
|
$response = $this->client->get('/');
|
||||||
|
17
app/tests/performance/AbstractPerformance.php
Normal file
17
app/tests/performance/AbstractPerformance.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace ProVM\Performance;
|
namespace ProVM\Performance;
|
||||||
|
|
||||||
use PHPUnit\Framework;
|
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
|
|
||||||
class HomeTest extends Framework\TestCase
|
class HomeTest extends AbstractPerformance
|
||||||
{
|
{
|
||||||
protected Client $client;
|
protected Client $client;
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
@ -14,9 +13,9 @@ class HomeTest extends Framework\TestCase
|
|||||||
|
|
||||||
public function testLoad(): void
|
public function testLoad(): void
|
||||||
{
|
{
|
||||||
$start = microtime(true);
|
$this->start();
|
||||||
$this->client->get('/');
|
$this->client->get('/');
|
||||||
$end = microtime(true);
|
$time = $this->end();
|
||||||
$this->assertLessThanOrEqual(1000, $end - $start);
|
$this->assertLessThanOrEqual(1000, $time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
app/tests/unit/src/Model/Proyecto/BrokerTest.php
Normal file
27
app/tests/unit/src/Model/Proyecto/BrokerTest.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
10
app/tests/unit/src/ObjectHasMethodTrait.php
Normal file
10
app/tests/unit/src/ObjectHasMethodTrait.php
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user