Skip to content

Commit 76ede70

Browse files
committed
test: add tests for toString, textInfo, and weekInfo
1 parent 986b06e commit 76ede70

File tree

7 files changed

+531
-26
lines changed

7 files changed

+531
-26
lines changed

NOTICE

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ Copyright (c) 2011, 2012 Norbert Lindenberg. All rights reserved.
99
Copyright (c) 2012, 2013, 2016, 2020 Mozilla Corporation. All rights reserved.
1010
Copyright (c) 2017, 2020, 2021 André Bargull. All rights reserved.
1111
Copyright (c) 2018 André Bargull; Igalia, S.L. All rights reserved.
12-
Copyright (c) 2018 Igalia, S.L. All rights reserved.
12+
Copyright (c) 2018, 2021 Igalia, S.L. All rights reserved.
1313
Copyright (c) 2018 Rick Waldron. All rights reserved.
1414
Copyright (c) 2019 Google Inc. All rights reserved.
15-
Copyright (c) 2020 Apple Inc. All rights reserved.
15+
Copyright (c) 2020, 2021 Apple Inc. All rights reserved.
1616
Copyright (c) 2020 Jeff Walden, Mozilla Corporation. All rights reserved.
1717

1818
The << Software identified by reference to the Ecma Standard* ("Software)">> is protected by copyright and is being

resources/ext

Submodule ext updated 53 files
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Ecma\Intl\Locale\CharacterDirection;
6+
use Ecma\Intl\Locale\TextInfo;
7+
8+
$reflected = new ReflectionClass(TextInfo::class);
9+
10+
test('its FQCN is Ecma\\Intl\\Locale\\TextInfo')
11+
->expect($reflected->getName())
12+
->toBe('Ecma\\Intl\\Locale\\TextInfo');
13+
14+
it('has a property named "direction"')
15+
->expect($reflected->hasProperty('direction'))
16+
->toBeTrue();
17+
18+
it('has a __construct method')
19+
->expect($reflected->hasMethod('__construct'))
20+
->toBeTrue();
21+
22+
it('implements JsonSerializable')
23+
->expect($reflected->getInterfaceNames())
24+
->toContain(JsonSerializable::class);
25+
26+
describe('TextInfo::__construct', function () use ($reflected): void {
27+
$constructor = $reflected->getMethod('__construct');
28+
29+
it('is public')
30+
->expect($constructor->isPublic())
31+
->toBeTrue();
32+
33+
it('has one required parameter')
34+
->expect($constructor->getNumberOfRequiredParameters())
35+
->toBe(1);
36+
37+
$parameter = $constructor->getParameters()[0] ?? null;
38+
39+
test('its first parameter is $direction')
40+
->expect($parameter)
41+
->not->toBeNull()
42+
->and($parameter->getName())
43+
->toBe('direction')
44+
->and($parameter->getType())
45+
->toBeInstanceOf(ReflectionType::class)
46+
->and($parameter->getType()->getName())
47+
->toBe(CharacterDirection::class)
48+
->and($parameter->getType()->allowsNull())
49+
->toBeFalse();
50+
});
51+
52+
describe('TextInfo::$direction', function () use ($reflected): void {
53+
$property = $reflected->getProperty('direction');
54+
$type = $property->getType();
55+
56+
test('its name is "direction"')
57+
->expect($property->getName())
58+
->toBe('direction');
59+
60+
it('is a public property')
61+
->expect($property->isPublic())
62+
->toBeTrue();
63+
64+
it('is not a static property')
65+
->expect($property->isStatic())
66+
->toBeFalse();
67+
68+
it('is a readonly property')
69+
->expect($property->isReadOnly())
70+
->toBeTrue();
71+
72+
it('is a CharacterDirection type and does not allow null values')
73+
->expect($type)
74+
->toBeInstanceOf(ReflectionType::class)
75+
->and($type->allowsNull())
76+
->toBeFalse()
77+
->and($type->getName())
78+
->toBe(CharacterDirection::class);
79+
});
80+
81+
describe('TextInfo::jsonSerialize', function () use ($reflected): void {
82+
$jsonSerialize = $reflected->getMethod('jsonSerialize');
83+
84+
it('is public')
85+
->expect($jsonSerialize->isPublic())
86+
->toBeTrue();
87+
88+
it('has a return type hint of "object"')
89+
->expect($jsonSerialize->getReturnType()?->getName())
90+
->toBe('object')
91+
->expect($jsonSerialize->getReturnType()?->allowsNull())
92+
->toBeFalse();
93+
94+
it('has zero parameters')
95+
->expect($jsonSerialize->getNumberOfParameters())
96+
->toBe(0);
97+
});
98+
99+
describe('CharacterDirection', function (): void {
100+
it('is a backed enum')
101+
->expect(is_a(CharacterDirection::class, BackedEnum::class, true))
102+
->toBeTrue();
103+
104+
it('has a LeftToRight case with value "ltr"')
105+
->expect(CharacterDirection::tryFrom('ltr'))
106+
->toBe(CharacterDirection::LeftToRight)
107+
->and(CharacterDirection::LeftToRight->value)
108+
->toBe('ltr');
109+
110+
it('has a RightToLeft case with value "rtl"')
111+
->expect(CharacterDirection::tryFrom('rtl'))
112+
->toBe(CharacterDirection::RightToLeft)
113+
->and(CharacterDirection::RightToLeft->value)
114+
->toBe('rtl');
115+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Ecma\Intl\Locale;
6+
use Ecma\Intl\Locale\TextInfo;
7+
8+
$reflected = new ReflectionClass(Locale::class);
9+
10+
it('has textInfo')
11+
->expect($reflected->hasProperty('textInfo'))
12+
->toBeTrue()
13+
->and($reflected->hasMethod('getTextInfo'))
14+
->toBeTrue();
15+
16+
describe('Locale::$textInfo', function () use ($reflected): void {
17+
$property = $reflected->getProperty('textInfo');
18+
$type = $property->getType();
19+
20+
test('its name is "textInfo"')
21+
->expect($property->getName())
22+
->toBe('textInfo');
23+
24+
it('is a public property')
25+
->expect($property->isPublic())
26+
->toBeTrue();
27+
28+
it('is not a static property')
29+
->expect($property->isStatic())
30+
->toBeFalse();
31+
32+
it('is a readonly property')
33+
->expect($property->isReadOnly())
34+
->toBeTrue();
35+
36+
it('is a TextInfo type and does not allow null values')
37+
->expect($type)
38+
->toBeInstanceOf(ReflectionType::class)
39+
->and($type->allowsNull())
40+
->toBeFalse()
41+
->and($type->getName())
42+
->toBe(TextInfo::class);
43+
});
44+
45+
describe('Locale::getTextInfo', function () use ($reflected): void {
46+
$method = $reflected->getMethod('getTextInfo');
47+
$returnType = $method->getReturnType();
48+
49+
test('its name is "getTextInfo"')
50+
->expect($method->getName())
51+
->toBe('getTextInfo');
52+
53+
it('is a public method')
54+
->expect($method->isPublic())
55+
->toBeTrue();
56+
57+
it('is not a static method')
58+
->expect($method->isStatic())
59+
->toBeFalse();
60+
61+
it('returns a TextInfo type and does not return null')
62+
->expect($returnType)
63+
->toBeInstanceOf(ReflectionType::class)
64+
->and($returnType->allowsNull())
65+
->toBeFalse()
66+
->and($returnType->getName())
67+
->toBe(TextInfo::class);
68+
});

tests/intl402/Locale/prototype/toString/prop-desc.php

+55-23
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,65 @@
55
use Ecma\Intl\Locale;
66

77
$reflected = new ReflectionClass(Locale::class);
8-
$method = $reflected->getMethod('__toString');
9-
$returnType = $method->getReturnType();
108

119
it('implements Stringable')
1210
->expect($reflected->implementsInterface(Stringable::class))
1311
->toBeTrue();
1412

15-
test('its name is "__toString"')
16-
->expect($method->getName())
17-
->toBe('__toString');
13+
describe('Locale::__toString', function () use ($reflected): void {
14+
$method = $reflected->getMethod('__toString');
15+
$returnType = $method->getReturnType();
1816

19-
it('is a public method')
20-
->expect($method->isPublic())
21-
->toBeTrue();
17+
test('its name is "__toString"')
18+
->expect($method->getName())
19+
->toBe('__toString');
20+
21+
it('is a public method')
22+
->expect($method->isPublic())
23+
->toBeTrue();
24+
25+
it('is not a static method')
26+
->expect($method->isStatic())
27+
->toBeFalse();
28+
29+
it('has zero parameters')
30+
->expect($method->getNumberOfParameters())
31+
->toBe(0);
32+
33+
it('returns a string type')
34+
->expect($returnType)
35+
->toBeInstanceOf(ReflectionType::class)
36+
->and($returnType->allowsNull())
37+
->toBeFalse()
38+
->and($returnType->getName())
39+
->toBe('string');
40+
});
41+
42+
describe('Locale::toString', function () use ($reflected): void {
43+
$method = $reflected->getMethod('toString');
44+
$returnType = $method->getReturnType();
45+
46+
test('its name is "toString"')
47+
->expect($method->getName())
48+
->toBe('toString');
49+
50+
it('is a public method')
51+
->expect($method->isPublic())
52+
->toBeTrue();
53+
54+
it('is not a static method')
55+
->expect($method->isStatic())
56+
->toBeFalse();
57+
58+
it('has zero parameters')
59+
->expect($method->getNumberOfParameters())
60+
->toBe(0);
2261

23-
it('is not a static method')
24-
->expect($method->isStatic())
25-
->toBeFalse();
26-
27-
it('has zero parameters')
28-
->expect($method->getNumberOfParameters())
29-
->toBe(0);
30-
31-
it('returns a string type')
32-
->expect($returnType)
33-
->toBeInstanceOf(ReflectionType::class)
34-
->and($returnType->allowsNull())
35-
->toBeFalse()
36-
->and($returnType->getName())
37-
->toBe('string');
62+
it('returns a string type')
63+
->expect($returnType)
64+
->toBeInstanceOf(ReflectionType::class)
65+
->and($returnType->allowsNull())
66+
->toBeFalse()
67+
->and($returnType->getName())
68+
->toBe('string');
69+
});

0 commit comments

Comments
 (0)