Skip to content

Commit

Permalink
tests: consolidated
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Sep 9, 2018
1 parent 8919116 commit db4152c
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 213 deletions.
40 changes: 0 additions & 40 deletions tests/Utils/Reflection.getParameterDefaultValue.php71.phpt

This file was deleted.

36 changes: 24 additions & 12 deletions tests/Utils/Reflection.getParameterDefaultValue.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,38 @@ Assert::exception(function () {
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'a'));
}, ReflectionException::class);

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

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

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

Assert::same(NS\Bar::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'e')));
Assert::same('abc', Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'e')));

Assert::same('abc', Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'f')));

Assert::same('abc', Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'g')));

Assert::same('abc', Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'h')));

Assert::exception(function () {
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'i'));
}, ReflectionException::class, 'Unable to resolve constant self::UNDEFINED used as default value of $i in NS\Foo::method().');

Assert::exception(function () {
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'f'));
}, ReflectionException::class, 'Unable to resolve constant self::UNDEFINED used as default value of $f in NS\Foo::method().');
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'j'));
}, ReflectionException::class, 'Unable to resolve constant NS\\Foo::UNDEFINED used as default value of $j in NS\Foo::method().');

Assert::same(NS\Bar::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'k')));

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

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

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

Assert::same(NS\NS_DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'j')));
Assert::same(NS\NS_DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'o')));
32 changes: 0 additions & 32 deletions tests/Utils/Reflection.getParameterType.php71.phpt

This file was deleted.

4 changes: 2 additions & 2 deletions tests/Utils/Reflection.getParameterType.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require __DIR__ . '/../bootstrap.php';

class A
{
public function method(Undeclared $undeclared, B $b, array $array, callable $callable, self $self, $none)
public function method(Undeclared $undeclared, B $b, array $array, callable $callable, self $self, $none, ?B $nullable)
{
}
}
Expand All @@ -37,7 +37,7 @@ Assert::same('array', Reflection::getParameterType($params[2]));
Assert::same('callable', Reflection::getParameterType($params[3]));
Assert::same('A', Reflection::getParameterType($params[4]));
Assert::null(Reflection::getParameterType($params[5]));

Assert::same('Test\B', Reflection::getParameterType($params[6]));

$method = new ReflectionMethod('AExt', 'methodExt');
$params = $method->getParameters();
Expand Down
67 changes: 0 additions & 67 deletions tests/Utils/Reflection.getReturnType.php7.phpt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ namespace NS
}


public function parentType(): parent
{
}


public function nullableClassType(): ?B
{
}
Expand All @@ -46,6 +51,13 @@ namespace NS
{
}
}

class AExt extends A
{
public function parentTypeExt(): parent
{
}
}
}

namespace
Expand All @@ -64,9 +76,13 @@ namespace

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

Assert::same('parent', Reflection::getReturnType(new \ReflectionMethod(NS\A::class, 'parentType')));

Assert::same('Test\B', Reflection::getReturnType(new \ReflectionMethod(NS\A::class, 'nullableClassType')));

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

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

Assert::same('NS\A', Reflection::getReturnType(new \ReflectionMethod(NS\AExt::class, 'parentTypeExt')));
}
2 changes: 1 addition & 1 deletion tests/Utils/Strings.Regexp.errors.backtrack.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ function cb()


Assert::exception(function () {
Strings::replace('0123456789', '#.*\d\d#', Nette\Utils\Callback::closure('cb'));
Strings::replace('0123456789', '#.*\d\d#', Closure::fromCallable('cb'));
}, Nette\Utils\RegexpException::class, 'Backtrack limit was exhausted (pattern: #.*\d\d#)');
4 changes: 2 additions & 2 deletions tests/Utils/Strings.Regexp.errors.compilation.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ function cb()


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

Assert::exception(function () {
Strings::replace('0123456789', ['##', '#*#'], Nette\Utils\Callback::closure('cb'));
Strings::replace('0123456789', ['##', '#*#'], Closure::fromCallable('cb'));
}, Nette\Utils\RegexpException::class, 'Compilation failed: %a% in pattern: ## or #*#');
2 changes: 1 addition & 1 deletion tests/Utils/Strings.Regexp.errors.utf8.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ function cb()


Assert::exception(function () {
Strings::replace("0123456789\xFF", '#\d#u', Nette\Utils\Callback::closure('cb'));
Strings::replace("0123456789\xFF", '#\d#u', Closure::fromCallable('cb'));
}, Nette\Utils\RegexpException::class, 'Malformed UTF-8 data (pattern: #\d#u)');
16 changes: 0 additions & 16 deletions tests/Utils/Strings.replace().php53.phpt

This file was deleted.

5 changes: 3 additions & 2 deletions tests/Utils/Strings.replace().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class Test
Assert::same('hello world!', Strings::replace('hello world!', '#([E-L])+#', '#'));
Assert::same('#o wor#d!', Strings::replace('hello world!', ['#([e-l])+#'], '#'));
Assert::same('#o wor#d!', Strings::replace('hello world!', '#([e-l])+#', '#'));
Assert::same('@o wor@d!', Strings::replace('hello world!', '#[e-l]+#', Nette\Utils\Callback::closure('Test::cb')));
Assert::same('@o wor@d!', Strings::replace('hello world!', ['#[e-l]+#'], Nette\Utils\Callback::closure('Test::cb')));
Assert::same('@o wor@d!', Strings::replace('hello world!', '#[e-l]+#', function () { return '@'; }));
Assert::same('@o wor@d!', Strings::replace('hello world!', '#[e-l]+#', Closure::fromCallable('Test::cb')));
Assert::same('@o wor@d!', Strings::replace('hello world!', ['#[e-l]+#'], Closure::fromCallable('Test::cb')));
Assert::same('@o wor@d!', Strings::replace('hello world!', '#[e-l]+#', ['Test', 'cb']));
Assert::same('#@ @@@#d!', Strings::replace('hello world!', [
'#([e-l])+#' => '#',
Expand Down
8 changes: 8 additions & 0 deletions tests/Utils/Strings.split().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ Assert::same([
',',
'c',
], Strings::split('a, b, c', '#(,)\s*#', PREG_SPLIT_NO_EMPTY));

Assert::same([
['a', 0],
[',', 1],
['b', 3],
[',', 4],
['c', 6],
], Strings::split('a, b, c', '#(,)\s*#', PREG_SPLIT_OFFSET_CAPTURE));
28 changes: 0 additions & 28 deletions tests/Utils/fixtures.reflection/defaultValue.71.php

This file was deleted.

27 changes: 17 additions & 10 deletions tests/Utils/fixtures.reflection/defaultValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,27 @@ interface Bar

class Foo
{
const DEFINED = 'abc';
public const PUBLIC_DEFINED = 'abc';
protected const PROTECTED_DEFINED = 'abc';
private const PRIVATE_DEFINED = 'abc';


public function method(
$a,
$b = self::DEFINED,
$c = Foo::DEFINED,
$d = SELF::DEFINED,
$e = bar::DEFINED,
$f = self::UNDEFINED,
$g = Undefined::ANY,
$h = DEFINED,
$i = UNDEFINED,
$j = NS_DEFINED
$b = self::PUBLIC_DEFINED,
$c = Foo::PUBLIC_DEFINED,
$d = SELF::PUBLIC_DEFINED,
$e = Foo::PROTECTED_DEFINED,
$f = self::PROTECTED_DEFINED,
$g = Foo::PRIVATE_DEFINED,
$h = self::PRIVATE_DEFINED,
$i = self::UNDEFINED,
$j = Foo::UNDEFINED,
$k = bar::DEFINED,
$l = Undefined::ANY,
$m = DEFINED,
$n = UNDEFINED,
$o = NS_DEFINED
) {
}
}

0 comments on commit db4152c

Please sign in to comment.