Skip to content

Commit 80dcb3e

Browse files
authored
Cover changes with unit test
1 parent f4fd1bd commit 80dcb3e

File tree

1 file changed

+98
-0
lines changed
  • lib/internal/Magento/Framework/Code/Test/Unit/Reader/https:/github.com/ven-com/magento2/tree

1 file changed

+98
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
*
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\Framework\Code\Test\Unit\Reader;
10+
11+
use Magento\Framework\Code\Reader\ClassReader;
12+
use PHPUnit\Framework\TestCase;
13+
14+
require_once __DIR__ . '/_files/ClassesForArgumentsReader.php';
15+
16+
class ClassReaderTest extends TestCase
17+
{
18+
19+
/**
20+
* @var ClassReader $model
21+
*/
22+
private $model;
23+
24+
/**
25+
* @inheritDoc
26+
*/
27+
protected function setUp()
28+
{
29+
$this->model = new ClassReader();
30+
}
31+
32+
/**
33+
* Get constructor test
34+
*
35+
* @param array $testData
36+
* @dataProvider getTestData
37+
* @throws \ReflectionException
38+
*/
39+
public function testGetConstructor(array $testData)
40+
{
41+
$this->assertEquals(
42+
$testData,
43+
$this->model->getConstructor('FirstClassForParentCall')
44+
);
45+
}
46+
47+
/**
48+
* Ensure that if we have cached class then returns this class
49+
*/
50+
public function testGetParents()
51+
{
52+
$model = new ClassReader();
53+
$this->assertEquals([0 => 'FirstClassForParentCall'], $model->getParents('ThirdClassForParentCall'));
54+
$reflection = new \ReflectionClass(ClassReader::class);
55+
$expectedClass = $reflection->getProperty('parentsCache');
56+
$expectedClass->setAccessible(true);
57+
$this->assertEquals(
58+
$expectedClass->getValue($model)['ThirdClassForParentCall'],
59+
$model->getParents('ThirdClassForParentCall')
60+
);
61+
}
62+
63+
/**
64+
* Data provider
65+
*
66+
* @return array
67+
*/
68+
public function getTestData()
69+
{
70+
return
71+
[
72+
[
73+
[
74+
0 => [
75+
0 => 'stdClassObject',
76+
1 => 'stdClass',
77+
2 => true,
78+
3 => null,
79+
],
80+
1 => [
81+
0 => 'runeTimeException',
82+
1 => 'ClassExtendsDefaultPhpType',
83+
2 => true,
84+
3 => null,
85+
],
86+
2 => [
87+
0 => 'arrayVariable',
88+
1 => null,
89+
2 => false,
90+
3 => [
91+
'key' => 'value',
92+
]
93+
]
94+
]
95+
]
96+
];
97+
}
98+
}

0 commit comments

Comments
 (0)