Skip to content

Commit

Permalink
Cover more
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz committed Mar 3, 2024
1 parent 3db8e6f commit 803071a
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/Inspector/ApplicationState.php
Expand Up @@ -4,7 +4,10 @@

namespace Yiisoft\Yii\Debug\Api\Inspector;

class ApplicationState
/**
* @internal
*/
final class ApplicationState
{
public static $params;
public static array $params = [];
}
2 changes: 2 additions & 0 deletions tests/Support/Application/fail.sh
@@ -0,0 +1,2 @@
echo 'failed'
exit $1
19 changes: 19 additions & 0 deletions tests/Unit/Inspector/ApplicationStateTest.php
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Debug\Api\Tests\Unit\Inspector;

use PHPUnit\Framework\TestCase;
use Yiisoft\Yii\Debug\Api\Inspector\ApplicationState;

final class ApplicationStateTest extends TestCase
{
public function testStatus(): void
{
$this->assertEquals([], ApplicationState::$params);

ApplicationState::$params = ['key' => 'value'];
$this->assertEquals(['key' => 'value'], ApplicationState::$params);
}
}
41 changes: 41 additions & 0 deletions tests/Unit/Inspector/Command/BashCommandTest.php
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Debug\Api\Tests\Unit\Inspector\Command;

use PHPUnit\Framework\TestCase;
use Yiisoft\Aliases\Aliases;
use Yiisoft\Yii\Debug\Api\Inspector\Command\BashCommand;
use Yiisoft\Yii\Debug\Api\Inspector\CommandResponse;

final class BashCommandTest extends TestCase
{
public function testSuccess(): void
{
$aliases = new Aliases([
'@root' => __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());
}
}
20 changes: 20 additions & 0 deletions tests/Unit/Inspector/CommandResponseTest.php
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Debug\Api\Tests\Unit\Inspector;

use PHPUnit\Framework\TestCase;
use Yiisoft\Yii\Debug\Api\Inspector\CommandResponse;

final class CommandResponseTest extends TestCase
{
public function testStatus(): void
{
$response = new CommandResponse(CommandResponse::STATUS_OK, 'result', ['errors']);

$this->assertSame(CommandResponse::STATUS_OK, $response->getStatus());
$this->assertSame('result', $response->getResult());
$this->assertSame(['errors'], $response->getErrors());
}
}
Expand Up @@ -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;
Expand Down

0 comments on commit 803071a

Please sign in to comment.