diff --git a/src/Inspector/ApplicationState.php b/src/Inspector/ApplicationState.php index 9996b20..1b73fd2 100644 --- a/src/Inspector/ApplicationState.php +++ b/src/Inspector/ApplicationState.php @@ -4,7 +4,10 @@ namespace Yiisoft\Yii\Debug\Api\Inspector; -class ApplicationState +/** + * @internal + */ +final class ApplicationState { - public static $params; + public static array $params = []; } diff --git a/tests/Support/Application/fail.sh b/tests/Support/Application/fail.sh new file mode 100644 index 0000000..4bbf6fa --- /dev/null +++ b/tests/Support/Application/fail.sh @@ -0,0 +1,2 @@ +echo 'failed' +exit $1 diff --git a/tests/Unit/Inspector/ApplicationStateTest.php b/tests/Unit/Inspector/ApplicationStateTest.php new file mode 100644 index 0000000..2b8aed5 --- /dev/null +++ b/tests/Unit/Inspector/ApplicationStateTest.php @@ -0,0 +1,19 @@ +assertEquals([], ApplicationState::$params); + + ApplicationState::$params = ['key' => 'value']; + $this->assertEquals(['key' => 'value'], ApplicationState::$params); + } +} diff --git a/tests/Unit/Inspector/Command/BashCommandTest.php b/tests/Unit/Inspector/Command/BashCommandTest.php new file mode 100644 index 0000000..013da82 --- /dev/null +++ b/tests/Unit/Inspector/Command/BashCommandTest.php @@ -0,0 +1,41 @@ + __DIR__, + ]); + $command = new BashCommand($aliases, ['echo', 'test']); + + $response = $command->run(); + + $this->assertSame(CommandResponse::STATUS_OK, $response->getStatus()); + $this->assertSame('test' . PHP_EOL, $response->getResult()); + $this->assertSame([], $response->getErrors()); + } + + public function testError(): void + { + $aliases = new Aliases([ + '@root' => dirname(__DIR__, 3) . '/Support/Application', + ]); + $command = new BashCommand($aliases, ['bash', 'fail.sh', '1']); + + $response = $command->run(); + + $this->assertSame(CommandResponse::STATUS_ERROR, $response->getStatus()); + $this->assertSame('failed' . PHP_EOL, $response->getResult()); + $this->assertSame([], $response->getErrors()); + } +} diff --git a/tests/Unit/Inspector/CommandResponseTest.php b/tests/Unit/Inspector/CommandResponseTest.php new file mode 100644 index 0000000..68b6428 --- /dev/null +++ b/tests/Unit/Inspector/CommandResponseTest.php @@ -0,0 +1,20 @@ +assertSame(CommandResponse::STATUS_OK, $response->getStatus()); + $this->assertSame('result', $response->getResult()); + $this->assertSame(['errors'], $response->getErrors()); + } +} diff --git a/tests/Inspector/Database/DbSchemaProviderTest.php b/tests/Unit/Inspector/Database/DbSchemaProviderTest.php similarity index 98% rename from tests/Inspector/Database/DbSchemaProviderTest.php rename to tests/Unit/Inspector/Database/DbSchemaProviderTest.php index 0584e09..5a00506 100644 --- a/tests/Inspector/Database/DbSchemaProviderTest.php +++ b/tests/Unit/Inspector/Database/DbSchemaProviderTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Yiisoft\Yii\Debug\Api\Tests\Inspector\Database; +namespace Yiisoft\Yii\Debug\Api\Tests\Unit\Inspector\Database; use PHPUnit\Framework\TestCase; use Yiisoft\Cache\NullCache;