Skip to content

Commit

Permalink
tests: improved
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 19, 2023
1 parent d7cf5bb commit 13c877a
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/Utils/FileSystem.normalizePath.phpt
Expand Up @@ -36,6 +36,10 @@ test('', function () {
Assert::same("..{$S}", FileSystem::normalizePath('file/../../'));
Assert::same("{$S}..{$S}bar", FileSystem::normalizePath('/file/../../bar'));
Assert::same("..{$S}bar", FileSystem::normalizePath('file/../../bar'));
Assert::same("..{$S}file", FileSystem::normalizePath('../file'));
Assert::same("{$S}..{$S}file", FileSystem::normalizePath('/../file'));
Assert::same('file', FileSystem::normalizePath('./file'));
Assert::same("{$S}file", FileSystem::normalizePath('/./file'));

Assert::same("{$S}..{$S}bar", FileSystem::normalizePath('/file/./.././.././bar'));
Assert::same("..{$S}bar", FileSystem::normalizePath('file/../../bar/.'));
Expand Down
163 changes: 163 additions & 0 deletions tests/Utils/SmartObject.undeclaredMethod.native.phpt
@@ -0,0 +1,163 @@
<?php

/**
* Test: PHP native error messages for undeclared method.
*/

declare(strict_types=1);

use Tester\Assert;

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


class ParentClass
{
public function callPrivate()
{
$this->privateMethod();
}


public function callPrivateStatic()
{
static::privateStaticMethod();
}


private function callPrivateParent()
{
}
}


class InterClass extends ParentClass
{
public function callParents()
{
parent::callParents();
}
}


class ChildClass extends InterClass
{
public function callParents()
{
parent::callParents();
}


public function callMissingParent()
{
parent::callMissingParent();
}


public static function callMissingParentStatic()
{
parent::callMissingParentStatic();
}


public function callPrivateParent()
{
parent::callPrivateParent();
}


protected function protectedMethod()
{
}


protected static function protectedStaticMethod()
{
}


private function privateMethod()
{
}


private static function privateStaticMethod()
{
}
}



$obj = new ParentClass;
Assert::exception(
fn() => $obj->undef(),
Error::class,
'Call to undefined method ParentClass::undef()',
);

$obj = new ChildClass;
Assert::exception(
fn() => $obj->undef(),
Error::class,
'Call to undefined method ChildClass::undef()',
);

Assert::exception(
fn() => $obj->callParents(),
Error::class,
'Call to undefined method ParentClass::callParents()',
);

Assert::exception(
fn() => $obj->callMissingParent(),
Error::class,
'Call to undefined method InterClass::callMissingParent()',
);

Assert::exception(
fn() => $obj->callMissingParentStatic(),
Error::class,
'Call to undefined method InterClass::callMissingParentStatic()',
);

Assert::exception(
fn() => $obj::callMissingParentStatic(),
Error::class,
'Call to undefined method InterClass::callMissingParentStatic()',
);

Assert::exception(
fn() => $obj->callPrivateParent(),
Error::class,
'Call to private method ParentClass::callPrivateParent() from scope ChildClass',
);

Assert::exception(
fn() => $obj->protectedMethod(),
Error::class,
'Call to protected method ChildClass::protectedMethod() from global scope',
);

Assert::exception(
fn() => $obj->protectedStaticMethod(),
Error::class,
'Call to protected method ChildClass::protectedStaticMethod() from global scope',
);

Assert::exception(
fn() => $obj::protectedStaticMethod(),
Error::class,
'Call to protected method ChildClass::protectedStaticMethod() from global scope',
);

Assert::exception(
fn() => $obj->callPrivate(),
Error::class,
'Call to private method ChildClass::privateMethod() from scope ParentClass',
);

Assert::exception(
fn() => $obj->callPrivateStatic(),
Error::class,
'Call to private method ChildClass::privateStaticMethod() from scope ParentClass',
);

0 comments on commit 13c877a

Please sign in to comment.