-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBaseClassifierTest.php
More file actions
120 lines (104 loc) · 3.44 KB
/
BaseClassifierTest.php
File metadata and controls
120 lines (104 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
declare(strict_types=1);
namespace Yiisoft\Classifier\Tests;
use PHPUnit\Framework\TestCase;
use Yiisoft\Classifier\Classifier;
use Yiisoft\Classifier\PhpParserClassifier;
use Yiisoft\Classifier\Tests\Support\Attributes\AuthorAttribute;
use Yiisoft\Classifier\Tests\Support\Author;
use Yiisoft\Classifier\Tests\Support\AuthorPost;
use Yiisoft\Classifier\Tests\Support\Interfaces\PostInterface;
use Yiisoft\Classifier\Tests\Support\Interfaces\UserInterface;
use Yiisoft\Classifier\Tests\Support\Post;
use Yiisoft\Classifier\Tests\Support\PostUser;
use Yiisoft\Classifier\Tests\Support\User;
use Yiisoft\Classifier\Tests\Support\UserSubclass;
abstract class BaseClassifierTest extends TestCase
{
/**
* @dataProvider dataProviderInterfaces
*/
public function testInterfaces(string|array $interfaces, array $expectedClasses)
{
$finder = $this->createClassifier(__DIR__);
$finder = $finder->withInterface($interfaces);
$result = $finder->find();
$this->assertEquals($expectedClasses, iterator_to_array($result));
}
/**
* @dataProvider attributesDataProvider
*/
public function testAttributes(string|array $attributes, array $expectedClasses)
{
$finder = $this->createClassifier(__DIR__);
$finder = $finder->withAttribute($attributes);
$result = $finder->find();
$this->assertEquals($expectedClasses, iterator_to_array($result));
}
/**
* @dataProvider mixedDataProvider
*/
public function testMixed(array $attributes, array $interfaces, array $expectedClasses)
{
$finder = $this->createClassifier(__DIR__);
$finder = $finder
->withAttribute($attributes)
->withInterface($interfaces);
$result = $finder->find();
$this->assertEquals($expectedClasses, iterator_to_array($result));
}
public function dataProviderInterfaces(): array
{
return [
// [
// [],
// [],
// ],
// [
// PostInterface::class,
// [AuthorPost::class, Post::class, PostUser::class],
// ],
// [
// [PostInterface::class],
// [AuthorPost::class, Post::class, PostUser::class],
// ],
[
[UserInterface::class],
[PostUser::class, User::class, UserSubclass::class],
],
// [
// [PostInterface::class, UserInterface::class],
// [PostUser::class],
// ],
];
}
public function attributesDataProvider(): array
{
return [
[
[],
[],
],
[
AuthorAttribute::class,
[Author::class, AuthorPost::class],
],
];
}
public function mixedDataProvider(): array
{
return [
[
[],
[],
[],
],
[
[AuthorAttribute::class],
[PostInterface::class],
[AuthorPost::class],
],
];
}
abstract protected function createClassifier(string $directory): Classifier|PhpParserClassifier;
}