Aggiunti tests Util\Generator

This commit is contained in:
Thomas Zilio 2019-01-19 11:36:31 +01:00
parent 214288c063
commit d315719151
3 changed files with 70 additions and 32 deletions

View File

@ -1,27 +0,0 @@
<?php
use Modules\Anagrafiche\Anagrafica;
use Modules\Fatture\Fattura;
use Modules\Fatture\Tipo;
class FatturaTest extends \Codeception\Test\Unit
{
public function testCreate()
{
$data = date('Y-m-d H:i:s');
$id_anagrafica = 1;
$id_tipo = 2;
$id_segment = 1;
$anagrafica = Anagrafica::find($id_anagrafica);
$tipo = Tipo::find($id_tipo);
$fattura = Fattura::build($anagrafica, $tipo, $data, $id_segment);
$this->assertEquals($fattura->idanagrafica, 1);
$this->assertEquals($fattura->idtipodocumento, 2);
$this->assertEquals($fattura->id_segment, 1);
$this->assertEquals($fattura->data, $data);
}
}

View File

@ -0,0 +1,70 @@
<?php
use Util\Generator;
class GeneratorTest extends \Codeception\Test\Unit
{
public function testNumbersWithPrefix()
{
$this->test(null, '|TEST');
}
public function testNumbersWithSuffix()
{
$this->test('|TEST');
}
public function testCommonNumbers()
{
$this->test();
}
public function testDates()
{
$this->test('/YYYY');
$this->test('/yy');
$this->test(null, 'YYYY-');
$this->test(null, 'yy-');
}
protected function test($prefix = null, $suffix = null)
{
$date = date('Y-m-d H:i:s');
$info = Generator::dateToPattern($date);
// Individuazione valori relativi a suffisso e prefisso
$prefix_value = Generator::complete($prefix, $info);
$suffix_value = Generator::complete($suffix, $info);
$step = 3;
// Pattern di base con numero di caratteri incrementale
$pattern = $prefix.'#'.$suffix;
$previous = null;
for ($i = 0; $i < 10000; $i = $i + $step) {
$value = $prefix_value.$this->pad($i + 1, $length).$suffix_value;
$this->assertEquals($value, Generator::generate($pattern, $previous, $step, $info));
$previous = $value;
}
// Pattern con padding
$length = 5;
$pattern = $prefix.str_repeat('#', $length).$suffix;
$previous = null;
for ($i = 0; $i < 10000; $i = $i + $step) {
$value = $prefix_value.$this->pad($i + 1, $length).$suffix_value;
$this->assertEquals($value, Generator::generate($pattern, $previous, $step, $info));
$previous = $value;
}
}
protected function pad($number, $length)
{
return str_pad($number, $length, '0', STR_PAD_LEFT);
}
}

View File

@ -8,8 +8,3 @@ foreach ($namespaces as $path => $namespace) {
Autoload::addNamespace($namespace.'\\', __DIR__.'/../../'.$path.'/custom/src');
Autoload::addNamespace($namespace.'\\', __DIR__.'/../../'.$path.'/src');
}
// Individuazione dei percorsi di base
App::definePaths(__DIR__.'/../..');
database();