File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+
4+ use Corpus \Http \Exceptions \AbstractHttpException ;
5+ use Corpus \Http \Status ;
6+ use PHPUnit \Framework \TestCase ;
7+
8+ class ExceptionNamingTest extends TestCase {
9+
10+ public function testNaming () : void {
11+ $ dir = new \RecursiveDirectoryIterator (__DIR__ . '/../src/Exceptions ' );
12+ $ ite = new \RecursiveIteratorIterator ($ dir );
13+ $ files = new \RegexIterator ($ ite , "/Exception \\.php$/ " );
14+ foreach ( $ files as $ file ) {
15+ require_once $ file ;
16+ }
17+
18+ $ classes = array_filter (get_declared_classes (), function ($ class ) {
19+ return is_subclass_of ($ class , AbstractHttpException::class);
20+ });
21+
22+ foreach ($ classes as $ className ) {
23+ $ reflect = new \ReflectionClass ($ className );
24+ if ($ reflect ->isAbstract ()) {
25+ continue ;
26+ }
27+
28+ $ inst = $ this ->getMockBuilder ($ className )
29+ ->onlyMethods ([])
30+ ->disableOriginalConstructor ()
31+ ->getMock ();
32+
33+ assert ($ inst instanceof AbstractHttpException);
34+
35+ $ shortName = $ reflect ->getShortName ();
36+ $ constName = preg_replace ('/Exception$/ ' , '' , $ shortName );
37+
38+ $ this ->assertSame (
39+ constant (Status::class . ':: ' . $ constName ),
40+ $ inst ->getHttpStatusCode ()
41+ );
42+ }
43+ }
44+
45+ }
You can’t perform that action at this time.
0 commit comments