Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests + Remove scrutinizer #149

Merged
merged 5 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
/docs export-ignore
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ name: build
jobs:
phpunit:
uses: yiisoft/actions/.github/workflows/phpunit.yml@master
secrets:
codecovToken: ${{ secrets.CODECOV_TOKEN }}
with:
extensions: fileinfo, pdo, pdo_sqlite, sqlite3
os: >-
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
[![Latest Stable Version](https://poser.pugx.org/yiisoft/yii-debug-api/v)](https://packagist.org/packages/yiisoft/yii-debug-api)
[![Total Downloads](https://poser.pugx.org/yiisoft/yii-debug-api/downloads)](https://packagist.org/packages/yiisoft/yii-debug-api)
[![Build status](https://github.com/yiisoft/yii-debug-api/actions/workflows/build.yml/badge.svg)](https://github.com/yiisoft/yii-debug-api/actions/workflows/build.yml)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiisoft/yii-debug-api/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/yii-debug-api/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/yii-debug-api/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/yii-debug-api/?branch=master)
[![Code Coverage](https://codecov.io/gh/yiisoft/yii-debug-api/branch/master/graph/badge.svg)](https://codecov.io/gh/yiisoft/yii-debug-api)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fyii-debug-api%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/yii-debug-api/master)
[![static analysis](https://github.com/yiisoft/yii-debug-api/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/yii-debug-api/actions?query=workflow%3A%22static+analysis%22)

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"yiisoft/router-fastroute": "^3.0",
"yiisoft/test-support": "^3.0",
"yiisoft/yii-cycle": "dev-master",
"yiisoft/yii-http": "^1.0",
"yiisoft/yii-view": "^6.0"
},
"suggest": {
Expand Down
5 changes: 1 addition & 4 deletions src/Debug/Http/HttpApplicationWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ public function __construct(
) {
}

/**
* @psalm-suppress UndefinedClass
*/
public function wrap(Application $application): void
{
$middlewareDispatcher = $this->middlewareDispatcher;
$middlewareDefinitions = $this->middlewareDefinitions;

$closure = Closure::bind(
/**
* @psalm-suppress UndefinedClass
* @psalm-suppress InaccessibleProperty
*/
static fn (Application $application) => $application->dispatcher = $middlewareDispatcher->withMiddlewares([
...$middlewareDefinitions,
Expand Down
90 changes: 35 additions & 55 deletions tests/Unit/Debug/Repository/CollectorRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,95 +6,75 @@

use PHPUnit\Framework\TestCase;
use Yiisoft\Yii\Debug\Api\Debug\Repository\CollectorRepository;
use Yiisoft\Yii\Debug\Api\Tests\Support\StubCollector;
use Yiisoft\Yii\Debug\DebuggerIdGenerator;
use Yiisoft\Yii\Debug\Storage\MemoryStorage;
use Yiisoft\Yii\Debug\Storage\StorageInterface;

final class CollectorRepositoryTest extends TestCase
{
public function testSummary(): void
{
$idGenerator = new DebuggerIdGenerator();
$stubCollector = new StubCollector(['key' => 'value']);

$storage = $this->createStorage($idGenerator);
$storage = new MemoryStorage();
$repository = new CollectorRepository($storage);

$this->assertIsArray($repository->getSummary());
$this->assertEquals([
[
'id' => $idGenerator->getId(),
'collectors' => [],
],
], $repository->getSummary());
$this->assertSame([], $repository->getSummary());

$storage->addCollector($stubCollector);
$storage->write('testId', ['stub' => ['key' => 'value']], [], ['total' => 7]);

$this->assertIsArray($repository->getSummary());
$this->assertEquals([
$this->assertSame(
[
'id' => $idGenerator->getId(),
'collectors' => [$stubCollector->getName()],
['total' => 7],
],
], $repository->getSummary());
$repository->getSummary()
);
}

public function testDetail(): void
{
$idGenerator = new DebuggerIdGenerator();
$stubCollector = new StubCollector(['key' => 'value']);

$storage = $this->createStorage($idGenerator);
$storage->addCollector($stubCollector);
$storage = new MemoryStorage();
$storage->write('testId', ['stub' => ['key' => 'value']], [], ['total' => 7]);

$repository = new CollectorRepository($storage);

$this->assertIsArray($repository->getDetail($idGenerator->getId()));
$this->assertEquals([
$stubCollector->getName() => $stubCollector->getCollected(),
], $repository->getDetail($idGenerator->getId()));
$this->assertSame(
['stub' => ['key' => 'value']],
$repository->getDetail('testId')
);
}

public function testDumpObject(): void
{
$idGenerator = new DebuggerIdGenerator();
$stubCollector = new StubCollector(['key' => 'value']);

$storage = $this->createStorage($idGenerator);
$storage->addCollector($stubCollector);
$storage = new MemoryStorage();
$storage->write('testId', ['stub' => ['key' => 'value']], ['object' => []], ['total' => 7]);

$repository = new CollectorRepository($storage);

$this->assertIsArray($repository->getDumpObject($idGenerator->getId()));
$this->assertEquals([
'key' => 'value',
], $repository->getDumpObject($idGenerator->getId()));
$this->assertSame(
['object' => []],
$repository->getDumpObject('testId')
);
}

public function testObject(): void
{
$idGenerator = new DebuggerIdGenerator();
$storage = new MemoryStorage();

$objectId = '123';
$stubCollector = new StubCollector([
'stdClass#' . $objectId => 'value',
]);

$storage = $this->createStorage($idGenerator);
$storage->addCollector($stubCollector);
$storage->write(
'testId',
['stub' => ['key' => 'value']],
['stdClass#' . $objectId => 'value'],
['total' => 7],
);

$repository = new CollectorRepository($storage);

$this->assertIsArray($repository->getObject($idGenerator->getId(), $objectId));
$this->assertEquals([
'stdClass',
'value',
], $repository->getObject($idGenerator->getId(), $objectId));
}

private function createStorage(DebuggerIdGenerator $idGenerator): StorageInterface
{
return new MemoryStorage($idGenerator);
$object = $repository->getObject('testId', $objectId);
$this->assertIsArray($object);
$this->assertSame(
[
'stdClass',
'value',
],
$object
);
}
}
Loading