404

[ Avaa Bypassed ]




Upload:

Command:

elspacio@3.145.76.12: ~ $
<?php

/**
 * Test: Nette\Utils\Callback closures tests.
 */

declare(strict_types=1);

use Nette\Utils\Callback;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';


class Test
{
	public function __invoke($a)
	{
		return __METHOD__ . $a;
	}


	public function publicFun($a)
	{
		return __METHOD__ . $a;
	}


	private function privateFun($a)
	{
		return __METHOD__ . $a;
	}


	public static function publicStatic($a)
	{
		return __METHOD__ . $a;
	}


	private static function privateStatic($a)
	{
		return __METHOD__ . $a;
	}


	public function createPrivateClosure(): Closure
	{
		return Closure::fromCallable([$this, 'privateFun']);
	}


	public static function createPrivateStaticClosure(): Closure
	{
		return Closure::fromCallable([self::class, 'privateStatic']);
	}


	public function ref(&$a)
	{
		$a = __METHOD__;
		return $a;
	}
}


class TestDynamic
{
	public function __call($nm, $args)
	{
		return __METHOD__ . " $nm $args[0]";
	}


	public static function __callStatic($nm, $args)
	{
		return __METHOD__ . " $nm $args[0]";
	}
}

class TestChild extends Test
{
}


function getName($ref)
{
	if ($ref instanceof ReflectionFunction) {
		return $ref->getName();
	} elseif ($ref instanceof ReflectionMethod) {
		return $ref->getDeclaringClass()->getName() . '::' . $ref->getName();
	}
}


test('global function', function () {
	Assert::same('trim', Callback::unwrap(Closure::fromCallable('trim')));
	Assert::same('trim', Callback::toString('trim'));
	Assert::same('{closure trim}', Callback::toString(Closure::fromCallable('trim')));
	Assert::same('trim', getName(Callback::toReflection('trim')));
	Assert::same('trim', getName(Callback::toReflection(Closure::fromCallable('trim'))));
	Assert::same('x', Closure::fromCallable('trim')->__invoke(' x '));


	Assert::same('undefined', Callback::toString('undefined'));

	Assert::exception(
		fn() => Callback::toReflection('undefined'),
		ReflectionException::class,
		'Function undefined() does not exist',
	);
});


test('closure', function () {
	$closure = function (&$a) {
		$a = __FUNCTION__;
		return $a;
	};
	Assert::same($closure, Closure::fromCallable($closure));
	Assert::same($closure, Callback::unwrap($closure));
	Assert::same('{closure}', Callback::toString($closure));
	Assert::same('{closure}', getName(Callback::toReflection($closure)));
	Assert::same('{closure}', Closure::fromCallable($closure)(...[&$res]));
	Assert::same('{closure}', $res);
});


test('invokable object', function () {
	$test = new Test;
	Assert::same([$test, '__invoke'], Callback::unwrap(Closure::fromCallable($test)));
	Assert::same('Test::__invoke', Callback::toString($test));
	Assert::same('{closure Test::__invoke}', Callback::toString(Closure::fromCallable($test)));
	Assert::same('Test::__invoke', getName(Callback::toReflection($test)));
	Assert::same('Test::__invoke', getName(Callback::toReflection(Closure::fromCallable($test))));
	Assert::same('Test::__invoke*', Closure::fromCallable($test)->__invoke('*'));
});


test('object methods', function () {
	$test = new Test;
	Assert::same([$test, 'publicFun'], Callback::unwrap(Closure::fromCallable([$test, 'publicFun'])));

	Assert::same('Test::publicFun', Callback::toString([$test, 'publicFun']));
	Assert::same('{closure Test::publicFun}', Callback::toString(Closure::fromCallable([$test, 'publicFun'])));

	Assert::same('Test::publicFun', getName(Callback::toReflection([$test, 'publicFun'])));
	Assert::same('Test::publicFun', getName(Callback::toReflection(Closure::fromCallable([$test, 'publicFun']))));

	Assert::same('Test::publicFun*', Closure::fromCallable([$test, 'publicFun'])->__invoke('*'));


	Assert::same([$test, 'privateFun'], Callback::unwrap($test->createPrivateClosure()));

	Assert::same('Test::privateFun', Callback::toString([$test, 'privateFun']));
	Assert::same('{closure Test::privateFun}', Callback::toString($test->createPrivateClosure()));

	Assert::same('Test::privateFun', getName(Callback::toReflection([$test, 'privateFun'])));
	Assert::same('Test::privateFun', getName(Callback::toReflection($test->createPrivateClosure())));
	Assert::same('Test::privateFun', getName(Callback::toReflection((new TestChild)->createPrivateClosure())));

	Assert::same('Test::privateFun*', $test->createPrivateClosure()->__invoke('*'));

	Assert::same('Test::ref', Closure::fromCallable([$test, 'ref'])(...[&$res]));
	Assert::same('Test::ref', $res);
});


test('static methods', function () {
	$test = new Test;
	Assert::same(['Test', 'publicStatic'], Callback::unwrap(Closure::fromCallable(['Test', 'publicStatic'])));
	Assert::same(['Test', 'publicStatic'], Callback::unwrap(Closure::fromCallable('Test::publicStatic')));

	Assert::same('Test::publicStatic', Callback::toString(['Test', 'publicStatic']));
	Assert::same('Test::publicStatic', Callback::toString([$test, 'publicStatic']));
	Assert::same('Test::publicStatic', Callback::toString('Test::publicStatic'));
	Assert::same('{closure Test::publicStatic}', Callback::toString(Closure::fromCallable('Test::publicStatic')));

	Assert::same('Test::publicStatic', getName(Callback::toReflection(['Test', 'publicStatic'])));
	Assert::same('Test::publicStatic', getName(Callback::toReflection([$test, 'publicStatic'])));
	Assert::same('Test::publicStatic', getName(Callback::toReflection('Test::publicStatic')));
	Assert::same('Test::publicStatic', getName(Callback::toReflection(Closure::fromCallable('Test::publicStatic'))));

	Assert::same('Test::publicStatic*', Closure::fromCallable(['Test', 'publicStatic'])->__invoke('*'));
	Assert::same('Test::publicStatic*', Closure::fromCallable([$test, 'publicStatic'])->__invoke('*'));


	Assert::same(['Test', 'privateStatic'], Callback::unwrap(Test::createPrivateStaticClosure()));
	Assert::same('Test::privateStatic', Callback::toString('Test::privateStatic'));
	Assert::same('{closure Test::privateStatic}', Callback::toString(Test::createPrivateStaticClosure()));
	Assert::same('Test::privateStatic', getName(Callback::toReflection('Test::privateStatic')));
	Assert::same('Test::privateStatic', getName(Callback::toReflection(Test::createPrivateStaticClosure())));
	Assert::same('Test::privateStatic', getName(Callback::toReflection(TestChild::createPrivateStaticClosure())));

	Assert::same('Test::privateStatic*', Test::createPrivateStaticClosure()->__invoke('*'));
});


test('magic methods', function () {
	$test = new TestDynamic;
	Assert::same([$test, 'magic'], Callback::unwrap(Closure::fromCallable([$test, 'magic'])));
	Assert::same('TestDynamic::magic', Callback::toString([$test, 'magic']));
	Assert::same('{closure TestDynamic::magic}', Callback::toString(Closure::fromCallable([$test, 'magic'])));
	Assert::same('TestDynamic::__call magic *', Closure::fromCallable([$test, 'magic'])->__invoke('*'));

	Assert::same(['TestDynamic', 'magic'], Callback::unwrap(Closure::fromCallable('TestDynamic::magic')));
	Assert::same('TestDynamic::magic', Callback::toString('TestDynamic::magic'));
	Assert::same('{closure TestDynamic::magic}', Callback::toString(Closure::fromCallable('TestDynamic::magic')));
	Assert::same('TestDynamic::__callStatic magic *', Closure::fromCallable('TestDynamic::magic')->__invoke('*'));

	Assert::exception(
		fn() => Callback::toReflection([new TestDynamic, 'magic']),
		ReflectionException::class,
		'Method TestDynamic::magic() does not exist',
	);

	Assert::exception(
		fn() => Callback::toReflection(Closure::fromCallable([new TestDynamic, 'magic'])),
		ReflectionException::class,
		'Method TestDynamic::magic() does not exist',
	);
});


test('PHP bugs - is_callable($object, true) fails', function () {
	Assert::same('stdClass::__invoke', Callback::toString(new stdClass));

	Assert::exception(
		fn() => Callback::toReflection(new stdClass),
		ReflectionException::class,
		'Method stdClass::__invoke() does not exist',
	);
});

Filemanager

Name Type Size Permission Actions
expected Folder 0755
fixtures.finder Folder 0755
fixtures.finder2 Folder 0755
fixtures.images Folder 0755
fixtures.reflection Folder 0755
ArrayHash.phpt File 4.35 KB 0644
ArrayList.phpt File 3.18 KB 0644
Arrays.associate().error.phpt File 384 B 0644
Arrays.associate().phpt File 4.1 KB 0644
Arrays.contains().phpt File 369 B 0644
Arrays.every().phpt File 2.03 KB 0644
Arrays.first().phpt File 393 B 0644
Arrays.flatten().phpt File 552 B 0644
Arrays.get().phpt File 901 B 0644
Arrays.getKeyOffset().phpt File 574 B 0644
Arrays.getRef().phpt File 1.29 KB 0644
Arrays.grep().errors.phpt File 541 B 0644
Arrays.grep().phpt File 455 B 0644
Arrays.insertBefore().phpt File 1.62 KB 0644
Arrays.invoke.phpt File 639 B 0644
Arrays.invokeMethod.phpt File 555 B 0644
Arrays.isList.phpt File 558 B 0644
Arrays.last().phpt File 376 B 0644
Arrays.map().phpt File 1.34 KB 0644
Arrays.normalize.phpt File 539 B 0644
Arrays.pick().phpt File 623 B 0644
Arrays.renameKey().phpt File 1.36 KB 0644
Arrays.renameKey().ref.phpt File 540 B 0644
Arrays.some().phpt File 1.98 KB 0644
Arrays.toKey.phpt File 372 B 0644
Arrays.toObject.phpt File 848 B 0644
Arrays.wrap().phpt File 955 B 0644
Callback.check.phpt File 963 B 0644
Callback.closure.phpt File 7.85 KB 0644
Callback.invokeSafe.phpt File 1.57 KB 0644
DateTime.JSON.phpt File 316 B 0644
DateTime.createFromFormat.phpt File 909 B 0644
DateTime.from.phpt File 1.28 KB 0644
DateTime.fromParts.phpt File 2.46 KB 0644
DateTime.modifyClone.phpt File 600 B 0644
FileSystem.copy.phpt File 2.28 KB 0644
FileSystem.createDir.phpt File 516 B 0644
FileSystem.delete.phpt File 566 B 0644
FileSystem.isAbsolute.phpt File 871 B 0644
FileSystem.joinPaths.phpt File 527 B 0644
FileSystem.makeWritable.phpt File 922 B 0644
FileSystem.normalizePath.phpt File 2.34 KB 0644
FileSystem.open.phpt File 426 B 0644
FileSystem.platformSlashes.phpt File 454 B 0644
FileSystem.read-write.phpt File 694 B 0644
FileSystem.readLines.phpt File 803 B 0644
FileSystem.rename.phpt File 2.01 KB 0644
FileSystem.unixSlashes.phpt File 264 B 0644
Finder.append.phpt File 1013 B 0644
Finder.basic.phpt File 3.89 KB 0644
Finder.errors.phpt File 662 B 0644
Finder.fileInfo.phpt File 1.2 KB 0644
Finder.filters.phpt File 2.05 KB 0644
Finder.mask.phpt File 5.87 KB 0644
Finder.multiple.phpt File 1.29 KB 0644
Finder.phar.phpt File 1.06 KB 0644
Finder.sort.phpt File 1.54 KB 0644
Floats.areEqual().phpt File 1.18 KB 0644
Floats.compare().phpt File 884 B 0644
Floats.isGreaterThan().phpt File 870 B 0644
Floats.isGreaterThanOrEqualTo().phpt File 990 B 0644
Floats.isInteger().phpt File 601 B 0644
Floats.isLessThan().phpt File 829 B 0644
Floats.isLessThanOrEqualTo().phpt File 949 B 0644
Floats.isZero().phpt File 546 B 0644
Helpers.capture().phpt File 465 B 0644
Helpers.clamp().phpt File 475 B 0644
Helpers.compare().phpt File 1.43 KB 0644
Helpers.falseToNull().phpt File 410 B 0644
Helpers.getLastError().phpt File 481 B 0644
Helpers.getSuggestion().phpt File 1.05 KB 0644
Html.basic.phpt File 6.31 KB 0644
Html.children.phpt File 2.14 KB 0644
Html.construct.phpt File 1021 B 0644
Html.data.phpt File 1.68 KB 0644
Html.style.phpt File 2.97 KB 0644
Image.alpha1.phpt File 942 B 0644
Image.alpha2.phpt File 2 KB 0644
Image.clone.phpt File 634 B 0644
Image.drawing.phpt File 1.28 KB 0644
Image.factories.phpt File 2.85 KB 0644
Image.place.phpt File 481 B 0644
Image.resize.phpt File 4.08 KB 0644
Image.save.phpt File 2.4 KB 0644
Image.send.phpt File 1.19 KB 0644
Json.decode().phpt File 2.23 KB 0644
Json.encode().phpt File 1.94 KB 0644
ObjectHelpers.getMagicProperites().phpt File 1.98 KB 0644
ObjectHelpers.getSuggestion().phpt File 2.14 KB 0644
ObjectHelpers.strictness.phpt File 3.57 KB 0644
Paginator.phpt File 4.23 KB 0644
Random.generate().phpt File 1.33 KB 0644
Reflection.expandClassName.phpt File 3.84 KB 0644
Reflection.getDeclaringMethod.alias.phpt File 2.21 KB 0644
Reflection.getDeclaringMethod.insteadof.phpt File 1000 B 0644
Reflection.getDeclaringMethod.overwrite.phpt File 1011 B 0644
Reflection.getDeclaringMethod.phpt File 976 B 0644
Reflection.getParameterDefaultValue.phpt File 2.64 KB 0644
Reflection.getPropertyDeclaringClass.overwrite.phpt File 1.03 KB 0644
Reflection.getPropertyDeclaringClass.overwrite2.phpt File 966 B 0644
Reflection.getPropertyDeclaringClass.phpt File 945 B 0644
Reflection.groupUseStatements.phpt File 416 B 0644
Reflection.nonClassUseStatements.phpt File 366 B 0644
Reflection.toString.phpt File 851 B 0644
SmartObject.arrayProperty.phpt File 510 B 0644
SmartObject.events.phpt File 1.63 KB 0644
SmartObject.property.inheritance.phpt File 1.93 KB 0644
SmartObject.property.phpt File 2.72 KB 0644
SmartObject.referenceProperty.phpt File 527 B 0644
SmartObject.undeclaredMethod.annotation.phpt File 1.95 KB 0644
SmartObject.undeclaredMethod.hints.phpt File 1.27 KB 0644
SmartObject.undeclaredMethod.phpt File 3.31 KB 0644
SmartObject.unsetProperty.phpt File 761 B 0644
StaticClass.phpt File 539 B 0644
Strings.Regexp.errors.backtrack.phpt File 1.2 KB 0644
Strings.Regexp.errors.compilation.phpt File 1.41 KB 0644
Strings.Regexp.errors.utf8.phpt File 1.24 KB 0644
Strings.after().phpt File 1.45 KB 0644
Strings.before().phpt File 1.47 KB 0644
Strings.checkEncoding().phpt File 512 B 0644
Strings.chr().phpt File 910 B 0644
Strings.compare().phpt File 1.17 KB 0644
Strings.contains().phpt File 673 B 0644
Strings.convertCase.phpt File 583 B 0644
Strings.endsWith().phpt File 631 B 0644
Strings.findPrefix().phpt File 1.42 KB 0644
Strings.fixEncoding().phpt File 8.68 KB 0644
Strings.indent().phpt File 700 B 0644
Strings.indexOf().phpt File 1.44 KB 0644
Strings.length().phpt File 582 B 0644
Strings.match().phpt File 1.4 KB 0644
Strings.matchAll().phpt File 2.69 KB 0644
Strings.normalize().phpt File 1.04 KB 0644
Strings.normalizeNewLines().phpt File 326 B 0644
Strings.ord().phpt File 1.12 KB 0644
Strings.pad.phpt File 1.35 KB 0644
Strings.platformNewLines().phpt File 424 B 0644
Strings.replace().errors.callback.phpt File 605 B 0644
Strings.replace().phpt File 1.85 KB 0644
Strings.reverse().phpt File 603 B 0644
Strings.split().phpt File 1.28 KB 0644
Strings.startsWith().phpt File 655 B 0644
Strings.substring().phpt File 1.74 KB 0644
Strings.toAscii().phpt File 1.62 KB 0644
Strings.trim().phpt File 518 B 0644
Strings.truncate().phpt File 2.99 KB 0644
Strings.unixNewLines().phpt File 377 B 0644
Strings.webalize().phpt File 899 B 0644
Type.allows.phpt File 2.37 KB 0644
Type.fromReflection.function.80.phpt File 1 KB 0644
Type.fromReflection.function.81.phpt File 1.32 KB 0644
Type.fromReflection.function.82.phpt File 1.51 KB 0644
Type.fromReflection.function.phpt File 639 B 0644
Type.fromReflection.method.phpt File 824 B 0644
Type.fromReflection.parameter.phpt File 708 B 0644
Type.fromReflection.property.74.phpt File 773 B 0644
Type.fromReflection.property.phpt File 254 B 0644
Type.fromString.phpt File 5.84 KB 0644
Validators.assert().phpt File 2.02 KB 0644
Validators.assertField().phpt File 713 B 0644
Validators.everyIs().phpt File 1.5 KB 0644
Validators.is().phpt File 13.79 KB 0644
Validators.isBuiltinType.phpt File 541 B 0644
Validators.isInRange().phpt File 2.1 KB 0644
Validators.isNumeric().phpt File 1.15 KB 0644
Validators.isTypeDeclaration.phpt File 1.34 KB 0644