File tree Expand file tree Collapse file tree 2 files changed +28
-18
lines changed
Expand file tree Collapse file tree 2 files changed +28
-18
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types = 1 );
4+
5+ namespace Ock \ClassFilesIterator \Tests ;
6+
7+ trait ExceptionTestTrait {
8+
9+ /**
10+ * @param class-string $exception_class
11+ * @param callable(): (void|mixed) $callback
12+ */
13+ protected function callAndAssertException (string $ exception_class , callable $ callback ): void {
14+ // Does not work with non-existing class.
15+ try {
16+ $ callback ();
17+ $ this ->fail ("Expected exception was not thrown. " );
18+ }
19+ catch (\Throwable $ e ) {
20+ if (get_class ($ e ) !== $ exception_class ) {
21+ throw $ e ;
22+ }
23+ $ this ->addToAssertionCount (1 );
24+ }
25+ }
26+
27+ }
Original file line number Diff line number Diff line change 1010
1111class NamespaceDirectoryTest extends TestCase {
1212
13+ use ExceptionTestTrait;
1314 use ImmutableObjectsTrait;
1415
1516 public function testCreate (): void {
@@ -488,24 +489,6 @@ protected function assertNamespaceDir(
488489 $ this ->assertSame ($ namespace , $ namespace_directory ->getNamespace ());
489490 }
490491
491- /**
492- * @param class-string $exception_class
493- * @param callable(): (void|mixed) $callback
494- */
495- protected function callAndAssertException (string $ exception_class , callable $ callback ): void {
496- // Does not work with non-existing class.
497- try {
498- $ callback ();
499- $ this ->fail ("Expected exception was not thrown. " );
500- }
501- catch (\Throwable $ e ) {
502- if (get_class ($ e ) !== $ exception_class ) {
503- throw $ e ;
504- }
505- $ this ->addToAssertionCount (1 );
506- }
507- }
508-
509492 /**
510493 * @param string $directory
511494 * @param string $namespace
You can’t perform that action at this time.
0 commit comments