Issues (15)

tests/Unit/EnglishDateTest.php (2 issues)

1
<?php
2
3
use Carbon\Carbon;
4
use Pratiksh\Nepalidate\Services\EnglishDate;
5
6
test('it converts BS date string to AD using create()', function () {
7
    $date = EnglishDate::create('2081-01-01');
8
9
    expect($date)->toBeInstanceOf(EnglishDate::class);
10
    expect($date->toCarbon()->format('Y-m-d'))->toBe('2024-04-13');
11
});
12
13
test('it converts BS date string to AD using fromBS()', function () {
14
    $date = EnglishDate::fromBS('2081/01/01');
15
16
    expect($date)->toBeInstanceOf(EnglishDate::class);
17
    expect($date->toCarbon()->format('Y-m-d'))->toBe('2024-04-13');
18
});
19
20
test('it throws exception for invalid date format in create()', function () {
21
    $this->expectException(Exception::class);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
22
    $this->expectExceptionMessage('Invalid date format');
23
24
    EnglishDate::create('2081-01');
25
});
26
27
test('it throws exception for invalid date format in fromBS()', function () {
28
    $this->expectException(Exception::class);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
29
    $this->expectExceptionMessage('Invalid date format');
30
31
    EnglishDate::fromBS('2081/01');
32
});
33
34
test('it correctly sets AD Carbon date after conversion', function () {
35
    $bs = '2081-01-01';
36
    $englishDate = EnglishDate::create($bs);
37
    $carbon = $englishDate->toCarbon();
38
39
    expect($carbon)->toBeInstanceOf(Carbon::class);
40
    expect($carbon->format('Y-m-d'))->toBe('2024-04-13');
41
});
42