Skip to content

Commit

Permalink
✅ add tests for NepaliToEnglish Conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
anuzpandey committed Oct 24, 2023
1 parent ed53a36 commit 19ea06d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 19 deletions.
7 changes: 0 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/NepaliDateTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function toNepaliDate(): string

$year = $this->nepaliYear;
$month = $this->nepaliMonth < 10 ? '0' . $this->nepaliMonth : $this->nepaliMonth;
$day = $this->nepaliDay;
$day = $this->nepaliDay < 10 ? '0' . $this->nepaliDay : $this->nepaliDay;

return $year . '-' . $month . '-' . $day;
}
Expand Down
3 changes: 0 additions & 3 deletions tests/ConvertToEglishDateTest.php

This file was deleted.

47 changes: 47 additions & 0 deletions tests/ConvertToEnglishDateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

use Anuzpandey\LaravelNepaliDate\LaravelNepaliDate;

it('can convert to basic nepali date', function (string $date, string $expectedResult) {
$nepaliDate = LaravelNepaliDate::from($date)->toEnglishDate();

expect($nepaliDate)
->toBe($expectedResult);
})->with([
['2053-01-10', '1996-04-22'],
['2029-04-04', '1972-07-19'],
['2022-12-20', '1966-04-02'],
]);

it('can convert to english date array', function () {
$date = '2053-01-10';

$englishDateArray = LaravelNepaliDate::from($date)->toEnglishDateArray();

expect($englishDateArray->toArray())
->toBeArray()
->toMatchArray([
'year' => '1996',
'month' => '04',
'day' => '22',
'npYear' => '१९९६',
'npDayName' => 'सोमबार',
]);
});

it('can convert to nepali formatted result', function (string $format, string $locale, string $expectedResult) {
$date = '2053-01-10';

expect(LaravelNepaliDate::from($date)->toFormattedEnglishDate(format: $format, locale: $locale))
->toBe($expectedResult);
})->with([
["d F Y, l", "np", "२२ अप्रिल १९९६, सोमबार"],
["d F Y, l", "en", "22 April 1996, Monday"],
["Y-m-d", "np", "१९९६-०४-२२"],
["Y-m-d", "en", "1996-04-22"],
["l, d F Y", "np", "सोमबार, २२ अप्रिल १९९६"],
["l, d F Y", "en", "Monday, 22 April 1996"],
["d F Y", "np", "२२ अप्रिल १९९६"],
["d F Y", "en", "22 April 1996"],
["Y/m/d", "np", "१९९६/०४/२२"]
]);
18 changes: 10 additions & 8 deletions tests/ConvertToNepaliDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

use Anuzpandey\LaravelNepaliDate\LaravelNepaliDate;

it('can convert to basic nepali date', function () {
$date = '1996-04-22';

it('can convert to basic nepali date', function (string $date, string $expectedResult) {
$nepaliDate = LaravelNepaliDate::from($date)->toNepaliDate();

expect($nepaliDate)
->toBe('2053-01-10');
});
->toBe($expectedResult);
})->with([
['1996-04-22', '2053-01-10'],
['1972-07-19', '2029-04-04'],
['1966-04-02', '2022-12-20'],
]);

it('can convert to date array', function () {
it('can convert to nepali date array', function () {
$date = '1996-04-22';

$nepaliDateArray = LaravelNepaliDate::from($date)->toNepaliDateArray();
Expand All @@ -27,7 +29,7 @@
]);
});

it('can convert to formatted result', function (string $format, string $locale, string $expectedResult) {
it('can convert to nepali formatted result', function (string $format, string $locale, string $expectedResult) {
$date = '1996-04-22';

expect(LaravelNepaliDate::from($date)->toFormattedNepaliDate(format: $format, locale: $locale))
Expand All @@ -39,7 +41,7 @@
["Y-m-d", "en", "2053-01-10"],
["l, d F Y", "np", "सोमबार, १० वैशाख २०५३"],
["l, d F Y", "en", "Monday, 10 Baisakh 2053"],
["d F Y", "np", "१० वैशाख २०५३"],
["d F Y", "np", "१० वैशाख २०५३"],
["d F Y", "en", "10 Baisakh 2053"],
["Y/m/d", "np", "२०५३/०१/१०"]
]);

0 comments on commit 19ea06d

Please sign in to comment.