Skip to content

Commit

Permalink
fix class doesnt extend TestCase throwing exception
Browse files Browse the repository at this point in the history
  • Loading branch information
ShockedPlot7560 committed Sep 23, 2023
1 parent d8cd9a3 commit f0ec595
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/framework/TestSuite.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ShockedPlot7560\PmmpUnit\framework\attribute\dataProvider\DataProviderAttribute;
use ShockedPlot7560\PmmpUnit\framework\attribute\dataProvider\DataProviderTest;
use ShockedPlot7560\PmmpUnit\framework\attribute\TestAttribute;
use ShockedPlot7560\PmmpUnit\framework\loader\exception\LoaderException;
use ShockedPlot7560\PmmpUnit\framework\loader\TestSuiteChecker;
use ShockedPlot7560\PmmpUnit\framework\loader\TestSuiteLoader;
use ShockedPlot7560\PmmpUnit\utils\Utils;
Expand Down Expand Up @@ -111,7 +112,11 @@ public function addTestFile(string $filename) : void {
* @param ReflectionClass<TestCase> $class
*/
public function addTestSuite(ReflectionClass $class) : void {
TestSuiteChecker::check($class);
try {
TestSuiteChecker::check($class);
} catch (LoaderException $e) {
return;
}

$this->addTest(self::fromClassReflection($class));
}
Expand Down
3 changes: 1 addition & 2 deletions src/framework/loader/exception/ClassAbstractException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
namespace ShockedPlot7560\PmmpUnit\framework\loader\exception;

use ReflectionClass;
use RuntimeException;

class ClassAbstractException extends RuntimeException {
class ClassAbstractException extends LoaderException {
public function __construct(string|ReflectionClass $className, ?string $file = null) {
if ($className instanceof ReflectionClass) {
$file = $className->getFileName();
Expand Down
4 changes: 1 addition & 3 deletions src/framework/loader/exception/ClassDoesntExistException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace ShockedPlot7560\PmmpUnit\framework\loader\exception;

use RuntimeException;

class ClassDoesntExistException extends RuntimeException {
class ClassDoesntExistException extends LoaderException {
public function __construct(string $className, string $fileName) {
parent::__construct(sprintf(
'Class "%s" does not exist in "%s".',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
namespace ShockedPlot7560\PmmpUnit\framework\loader\exception;

use ReflectionClass;
use RuntimeException;
use ShockedPlot7560\PmmpUnit\framework\TestCase;

class ClassDoesntExtendTestCaseException extends RuntimeException {
class ClassDoesntExtendTestCaseException extends LoaderException {
public function __construct(string|ReflectionClass $className, ?string $fileName = null) {
if ($className instanceof ReflectionClass) {
$fileName = $className->getFileName();
Expand Down
8 changes: 8 additions & 0 deletions src/framework/loader/exception/LoaderException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace ShockedPlot7560\PmmpUnit\framework\loader\exception;

use RuntimeException;

class LoaderException extends RuntimeException {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace ShockedPlot7560\PmmpUnit\tests\normal;

/**
* Will be ignored because it doesn't extend TestCase
*/
class ClassDontExtendTestCase {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use ShockedPlot7560\PmmpUnit\framework\TestCase;

class ClassIsLoadTest extends TestCase {
/**
* @phpstan-return PromiseInterface<null>
*/
public function testChatGamesMainClassIsLoad() : PromiseInterface {
$this->assertTrue(class_exists(Main::class));

Expand Down

0 comments on commit f0ec595

Please sign in to comment.