Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guanguans committed Jun 2, 2023
1 parent 2a39e1a commit 3ebf64c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@
],
],
'phpdoc_to_comment' => [
'ignored_tags' => [],
'ignored_tags' => [
'noinspection',
],
],

// return_notation
Expand Down
18 changes: 17 additions & 1 deletion tests/BootstrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,24 @@
expect($this->bootstrapper->getScores())->toBeCollection();
});

it('can sanitize `explain` for `sanitizeExplain`', function (): void {
$explain = [
[
'Item' => 'EXP.000',
'Severity' => 'L0',
'Summary' => 'Explain信息',
'Content' => '| id | select\\_type | table | partitions | type | possible_keys | key | key\\_len | ref | rows | filtered | scalability | Extra | |---|---|---|---|---|---|---|---|---|---|---|---|---| | 1 | SIMPLE | *NULL* | NULL | NULL | NULL | NULL | NULL | NULL | 0 | 0.00% | NULL | no matching row in const table | ',
'Case' => '### Explain信息解读 #### SelectType信息解读 * **SIMPLE**: 简单SELECT(不使用UNION或子查询等). #### Extra信息解读 * **no matching row in const table**: 对于连接查询, 列未满足唯一索引的条件或表为空. ',
'Position' => 0,
],
];
$sanitizeExplain = fn (array $explain): array => $this->sanitizeExplain($explain);

expect($sanitizeExplain->call($this->bootstrapper, $explain))->toBeArray();
});

it('can to `human time` for `toHumanTime`', function (): void {
$toHumanTime = fn (float $milliseconds) => $this->toHumanTime($milliseconds);
$toHumanTime = fn (float $milliseconds): string => $this->toHumanTime($milliseconds);

expect([
$toHumanTime->call($this->bootstrapper, 0.1),
Expand Down
44 changes: 29 additions & 15 deletions tests/JavascriptRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,35 @@
namespace Tests;

use Guanguans\LaravelSoar\JavascriptRenderer;
use Pest\Expectation;

it('can dump `AssetsToString` for `dumpAssetsToString`', function (): void {
expect(['css', 'js'])
->each(
fn (Expectation $item) => expect((fn () => $this->dumpAssetsToString($item->value))->call($this->app->make(JavascriptRenderer::class)))
->toBeString()
);

beforeEach(function (): void {
$this->javascriptRenderer = $this->app->make(JavascriptRenderer::class);
});

it('can dump assets to string for `dumpAssetsToString`', function (): void {
$dumpAssetsToString = fn (string $type): string => $this->dumpAssetsToString($type);

expect([
$dumpAssetsToString->call($this->javascriptRenderer, 'css'),
$dumpAssetsToString->call($this->javascriptRenderer, 'js'),
])->each->toBeString();
})->group(__DIR__, __FILE__);

it('can make `UriRelativeTo` for `makeUriRelativeTo`', function (): void {
expect(['css', 'js'])
->each(
fn (Expectation $item) => expect(
(fn () => $this->dumpAssetsToString($item->value))->call($this->app->make(JavascriptRenderer::class))
)->toBeString()
);
it('can get inline html for `getInlineHtml`', function (): void {
expect($this->javascriptRenderer)
->addInlineAssets(
'<style></style>',
'<script></script>',
'<meta charset="utf-8">',
)
->renderHead()->toBeString();
})->group(__DIR__, __FILE__);

it('can make uri relative to for `makeUriRelativeTo`', function (): void {
$makeUriRelativeTo = fn ($uri, $root): string => $this->makeUriRelativeTo($uri, $root);

expect([
$makeUriRelativeTo->call($this->javascriptRenderer, '/', ''),
$makeUriRelativeTo->call($this->javascriptRenderer, '/', '/'),
])->each->toBeString();
})->group(__DIR__, __FILE__);
4 changes: 3 additions & 1 deletion tests/OutputManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

namespace Tests;

use Guanguans\LaravelSoar\Exceptions\InvalidArgumentException;
use Guanguans\LaravelSoar\OutputManager;

it('can throw `InvalidArgumentException` for `offsetSet`', function (): void {
/** @noinspection PhpParamsInspection */
new OutputManager([new \stdClass()]);
})->group(__DIR__, __FILE__)->throws(\Guanguans\LaravelSoar\Exceptions\InvalidArgumentException::class);
})->group(__DIR__, __FILE__)->throws(InvalidArgumentException::class);

0 comments on commit 3ebf64c

Please sign in to comment.