Skip to content

Commit 19faf16

Browse files
committed
test: add tests for Ecma\Intl\Locale\Options
1 parent d71e1e7 commit 19faf16

File tree

15 files changed

+573
-4
lines changed

15 files changed

+573
-4
lines changed

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
],
1717
"require": {
1818
"php": "^8.2",
19-
"pestphp/pest": "^2.6"
19+
"pestphp/pest": "^2.9"
2020
},
2121
"require-dev": {
2222
"ramsey/devtools": "^2.0"

Diff for: tests/intl402/Locale/Options/empty-constructor.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Ecma\Intl\Locale\Options;
6+
7+
$emptyOptions = new Options();
8+
9+
it('constructs an object with all properties set to null')
10+
->expect($emptyOptions->calendar)
11+
->toBeNull()
12+
->and($emptyOptions->caseFirst)
13+
->toBeNull()
14+
->and($emptyOptions->collation)
15+
->toBeNull()
16+
->and($emptyOptions->hourCycle)
17+
->toBeNull()
18+
->and($emptyOptions->language)
19+
->toBeNull()
20+
->and($emptyOptions->numberingSystem)
21+
->toBeNull()
22+
->and($emptyOptions->numeric)
23+
->toBeNull()
24+
->and($emptyOptions->region)
25+
->toBeNull()
26+
->and($emptyOptions->script)
27+
->toBeNull();
28+
29+
it('serializes to an empty JSON object')
30+
->expect(json_encode($emptyOptions))
31+
->toBe('{}');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Ecma\Intl\Locale\Options;
6+
7+
it('throws an exception for invalid calendar', function (): void {
8+
expect(fn () => new Options(calendar: 'gregoryab'))
9+
->toThrow(ValueError::class, 'calendar is not a well-formed calendar value');
10+
});
11+
12+
it('throws an exception for invalid caseFirst', function (): void {
13+
expect(fn () => new Options(caseFirst: 'foobar'))
14+
->toThrow(ValueError::class, 'caseFirst must be either "upper", "lower", or "false"');
15+
});
16+
17+
it('throws an exception for invalid collation', function (): void {
18+
expect(fn () => new Options(collation: 'emojiabcd'))
19+
->toThrow(ValueError::class, 'collation is not a well-formed collation value');
20+
});
21+
22+
it('throws an exception for invalid hourCycle', function (): void {
23+
expect(fn () => new Options(hourCycle: 'hour12'))
24+
->toThrow(ValueError::class, 'hourCycle must be "h11", "h12", "h23", or "h24"');
25+
});
26+
27+
it('throws an exception for invalid language', function (): void {
28+
expect(fn () => new Options(language: 'english language'))
29+
->toThrow(ValueError::class, 'language is not a well-formed language value');
30+
});
31+
32+
it('throws an exception for invalid numberingSystem', function (): void {
33+
expect(fn () => new Options(numberingSystem: 'numbersystem'))
34+
->toThrow(ValueError::class, 'numberingSystem is not a well-formed numbering system value');
35+
});
36+
37+
it('throws an exception for invalid numeric', function (): void {
38+
expect(fn () => new Options(numeric: 1234))
39+
->toThrow(
40+
TypeError::class,
41+
'Ecma\Intl\Locale\Options::__construct(): Argument #7 ($numeric) must be of type ?bool, int given',
42+
);
43+
});
44+
45+
it('throws an exception for invalid region', function (): void {
46+
expect(fn () => new Options(region: 'region'))
47+
->toThrow(ValueError::class, 'region is not a well-formed region value');
48+
});
49+
50+
it('throws an exception for invalid script', function (): void {
51+
expect(fn () => new Options(script: 'script'))
52+
->toThrow(ValueError::class, 'script is not a well-formed script value');
53+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Ecma\Intl\Locale\Options;
6+
7+
$reflected = new ReflectionClass(Options::class);
8+
9+
test('Locale\\Options has a property named "calendar"')
10+
->expect($reflected->hasProperty('calendar'))
11+
->toBeTrue();
12+
13+
describe('property', function () use ($reflected): void {
14+
$property = $reflected->getProperty('calendar');
15+
$type = $property->getType();
16+
17+
it('is named "calendar"')
18+
->expect($property->getName())
19+
->toBe('calendar');
20+
21+
it('is a public property')
22+
->expect($property->isPublic())
23+
->toBeTrue();
24+
25+
it('is not a static property')
26+
->expect($property->isStatic())
27+
->toBeFalse();
28+
29+
it('is a readonly property')
30+
->expect($property->isReadOnly())
31+
->toBeTrue();
32+
33+
it('is a string type and allows null values')
34+
->expect($type)
35+
->toBeInstanceOf(ReflectionType::class)
36+
->and($type->allowsNull())
37+
->toBeTrue()
38+
->and($type->getName())
39+
->toBe('string');
40+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Ecma\Intl\Locale\Options;
6+
7+
$reflected = new ReflectionClass(Options::class);
8+
9+
test('Locale\\Options has a property named "caseFirst"')
10+
->expect($reflected->hasProperty('caseFirst'))
11+
->toBeTrue();
12+
13+
describe('property', function () use ($reflected): void {
14+
$property = $reflected->getProperty('caseFirst');
15+
$type = $property->getType();
16+
17+
it('is named "caseFirst"')
18+
->expect($property->getName())
19+
->toBe('caseFirst');
20+
21+
it('is a public property')
22+
->expect($property->isPublic())
23+
->toBeTrue();
24+
25+
it('is not a static property')
26+
->expect($property->isStatic())
27+
->toBeFalse();
28+
29+
it('is a readonly property')
30+
->expect($property->isReadOnly())
31+
->toBeTrue();
32+
33+
it('is a string type and allows null values')
34+
->expect($type)
35+
->toBeInstanceOf(ReflectionType::class)
36+
->and($type->allowsNull())
37+
->toBeTrue()
38+
->and($type->getName())
39+
->toBe('string');
40+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Ecma\Intl\Locale\Options;
6+
7+
$reflected = new ReflectionClass(Options::class);
8+
9+
test('Locale\\Options has a property named "collation"')
10+
->expect($reflected->hasProperty('collation'))
11+
->toBeTrue();
12+
13+
describe('property', function () use ($reflected): void {
14+
$property = $reflected->getProperty('collation');
15+
$type = $property->getType();
16+
17+
it('is named "collation"')
18+
->expect($property->getName())
19+
->toBe('collation');
20+
21+
it('is a public property')
22+
->expect($property->isPublic())
23+
->toBeTrue();
24+
25+
it('is not a static property')
26+
->expect($property->isStatic())
27+
->toBeFalse();
28+
29+
it('is a readonly property')
30+
->expect($property->isReadOnly())
31+
->toBeTrue();
32+
33+
it('is a string type and allows null values')
34+
->expect($type)
35+
->toBeInstanceOf(ReflectionType::class)
36+
->and($type->allowsNull())
37+
->toBeTrue()
38+
->and($type->getName())
39+
->toBe('string');
40+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Ecma\Intl\Locale\Options;
6+
7+
$reflected = new ReflectionClass(Options::class);
8+
9+
test('Locale\\Options has a property named "hourCycle"')
10+
->expect($reflected->hasProperty('hourCycle'))
11+
->toBeTrue();
12+
13+
describe('property', function () use ($reflected): void {
14+
$property = $reflected->getProperty('hourCycle');
15+
$type = $property->getType();
16+
17+
it('is named "hourCycle"')
18+
->expect($property->getName())
19+
->toBe('hourCycle');
20+
21+
it('is a public property')
22+
->expect($property->isPublic())
23+
->toBeTrue();
24+
25+
it('is not a static property')
26+
->expect($property->isStatic())
27+
->toBeFalse();
28+
29+
it('is a readonly property')
30+
->expect($property->isReadOnly())
31+
->toBeTrue();
32+
33+
it('is a string type and allows null values')
34+
->expect($type)
35+
->toBeInstanceOf(ReflectionType::class)
36+
->and($type->allowsNull())
37+
->toBeTrue()
38+
->and($type->getName())
39+
->toBe('string');
40+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Ecma\Intl\Locale\Options;
6+
7+
$reflected = new ReflectionClass(Options::class);
8+
9+
test('Locale\\Options has a property named "language"')
10+
->expect($reflected->hasProperty('language'))
11+
->toBeTrue();
12+
13+
describe('property', function () use ($reflected): void {
14+
$property = $reflected->getProperty('language');
15+
$type = $property->getType();
16+
17+
it('is named "language"')
18+
->expect($property->getName())
19+
->toBe('language');
20+
21+
it('is a public property')
22+
->expect($property->isPublic())
23+
->toBeTrue();
24+
25+
it('is not a static property')
26+
->expect($property->isStatic())
27+
->toBeFalse();
28+
29+
it('is a readonly property')
30+
->expect($property->isReadOnly())
31+
->toBeTrue();
32+
33+
it('is a string type and allows null values')
34+
->expect($type)
35+
->toBeInstanceOf(ReflectionType::class)
36+
->and($type->allowsNull())
37+
->toBeTrue()
38+
->and($type->getName())
39+
->toBe('string');
40+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Ecma\Intl\Locale\Options;
6+
7+
$reflected = new ReflectionClass(Options::class);
8+
9+
test('Locale\\Options has a property named "numberingSystem"')
10+
->expect($reflected->hasProperty('numberingSystem'))
11+
->toBeTrue();
12+
13+
describe('property', function () use ($reflected): void {
14+
$property = $reflected->getProperty('numberingSystem');
15+
$type = $property->getType();
16+
17+
it('is named "numberingSystem"')
18+
->expect($property->getName())
19+
->toBe('numberingSystem');
20+
21+
it('is a public property')
22+
->expect($property->isPublic())
23+
->toBeTrue();
24+
25+
it('is not a static property')
26+
->expect($property->isStatic())
27+
->toBeFalse();
28+
29+
it('is a readonly property')
30+
->expect($property->isReadOnly())
31+
->toBeTrue();
32+
33+
it('is a string type and allows null values')
34+
->expect($type)
35+
->toBeInstanceOf(ReflectionType::class)
36+
->and($type->allowsNull())
37+
->toBeTrue()
38+
->and($type->getName())
39+
->toBe('string');
40+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Ecma\Intl\Locale\Options;
6+
7+
$reflected = new ReflectionClass(Options::class);
8+
9+
test('Locale\\Options has a property named "numeric"')
10+
->expect($reflected->hasProperty('numeric'))
11+
->toBeTrue();
12+
13+
describe('property', function () use ($reflected): void {
14+
$property = $reflected->getProperty('numeric');
15+
$type = $property->getType();
16+
17+
it('is named "numeric"')
18+
->expect($property->getName())
19+
->toBe('numeric');
20+
21+
it('is a public property')
22+
->expect($property->isPublic())
23+
->toBeTrue();
24+
25+
it('is not a static property')
26+
->expect($property->isStatic())
27+
->toBeFalse();
28+
29+
it('is a readonly property')
30+
->expect($property->isReadOnly())
31+
->toBeTrue();
32+
33+
it('is a bool type and allows null values')
34+
->expect($type)
35+
->toBeInstanceOf(ReflectionType::class)
36+
->and($type->allowsNull())
37+
->toBeTrue()
38+
->and($type->getName())
39+
->toBe('bool');
40+
});

0 commit comments

Comments
 (0)