Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rskrzypczak committed Nov 2, 2023
1 parent b46760f commit 2449215
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions tests/Base/Z_ResetingRecordNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,7 @@ class RecordNumber extends \App\Fields\RecordNumber
* @var array of dates
*/
public static $dates = [
'2015-01-01',
'2015-03-03',
'2015-03-03',
'2015-03-03',
'2015-03-04',
'2015-03-04',
'2015-03-05',
'2015-11-09',
'2015-11-10',
'2015-11-11',
'2015-11-28',
'2016-11-29',
'2017-03-15',
'2017-03-18',
'2017-07-19',
'2018-01-01',
'2018-01-02',
'2018-01-02',
'2018-02-03',
'2018-05-05',
'2015-01-01'
];

/**
Expand Down Expand Up @@ -82,15 +63,7 @@ class Z_ResetingRecordNumber extends \Tests\Base
public static function setUpBeforeClass(): void
{
self::$transaction = \App\Db::getInstance()->beginTransaction();
}

/**
* Cleaning after tests.
*/
public static function tearDownAfterClass(): void
{
self::$transaction->rollBack();
\App\Cache::clear();
RecordNumber::$dates[0] = date('Y-m-d');
}

/**
Expand Down Expand Up @@ -144,6 +117,25 @@ public function testIncrementNumberStandard()
}
}

/**
* Test method "Parse".
* Test parsing method for record numbers on different dates.
*/
public function testParse()
{
$instance = RecordNumber::getInstance('FInvoice');
foreach (RecordNumber::$dates as $index => $date) {
RecordNumber::$currentDateIndex = $index;
$parts = explode('-', $date);
$instance->set('prefix', '{{DD}}/');
$this->assertSame($parts[2] . '/1', $instance->parseNumber(1));
$instance->set('prefix', '{{MM}}/');
$this->assertSame($parts[1] . '/1', $instance->parseNumber(1));
$instance->set('prefix', '{{YYYY}}/');
$this->assertSame($parts[0] . '/1', $instance->parseNumber(1));
}
}

/**
* Test method "IncrementNumberDay".
* Test record number resetting with new day.
Expand Down Expand Up @@ -334,7 +326,7 @@ public function testLeadingZeros(): void
$currentNumber = 1;
$currentDate = $sequence;
}
$currentNumber = str_pad($currentNumber, $leadingZeros, '0', STR_PAD_LEFT);
$currentNumber = \str_pad($currentNumber, $leadingZeros, '0', STR_PAD_LEFT);
$this->assertSame("$date/$currentNumber", $instance->getIncrementNumber());
$number = RecordNumber::getInstance('FInvoice');
$this->assertSame($currentNumber + 1, $number->get('cur_id'));
Expand All @@ -346,4 +338,13 @@ public function testLeadingZeros(): void
}
}
}

/**
* Cleaning after tests.
*/
public static function tearDownAfterClass(): void
{
self::$transaction->rollBack();
\App\Cache::clear();
}
}

0 comments on commit 2449215

Please sign in to comment.