Skip to content

Commit

Permalink
fix phpstan & cs
Browse files Browse the repository at this point in the history
  • Loading branch information
ShockedPlot7560 committed Dec 24, 2023
1 parent 45f1426 commit b035fd9
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 189 deletions.
41 changes: 21 additions & 20 deletions src/TestProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ public function setup() : void {

$this->playerManager = new TestPlayerManager($this->pmmpUnit);
$this->playerBag = new PlayerBag();
try {
$this->runner->onLoad();
} catch (Throwable $e) {
TestResults::fatal($e);
$this->finish();
}
try {
$this->runner->onLoad();
} catch (Throwable $e) {
TestResults::fatal($e);
$this->finish();
}
}

public function prepare() : void {
try {
$this->runner->onEnable();
} catch (Throwable $e) {
TestResults::fatal($e);
$this->finish();
}
try {
$this->runner->onEnable();
} catch (Throwable $e) {
TestResults::fatal($e);
$this->finish();
}
}

public function start() : void {
Expand All @@ -81,14 +81,15 @@ public function start() : void {
}

public function stop() : void {
try {
$this->runner->onDisable();
} catch (Throwable $e) {
TestResults::fatal($e);

$this->finish(false);
return;
}
try {
$this->runner->onDisable();
} catch (Throwable $e) {
TestResults::fatal($e);

$this->finish(false);

return;
}
if (TestMemory::$currentTest !== null) {
global $lastExceptionError, $lastError;
$error = $lastExceptionError ?? $lastError;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

namespace ShockedPlot7560\PmmpUnit\framework\attribute\dataProvider;
namespace ShockedPlot7560\PmmpUnit\framework\attribute;

use Attribute;
use ReflectionClass;
use ReflectionMethod;
use ShockedPlot7560\PmmpUnit\framework\attribute\MethodAttributeToRunner;
use ShockedPlot7560\PmmpUnit\framework\runner\DataProviderRunner;
use ShockedPlot7560\PmmpUnit\framework\runner\TestRunnerInterface;

Expand Down
4 changes: 4 additions & 0 deletions src/framework/attribute/MethodAttributeToRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
use ReflectionClass;
use ReflectionMethod;
use ShockedPlot7560\PmmpUnit\framework\runner\TestRunnerInterface;
use ShockedPlot7560\PmmpUnit\framework\TestCase;

interface MethodAttributeToRunner {
/**
* @param ReflectionClass<TestCase> $class
*/
public function getRunner(ReflectionClass $class, ReflectionMethod $method) : TestRunnerInterface;
}
79 changes: 0 additions & 79 deletions src/framework/attribute/dataProvider/DataProviderTest.php

This file was deleted.

44 changes: 0 additions & 44 deletions src/framework/attribute/dataProvider/TestMethodFeeded.php

This file was deleted.

16 changes: 8 additions & 8 deletions src/framework/result/FailedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
namespace ShockedPlot7560\PmmpUnit\framework\result;

use ShockedPlot7560\PmmpUnit\framework\runner\TestRunnerInterface;
use Stringable;
use Throwable;

class FailedTest implements TestResult, ThrowableResult, \Stringable {
class FailedTest implements TestResult, ThrowableResult, Stringable {
public function __construct(
public readonly TestRunnerInterface $test,
public readonly Throwable $throwable
) {
}

public function getThrowable(): Throwable {
return $this->throwable;
}
public function getThrowable() : Throwable {
return $this->throwable;
}

public function __toString(): string
{
return $this->test->__toString();
}
public function __toString() : string {
return $this->test->__toString();
}
}
27 changes: 15 additions & 12 deletions src/framework/result/Fatal.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

namespace ShockedPlot7560\PmmpUnit\framework\result;

class Fatal implements TestResult, ThrowableResult, \Stringable {
public function __construct(
public readonly \Throwable $throwable
) { }
use Stringable;
use Throwable;

public function getThrowable(): \Throwable {
return $this->throwable;
}
class Fatal implements TestResult, ThrowableResult, Stringable {
public function __construct(
public readonly Throwable $throwable
) {
}

public function __toString(): string
{
return "Runtime exception";
}
}
public function getThrowable() : Throwable {
return $this->throwable;
}

public function __toString() : string {
return "Runtime exception";
}
}
9 changes: 4 additions & 5 deletions src/framework/result/FatalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ public function __construct(
public readonly TestRunnerInterface $test,
Throwable $throwable
) {
parent::__construct($throwable);
parent::__construct($throwable);
}

public function __toString(): string
{
return $this->test->__toString();
}
public function __toString() : string {
return $this->test->__toString();
}
}
6 changes: 3 additions & 3 deletions src/framework/result/TestResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public static function fatalTest(TestRunnerInterface $test, Throwable $throwable
self::$testResults[] = new FatalTest($test, $throwable);
}

public static function fatal(Throwable $throwable) : void {
self::$testResults[] = new Fatal($throwable);
}
public static function fatal(Throwable $throwable) : void {
self::$testResults[] = new Fatal($throwable);
}

/**
* @return TestResult[]
Expand Down
6 changes: 4 additions & 2 deletions src/framework/result/ThrowableResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace ShockedPlot7560\PmmpUnit\framework\result;

use Throwable;

interface ThrowableResult {
public function getThrowable();
}
public function getThrowable() : Throwable;
}
5 changes: 2 additions & 3 deletions src/framework/result/printer/TestResultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
namespace ShockedPlot7560\PmmpUnit\framework\result\printer;

use Logger;
use ShockedPlot7560\PmmpUnit\framework\result\FailedTest;
use ShockedPlot7560\PmmpUnit\framework\result\FatalTest;
use ShockedPlot7560\PmmpUnit\framework\result\ThrowableResult;
use Stringable;

class TestResultPrinter {
public function __construct(
Expand Down Expand Up @@ -60,7 +59,7 @@ private function printStats(Logger $logger) : void {
);
}

private function errorToString(ThrowableResult&\Stringable $error) : string {
private function errorToString(ThrowableResult&Stringable $error) : string {
$ret = $error->__toString() . ": ";
$ret .= str_replace("§", "&", $error->getThrowable()->getMessage());
$ret .= " (line: " . $error->getThrowable()->getLine() . ")";
Expand Down
5 changes: 2 additions & 3 deletions src/framework/result/printer/TestResultsBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

use ShockedPlot7560\PmmpUnit\framework\result\FailedTest;
use ShockedPlot7560\PmmpUnit\framework\result\Fatal;
use ShockedPlot7560\PmmpUnit\framework\result\FatalTest;
use ShockedPlot7560\PmmpUnit\framework\result\SuccessTest;
use ShockedPlot7560\PmmpUnit\framework\result\TestResult;

class TestResultsBag {
/** @var FatalTest[] $fatalErrors */
/** @var Fatal[] $fatalErrors */
private array $fatalErrors = [];

/** @var FailedTest[] $failedTests */
Expand Down Expand Up @@ -57,7 +56,7 @@ public function getPassedTests() : array {
}

/**
* @return FatalTest[]
* @return Fatal[]
*/
public function getFatalErrors() : array {
return $this->fatalErrors;
Expand Down
2 changes: 1 addition & 1 deletion src/framework/runner/DataProviderRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use React\Promise\PromiseInterface;
use ReflectionClass;
use ReflectionMethod;
use ShockedPlot7560\PmmpUnit\framework\attribute\dataProvider\DataProviderAttribute;
use ShockedPlot7560\PmmpUnit\framework\attribute\DataProviderAttribute;
use ShockedPlot7560\PmmpUnit\framework\TestCase;
use Webmozart\Assert\Assert;

Expand Down
8 changes: 7 additions & 1 deletion src/framework/runner/EndChildRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
abstract class EndChildRunner implements TestRunnerInterface {
private ?TestCase $instance = null;

/**
* @param ReflectionClass<TestCase> $class
*/
public function __construct(
protected ReflectionClass $class,
protected ReflectionMethod $method
Expand Down Expand Up @@ -128,6 +131,9 @@ protected function getInstance(bool $regenerate = true) : TestCase {
}

private function createInstance() : TestCase {
return $this->class->newInstance(new ExpectedExceptionHandler($this->method));
/** @var TestCase $instance */
$instance = $this->class->newInstance(new ExpectedExceptionHandler($this->method));

return $instance;
}
}
Loading

0 comments on commit b035fd9

Please sign in to comment.