Skip to content

Commit db4152c

Browse files
committedSep 9, 2018
tests: consolidated
1 parent 8919116 commit db4152c

14 files changed

+74
-213
lines changed
 

‎tests/Utils/Reflection.getParameterDefaultValue.php71.phpt

-40
This file was deleted.

‎tests/Utils/Reflection.getParameterDefaultValue.phpt

+24-12
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,38 @@ Assert::exception(function () {
1717
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'a'));
1818
}, ReflectionException::class);
1919

20-
Assert::same(NS\Foo::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'b')));
20+
Assert::same('abc', Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'b')));
2121

22-
Assert::same(NS\Foo::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'c')));
22+
Assert::same('abc', Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'c')));
2323

24-
Assert::same(NS\Foo::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'd')));
24+
Assert::same('abc', Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'd')));
2525

26-
Assert::same(NS\Bar::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'e')));
26+
Assert::same('abc', Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'e')));
27+
28+
Assert::same('abc', Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'f')));
29+
30+
Assert::same('abc', Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'g')));
31+
32+
Assert::same('abc', Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'h')));
33+
34+
Assert::exception(function () {
35+
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'i'));
36+
}, ReflectionException::class, 'Unable to resolve constant self::UNDEFINED used as default value of $i in NS\Foo::method().');
2737

2838
Assert::exception(function () {
29-
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'f'));
30-
}, ReflectionException::class, 'Unable to resolve constant self::UNDEFINED used as default value of $f in NS\Foo::method().');
39+
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'j'));
40+
}, ReflectionException::class, 'Unable to resolve constant NS\\Foo::UNDEFINED used as default value of $j in NS\Foo::method().');
41+
42+
Assert::same(NS\Bar::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'k')));
3143

3244
Assert::exception(function () {
33-
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'g'));
34-
}, ReflectionException::class, 'Unable to resolve constant NS\Undefined::ANY used as default value of $g in NS\Foo::method().');
45+
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'l'));
46+
}, ReflectionException::class, 'Unable to resolve constant NS\Undefined::ANY used as default value of $l in NS\Foo::method().');
3547

36-
Assert::same(DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'h')));
48+
Assert::same(DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'm')));
3749

3850
Assert::exception(function () {
39-
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'i'));
40-
}, ReflectionException::class, 'Unable to resolve constant NS\UNDEFINED used as default value of $i in NS\Foo::method().');
51+
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'n'));
52+
}, ReflectionException::class, 'Unable to resolve constant NS\UNDEFINED used as default value of $n in NS\Foo::method().');
4153

42-
Assert::same(NS\NS_DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'j')));
54+
Assert::same(NS\NS_DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'o')));

‎tests/Utils/Reflection.getParameterType.php71.phpt

-32
This file was deleted.

‎tests/Utils/Reflection.getParameterType.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require __DIR__ . '/../bootstrap.php';
1616

1717
class A
1818
{
19-
public function method(Undeclared $undeclared, B $b, array $array, callable $callable, self $self, $none)
19+
public function method(Undeclared $undeclared, B $b, array $array, callable $callable, self $self, $none, ?B $nullable)
2020
{
2121
}
2222
}
@@ -37,7 +37,7 @@ Assert::same('array', Reflection::getParameterType($params[2]));
3737
Assert::same('callable', Reflection::getParameterType($params[3]));
3838
Assert::same('A', Reflection::getParameterType($params[4]));
3939
Assert::null(Reflection::getParameterType($params[5]));
40-
40+
Assert::same('Test\B', Reflection::getParameterType($params[6]));
4141

4242
$method = new ReflectionMethod('AExt', 'methodExt');
4343
$params = $method->getParameters();

‎tests/Utils/Reflection.getReturnType.php7.phpt

-67
This file was deleted.

‎tests/Utils/Reflection.getReturnType.php71.phpt renamed to ‎tests/Utils/Reflection.getReturnType.phpt

+16
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ namespace NS
3232
}
3333

3434

35+
public function parentType(): parent
36+
{
37+
}
38+
39+
3540
public function nullableClassType(): ?B
3641
{
3742
}
@@ -46,6 +51,13 @@ namespace NS
4651
{
4752
}
4853
}
54+
55+
class AExt extends A
56+
{
57+
public function parentTypeExt(): parent
58+
{
59+
}
60+
}
4961
}
5062

5163
namespace
@@ -64,9 +76,13 @@ namespace
6476

6577
Assert::same('NS\A', Reflection::getReturnType(new \ReflectionMethod(NS\A::class, 'selfType')));
6678

79+
Assert::same('parent', Reflection::getReturnType(new \ReflectionMethod(NS\A::class, 'parentType')));
80+
6781
Assert::same('Test\B', Reflection::getReturnType(new \ReflectionMethod(NS\A::class, 'nullableClassType')));
6882

6983
Assert::same('string', Reflection::getReturnType(new \ReflectionMethod(NS\A::class, 'nullableNativeType')));
7084

7185
Assert::same('NS\A', Reflection::getReturnType(new \ReflectionMethod(NS\A::class, 'nullableSelfType')));
86+
87+
Assert::same('NS\A', Reflection::getReturnType(new \ReflectionMethod(NS\AExt::class, 'parentTypeExt')));
7288
}

‎tests/Utils/Strings.Regexp.errors.backtrack.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ function cb()
4040

4141

4242
Assert::exception(function () {
43-
Strings::replace('0123456789', '#.*\d\d#', Nette\Utils\Callback::closure('cb'));
43+
Strings::replace('0123456789', '#.*\d\d#', Closure::fromCallable('cb'));
4444
}, Nette\Utils\RegexpException::class, 'Backtrack limit was exhausted (pattern: #.*\d\d#)');

‎tests/Utils/Strings.Regexp.errors.compilation.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ function cb()
4141

4242

4343
Assert::exception(function () {
44-
Strings::replace('0123456789', '#*#', Nette\Utils\Callback::closure('cb'));
44+
Strings::replace('0123456789', '#*#', Closure::fromCallable('cb'));
4545
}, Nette\Utils\RegexpException::class, 'Compilation failed: %a% in pattern: #*#');
4646

4747
Assert::exception(function () {
48-
Strings::replace('0123456789', ['##', '#*#'], Nette\Utils\Callback::closure('cb'));
48+
Strings::replace('0123456789', ['##', '#*#'], Closure::fromCallable('cb'));
4949
}, Nette\Utils\RegexpException::class, 'Compilation failed: %a% in pattern: ## or #*#');

‎tests/Utils/Strings.Regexp.errors.utf8.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ function cb()
3737

3838

3939
Assert::exception(function () {
40-
Strings::replace("0123456789\xFF", '#\d#u', Nette\Utils\Callback::closure('cb'));
40+
Strings::replace("0123456789\xFF", '#\d#u', Closure::fromCallable('cb'));
4141
}, Nette\Utils\RegexpException::class, 'Malformed UTF-8 data (pattern: #\d#u)');

‎tests/Utils/Strings.replace().php53.phpt

-16
This file was deleted.

‎tests/Utils/Strings.replace().phpt

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ class Test
2424
Assert::same('hello world!', Strings::replace('hello world!', '#([E-L])+#', '#'));
2525
Assert::same('#o wor#d!', Strings::replace('hello world!', ['#([e-l])+#'], '#'));
2626
Assert::same('#o wor#d!', Strings::replace('hello world!', '#([e-l])+#', '#'));
27-
Assert::same('@o wor@d!', Strings::replace('hello world!', '#[e-l]+#', Nette\Utils\Callback::closure('Test::cb')));
28-
Assert::same('@o wor@d!', Strings::replace('hello world!', ['#[e-l]+#'], Nette\Utils\Callback::closure('Test::cb')));
27+
Assert::same('@o wor@d!', Strings::replace('hello world!', '#[e-l]+#', function () { return '@'; }));
28+
Assert::same('@o wor@d!', Strings::replace('hello world!', '#[e-l]+#', Closure::fromCallable('Test::cb')));
29+
Assert::same('@o wor@d!', Strings::replace('hello world!', ['#[e-l]+#'], Closure::fromCallable('Test::cb')));
2930
Assert::same('@o wor@d!', Strings::replace('hello world!', '#[e-l]+#', ['Test', 'cb']));
3031
Assert::same('#@ @@@#d!', Strings::replace('hello world!', [
3132
'#([e-l])+#' => '#',

‎tests/Utils/Strings.split().phpt

+8
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ Assert::same([
2828
',',
2929
'c',
3030
], Strings::split('a, b, c', '#(,)\s*#', PREG_SPLIT_NO_EMPTY));
31+
32+
Assert::same([
33+
['a', 0],
34+
[',', 1],
35+
['b', 3],
36+
[',', 4],
37+
['c', 6],
38+
], Strings::split('a, b, c', '#(,)\s*#', PREG_SPLIT_OFFSET_CAPTURE));

‎tests/Utils/fixtures.reflection/defaultValue.71.php

-28
This file was deleted.

‎tests/Utils/fixtures.reflection/defaultValue.php

+17-10
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,27 @@ interface Bar
1515

1616
class Foo
1717
{
18-
const DEFINED = 'abc';
18+
public const PUBLIC_DEFINED = 'abc';
19+
protected const PROTECTED_DEFINED = 'abc';
20+
private const PRIVATE_DEFINED = 'abc';
1921

2022

2123
public function method(
2224
$a,
23-
$b = self::DEFINED,
24-
$c = Foo::DEFINED,
25-
$d = SELF::DEFINED,
26-
$e = bar::DEFINED,
27-
$f = self::UNDEFINED,
28-
$g = Undefined::ANY,
29-
$h = DEFINED,
30-
$i = UNDEFINED,
31-
$j = NS_DEFINED
25+
$b = self::PUBLIC_DEFINED,
26+
$c = Foo::PUBLIC_DEFINED,
27+
$d = SELF::PUBLIC_DEFINED,
28+
$e = Foo::PROTECTED_DEFINED,
29+
$f = self::PROTECTED_DEFINED,
30+
$g = Foo::PRIVATE_DEFINED,
31+
$h = self::PRIVATE_DEFINED,
32+
$i = self::UNDEFINED,
33+
$j = Foo::UNDEFINED,
34+
$k = bar::DEFINED,
35+
$l = Undefined::ANY,
36+
$m = DEFINED,
37+
$n = UNDEFINED,
38+
$o = NS_DEFINED
3239
) {
3340
}
3441
}

0 commit comments

Comments
 (0)
Please sign in to comment.