Tests
This commit is contained in:
13
app/.phpunit-watcher.yml
Normal file
13
app/.phpunit-watcher.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
watch:
|
||||||
|
directories:
|
||||||
|
- src
|
||||||
|
- tests
|
||||||
|
- common
|
||||||
|
fileMask: '*.php'
|
||||||
|
notifications:
|
||||||
|
passingTests: false
|
||||||
|
failingTests: false
|
||||||
|
hideManual: true
|
||||||
|
phpunit:
|
||||||
|
arguments: '--log-events-text /logs/output.txt --stop-on-failure'
|
||||||
|
timeout: 180
|
40
app/phpunit.xml
Normal file
40
app/phpunit.xml
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
|
||||||
|
bootstrap="vendor/autoload.php"
|
||||||
|
cacheDirectory=".phpunit.cache"
|
||||||
|
executionOrder="depends,defects"
|
||||||
|
requireCoverageMetadata="false"
|
||||||
|
beStrictAboutCoverageMetadata="false"
|
||||||
|
beStrictAboutOutputDuringTests="true"
|
||||||
|
colors="true"
|
||||||
|
failOnRisky="false"
|
||||||
|
failOnWarning="false">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="unit">
|
||||||
|
<directory>tests/units</directory>
|
||||||
|
</testsuite>
|
||||||
|
<testsuite name="acceptance">
|
||||||
|
<directory>tests/acceptance</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
|
||||||
|
<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
|
||||||
|
<include>
|
||||||
|
<directory>src</directory>
|
||||||
|
<directory>common</directory>
|
||||||
|
</include>
|
||||||
|
</source>
|
||||||
|
<coverage includeUncoveredFiles="true" pathCoverage="false" ignoreDeprecatedCodeUnits="true" disableCodeCoverageIgnore="true">
|
||||||
|
<report>
|
||||||
|
<html outputDirectory="/code/public/coverage/html" />
|
||||||
|
<php outputFile="/code/public/coverage/coverage.php" />
|
||||||
|
</report>
|
||||||
|
</coverage>
|
||||||
|
<logging>
|
||||||
|
<junit outputFile="/logs/junit.xml" />
|
||||||
|
<teamcity outputFile="/logs/teamcity.txt" />
|
||||||
|
<testdoxHtml outputFile="/logs/testdox.html" />
|
||||||
|
<testdoxText outputFile="/logs/testdox.txt" />
|
||||||
|
</logging>
|
||||||
|
</phpunit>
|
22
app/tests/acceptance/HomeTest.php
Normal file
22
app/tests/acceptance/HomeTest.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
use PHPUnit\Framework;
|
||||||
|
|
||||||
|
class HomeTest extends Framework\TestCase
|
||||||
|
{
|
||||||
|
public function testLoadHome(): void
|
||||||
|
{
|
||||||
|
$client = new GuzzleHttp\Client(['base_uri' => 'http://proxy']);
|
||||||
|
$home = $client->get('');
|
||||||
|
$home = $home->getBody()->getContents();
|
||||||
|
|
||||||
|
$expected = [
|
||||||
|
'<!DOCTYPE html>',
|
||||||
|
'<title>Incoviba</title>',
|
||||||
|
'<img src="http://localhost:8080/assets/images/logo_cabezal.png" alt="logo" />',
|
||||||
|
'Bienvenid@ a Incoviba'
|
||||||
|
];
|
||||||
|
foreach ($expected as $segment) {
|
||||||
|
$this->assertStringContainsString($segment, $home);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
30
app/tests/acceptance/LoginTest.php
Normal file
30
app/tests/acceptance/LoginTest.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
use PHPUnit\Framework;
|
||||||
|
|
||||||
|
class LoginTest extends Framework\TestCase
|
||||||
|
{
|
||||||
|
public function testShowLogin(): void
|
||||||
|
{
|
||||||
|
$client = $this->getClient();
|
||||||
|
$response = $client->get('/login');
|
||||||
|
$login = $response->getBody()->getContents();
|
||||||
|
$expected = [
|
||||||
|
'<input type="text" id="name" name="name" />',
|
||||||
|
'<input type="password" id="password" name="password" />',
|
||||||
|
'<button class="ui button" id="enter">Ingresar</button>'
|
||||||
|
];
|
||||||
|
foreach ($expected as $segment) {
|
||||||
|
$this->assertStringContainsString($segment, $login);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function testDoLogin(): void
|
||||||
|
{
|
||||||
|
$client = $this->getClient();
|
||||||
|
$response = $client->get('/login');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getClient(): GuzzleHttp\Client
|
||||||
|
{
|
||||||
|
return new GuzzleHttp\Client(['base_uri' => 'http://proxy']);
|
||||||
|
}
|
||||||
|
}
|
36
app/tests/units/common/Alias/ViewTest.php
Normal file
36
app/tests/units/common/Alias/ViewTest.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
namespace ProVM\Test\Common\Alias;
|
||||||
|
|
||||||
|
use Incoviba\Common\Alias\View;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\StreamInterface;
|
||||||
|
|
||||||
|
class ViewTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testRender(): void
|
||||||
|
{
|
||||||
|
$contents = <<<HTML
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf8" />
|
||||||
|
<title>Test</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
Test
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
HTML;
|
||||||
|
mkdir('/tmp/views');
|
||||||
|
mkdir('/tmp/cache', 777);
|
||||||
|
file_put_contents('/tmp/views/test.blade.php', $contents);
|
||||||
|
$view = new View('/tmp/views', '/tmp/cache');
|
||||||
|
$body = $this->getMockBuilder(StreamInterface::class)->getMock();
|
||||||
|
$body->method('getContents')->willReturn($contents);
|
||||||
|
$response = $this->getMockBuilder(ResponseInterface::class)->getMock();
|
||||||
|
$response->method('getBody')->willReturn($body);
|
||||||
|
$output = $view->render($response, 'test');
|
||||||
|
$this->assertEquals($contents, $output->getBody()->getContents());
|
||||||
|
}
|
||||||
|
}
|
8
app/tests/units/common/Implement/ConnectionTest.php
Normal file
8
app/tests/units/common/Implement/ConnectionTest.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
namespace ProVM\Test\Common\Implement;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class ConnectionTest extends TestCase
|
||||||
|
{
|
||||||
|
}
|
50
app/tests/units/src/Service/MenuTest.php
Normal file
50
app/tests/units/src/Service/MenuTest.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
namespace ProVM\Test\Service;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Incoviba\Common\Define;
|
||||||
|
use Incoviba\Model;
|
||||||
|
use Incoviba\Repository;
|
||||||
|
use Incoviba\Service;
|
||||||
|
|
||||||
|
class MenuTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testBuild(): void
|
||||||
|
{
|
||||||
|
$tests = mt_rand(10, 100);
|
||||||
|
for ($i = 0; $i < $tests; $i ++) {
|
||||||
|
list($expected, $menu) = $this->generateBuildTest();
|
||||||
|
$this->assertEquals($expected, $menu->build(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected function generateBuildTest(): array
|
||||||
|
{
|
||||||
|
$modelCount = mt_rand(3, 100);
|
||||||
|
$expected = [];
|
||||||
|
$models = [];
|
||||||
|
for ($j = 0; $j < $modelCount; $j ++) {
|
||||||
|
$model = $this->generateModel();
|
||||||
|
$models []= $model;
|
||||||
|
$expected []= "<a class=\"item\" href=\"http://localhost/url{$model->id}\">title{$model->id}</a>";
|
||||||
|
}
|
||||||
|
$expected = implode(PHP_EOL, $expected);
|
||||||
|
$connection = $this->getMockBuilder(Define\Connection::class)->getMock();
|
||||||
|
$repository = $this->getMockBuilder(Repository\Menu::class)->setConstructorArgs(compact('connection'))->getMock();
|
||||||
|
$permissionsRepository = $this->getMockBuilder(Repository\Permission::class)->setConstructorArgs(compact('connection'))->getMock();
|
||||||
|
$permissions = $this->getMockBuilder(Service\Permission::class)->setConstructorArgs([$permissionsRepository])->getMock();
|
||||||
|
$repository->method('fetchByUser')->willReturn($models);
|
||||||
|
$menu = new Service\Menu($repository, $permissions, (object) ['base' => 'http://localhost']);
|
||||||
|
|
||||||
|
return [$expected, $menu];
|
||||||
|
}
|
||||||
|
protected function generateModel(): Model\Menu
|
||||||
|
{
|
||||||
|
$id = mt_rand(1, 100000);
|
||||||
|
$model = $this->getMockBuilder(Model\Menu::class)->getMock();
|
||||||
|
$model->id = $id;
|
||||||
|
$model->url = "url{$id}";
|
||||||
|
$model->title = "title{$id}";
|
||||||
|
|
||||||
|
return $model;
|
||||||
|
}
|
||||||
|
}
|
@ -83,6 +83,16 @@ services:
|
|||||||
- ${CLI_PATH:-.}:/code
|
- ${CLI_PATH:-.}:/code
|
||||||
- ./logs/cli:/logs
|
- ./logs/cli:/logs
|
||||||
|
|
||||||
|
testing:
|
||||||
|
profiles:
|
||||||
|
- testing
|
||||||
|
container_name: incoviba_tests
|
||||||
|
extends:
|
||||||
|
service: web
|
||||||
|
volumes:
|
||||||
|
- ./logs/test:/logs
|
||||||
|
command: [ '/code/vendor/bin/phpunit-watcher', 'watch' ]
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
dbdata: {}
|
dbdata: {}
|
||||||
incoviba_redis: {}
|
incoviba_redis: {}
|
||||||
|
Reference in New Issue
Block a user