5
5
use PHPUnit \Framework \TestCase ;
6
6
use ShipMonk \ComposerDependencyAnalyser \Config \Configuration ;
7
7
use ShipMonk \ComposerDependencyAnalyser \Config \ErrorType ;
8
+ use ShipMonk \ComposerDependencyAnalyser \Config \Ignore \UnusedClassIgnore ;
8
9
use ShipMonk \ComposerDependencyAnalyser \Config \Ignore \UnusedErrorIgnore ;
9
10
use ShipMonk \ComposerDependencyAnalyser \Exception \InvalidConfigException ;
10
11
use ShipMonk \ComposerDependencyAnalyser \Exception \InvalidPathException ;
@@ -17,13 +18,18 @@ class ConfigurationTest extends TestCase
17
18
public function testShouldIgnore (): void
18
19
{
19
20
$ configuration = new Configuration ();
20
- $ configuration ->ignoreErrors ([ErrorType::UNUSED_DEPENDENCY ]);
21
+ $ configuration ->ignoreUnknownClasses (['Unknown\Clazz ' ]);
22
+ $ configuration ->ignoreErrors ([ErrorType::UNUSED_DEPENDENCY , ErrorType::UNKNOWN_CLASS ]);
21
23
$ configuration ->ignoreErrorsOnPath (__DIR__ . '/app/../ ' , [ErrorType::SHADOW_DEPENDENCY ]);
22
24
$ configuration ->ignoreErrorsOnPackage ('my/package ' , [ErrorType::PROD_DEPENDENCY_ONLY_IN_DEV ]);
23
25
$ configuration ->ignoreErrorsOnPackageAndPath ('vendor/package ' , __DIR__ . '/../tests/app ' , [ErrorType::DEV_DEPENDENCY_IN_PROD ]);
24
26
25
27
$ ignoreList = $ configuration ->getIgnoreList ();
26
28
29
+ self ::assertTrue ($ ignoreList ->shouldIgnoreUnknownClass ('Unknown\Clazz ' , __DIR__ ));
30
+ self ::assertTrue ($ ignoreList ->shouldIgnoreUnknownClass ('Unknown\Clazz ' , __DIR__ . '/app ' ));
31
+ self ::assertTrue ($ ignoreList ->shouldIgnoreUnknownClass ('Any\Clazz ' , __DIR__ ));
32
+
27
33
self ::assertTrue ($ ignoreList ->shouldIgnoreError (ErrorType::UNUSED_DEPENDENCY , null , null ));
28
34
self ::assertTrue ($ ignoreList ->shouldIgnoreError (ErrorType::UNUSED_DEPENDENCY , null , 'some/package ' ));
29
35
self ::assertTrue ($ ignoreList ->shouldIgnoreError (ErrorType::UNUSED_DEPENDENCY , __DIR__ , null ));
@@ -87,6 +93,46 @@ public function testOverlappingUnusedIgnores(): void
87
93
], $ ignoreList3 ->getUnusedIgnores ());
88
94
}
89
95
96
+ public function testOverlappingUnusedIgnoresOfUnknownClass (): void
97
+ {
98
+ $ configuration = new Configuration ();
99
+ $ configuration ->ignoreErrors ([ErrorType::UNKNOWN_CLASS ]);
100
+ $ configuration ->ignoreErrorsOnPath (__DIR__ , [ErrorType::UNKNOWN_CLASS ]);
101
+ $ configuration ->ignoreUnknownClasses (['Unknown\Clazz ' ]);
102
+ $ configuration ->ignoreUnknownClassesRegex ('~^Unknown~ ' );
103
+
104
+ $ ignoreList1 = $ configuration ->getIgnoreList ();
105
+ $ ignoreList2 = $ configuration ->getIgnoreList ();
106
+ $ ignoreList3 = $ configuration ->getIgnoreList ();
107
+
108
+ $ parentDir = realpath (__DIR__ . '/.. ' );
109
+ self ::assertNotFalse ($ parentDir );
110
+
111
+ foreach ([$ ignoreList1 , $ ignoreList2 , $ ignoreList3 ] as $ ignoreList ) {
112
+ self ::assertEquals ([
113
+ new UnusedErrorIgnore (ErrorType::UNKNOWN_CLASS , null , null ),
114
+ new UnusedErrorIgnore (ErrorType::UNKNOWN_CLASS , __DIR__ , null ),
115
+ new UnusedClassIgnore ('Unknown\Clazz ' , false ),
116
+ new UnusedClassIgnore ('~^Unknown~ ' , true ),
117
+ ], $ ignoreList ->getUnusedIgnores ());
118
+ }
119
+
120
+ self ::assertTrue ($ ignoreList1 ->shouldIgnoreUnknownClass ('Unknown\Clazz ' , __DIR__ ));
121
+ self ::assertEquals ([], $ ignoreList1 ->getUnusedIgnores ());
122
+
123
+ self ::assertTrue ($ ignoreList2 ->shouldIgnoreUnknownClass ('Unknown\Clazz ' , $ parentDir ));
124
+ self ::assertEquals ([
125
+ new UnusedErrorIgnore (ErrorType::UNKNOWN_CLASS , __DIR__ , null ),
126
+ ], $ ignoreList2 ->getUnusedIgnores ());
127
+
128
+ self ::assertTrue ($ ignoreList3 ->shouldIgnoreUnknownClass ('Another\Clazz ' , $ parentDir ));
129
+ self ::assertEquals ([
130
+ new UnusedErrorIgnore (ErrorType::UNKNOWN_CLASS , __DIR__ , null ),
131
+ new UnusedClassIgnore ('Unknown\Clazz ' , false ),
132
+ new UnusedClassIgnore ('~^Unknown~ ' , true ),
133
+ ], $ ignoreList3 ->getUnusedIgnores ());
134
+ }
135
+
90
136
/**
91
137
* @param callable(Configuration): void $configure
92
138
* @dataProvider provideInvalidConfigs
0 commit comments