Skip to content

Commit d5726a5

Browse files
committed
ClassDeclaredContextTest: Test siblings in isAccessible
1 parent a738743 commit d5726a5

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Kint\Test\Fixtures;
4+
5+
class OtherChildTestClass extends TestClass
6+
{
7+
}

tests/Value/Context/ClassDeclaredContextTest.php

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
use __PHP_Incomplete_Class;
3131
use Kint\Test\Fixtures\ChildTestClass;
32+
use Kint\Test\Fixtures\OtherChildTestClass;
3233
use Kint\Test\Fixtures\TestClass;
3334
use Kint\Test\KintTestCase;
3435
use Kint\Value\Context\ClassDeclaredContext;
@@ -45,6 +46,10 @@ public function isAccessibleProvider()
4546
$pro = new PropertyContext('name', TestClass::class, ClassDeclaredContext::ACCESS_PROTECTED);
4647
$pri = new PropertyContext('name', TestClass::class, ClassDeclaredContext::ACCESS_PRIVATE);
4748

49+
$child_pub = new PropertyContext('name', ChildTestClass::class, ClassDeclaredContext::ACCESS_PUBLIC);
50+
$child_pro = new PropertyContext('name', ChildTestClass::class, ClassDeclaredContext::ACCESS_PROTECTED);
51+
$child_pri = new PropertyContext('name', ChildTestClass::class, ClassDeclaredContext::ACCESS_PRIVATE);
52+
4853
return [
4954
'global public' => [
5055
$pub,
@@ -61,36 +66,54 @@ public function isAccessibleProvider()
6166
null,
6267
false,
6368
],
64-
'shared public' => [
69+
'child public' => [
6570
$pub,
6671
ChildTestClass::class,
6772
true,
6873
],
69-
'shared protected' => [
74+
'child protected' => [
7075
$pro,
7176
ChildTestClass::class,
7277
true,
7378
],
74-
'shared private' => [
79+
'child private' => [
7580
$pri,
7681
ChildTestClass::class,
7782
false,
7883
],
79-
'reverse shared public' => [
80-
new PropertyContext('name', ChildTestClass::class, ClassDeclaredContext::ACCESS_PUBLIC),
84+
'parent public' => [
85+
$child_pub,
8186
TestClass::class,
8287
true,
8388
],
84-
'reverse shared protected' => [
85-
new PropertyContext('name', ChildTestClass::class, ClassDeclaredContext::ACCESS_PROTECTED),
89+
'parent protected' => [
90+
$child_pro,
8691
TestClass::class,
8792
true,
8893
],
89-
'reverse shared private' => [
90-
new PropertyContext('name', ChildTestClass::class, ClassDeclaredContext::ACCESS_PRIVATE),
94+
'parent private' => [
95+
$child_pri,
9196
TestClass::class,
9297
false,
9398
],
99+
// There is no need to test reverse siblings (ie. accessing an inherited property from
100+
// a child of the parent that redeclared it) because then the declaring class of the
101+
// property is the parent and we are identical to the 'child protected' test case
102+
'sibling public' => [
103+
$child_pub,
104+
OtherChildTestClass::class,
105+
true,
106+
],
107+
'sibling protected' => [
108+
$child_pro,
109+
OtherChildTestClass::class,
110+
false,
111+
],
112+
'sibling private' => [
113+
$child_pri,
114+
OtherChildTestClass::class,
115+
false,
116+
],
94117
'local public' => [
95118
$pub,
96119
TestClass::class,

0 commit comments

Comments
 (0)