mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-03-08 07:25:25 +01:00
feat: ripristino unit test basilare
This commit is contained in:
parent
68ca4480f0
commit
5c1e88be34
@ -67,6 +67,7 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"friendsofphp/php-cs-fixer": "^3.53",
|
"friendsofphp/php-cs-fixer": "^3.53",
|
||||||
|
"phpunit/phpunit": "^11.5",
|
||||||
"rector/rector": "^1.0"
|
"rector/rector": "^1.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
70
tests/GeneratorTest.php
Normal file
70
tests/GeneratorTest.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Util\Generator;
|
||||||
|
|
||||||
|
class GeneratorTest extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
10
tests/_bootstrap.php
Normal file
10
tests/_bootstrap.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Codeception\Util\Autoload;
|
||||||
|
|
||||||
|
// Caricamento delle dipendenze e delle librerie del progetto
|
||||||
|
$namespaces = require_once __DIR__.'/../config/namespaces.php';
|
||||||
|
foreach ($namespaces as $path => $namespace) {
|
||||||
|
Autoload::addNamespace($namespace.'\\', __DIR__.'/../'.$path.'/custom/src');
|
||||||
|
Autoload::addNamespace($namespace.'\\', __DIR__.'/../'.$path.'/src');
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user