Skip to content

Commit

Permalink
Fix tests & psalm errors
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz committed Sep 4, 2023
1 parent f8bf302 commit 6d4db1b
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/Collector/ExceptionCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function collect(ApplicationError $error): void
}

$this->exception = $error->getThrowable();
$this->timelineCollector->collect($error::class, $this);
$this->timelineCollector->collect($this, $error::class);

Check warning on line 43 in src/Collector/ExceptionCollector.php

View check run for this annotation

Codecov / codecov/patch

src/Collector/ExceptionCollector.php#L43

Added line #L43 was not covered by tests
}

public function getSummary(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Collector/HttpClientCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function collect(RequestInterface $request, float|string $startTime, stri
'headers' => $request->getHeaders(),
'line' => $line,
];
$this->timelineCollector->collect($uniqueId, $this);
$this->timelineCollector->collect($this, $uniqueId);

Check warning on line 73 in src/Collector/HttpClientCollector.php

View check run for this annotation

Codecov / codecov/patch

src/Collector/HttpClientCollector.php#L73

Added line #L73 was not covered by tests
}

public function collectTotalTime(?ResponseInterface $response, float|string $startTime, ?string $uniqueId): void
Expand Down
2 changes: 1 addition & 1 deletion src/Collector/TimelineCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function collect(CollectorInterface $collector, string|int $reference, ..
return;
}

$this->events[] = [microtime(true), $reference, $collector::class, ...$data];
$this->events[] = [microtime(true), $reference, $collector::class, array_values($data)];

Check warning on line 27 in src/Collector/TimelineCollector.php

View check run for this annotation

Codecov / codecov/patch

src/Collector/TimelineCollector.php#L27

Added line #L27 was not covered by tests
}

private function reset(): void

Check warning on line 30 in src/Collector/TimelineCollector.php

View check run for this annotation

Codecov / codecov/patch

src/Collector/TimelineCollector.php#L30

Added line #L30 was not covered by tests
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Collector/CommandCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Yiisoft\Yii\Console\Output\ConsoleBufferedOutput;
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
use Yiisoft\Yii\Debug\Collector\Console\CommandCollector;
use Yiisoft\Yii\Debug\Collector\TimelineCollector;
use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase;

final class CommandCollectorTest extends AbstractCollectorTestCase
Expand Down Expand Up @@ -57,7 +58,7 @@ public function testCollectWithInactiveCollector(): void

protected function getCollector(): CollectorInterface
{
return new CommandCollector();
return new CommandCollector(new TimelineCollector());
}

protected function checkCollectedData(array $data): void
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Collector/ConsoleAppInfoCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use Yiisoft\Yii\Console\Event\ApplicationStartup;
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
use Yiisoft\Yii\Debug\Collector\Console\ConsoleAppInfoCollector;
use Yiisoft\Yii\Debug\Collector\TimelineCollector;
use Yiisoft\Yii\Debug\Collector\Web\WebAppInfoCollector;

use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase;

use function sleep;
Expand All @@ -31,7 +31,7 @@ protected function collectTestData(CollectorInterface $collector): void

protected function getCollector(): CollectorInterface
{
return new ConsoleAppInfoCollector();
return new ConsoleAppInfoCollector(new TimelineCollector());
}

protected function checkCollectedData(array $data): void
Expand Down
20 changes: 13 additions & 7 deletions tests/Unit/Collector/ContainerInterfaceProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
use Yiisoft\EventDispatcher\Provider\Provider;
use Yiisoft\Files\FileHelper;
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
use Yiisoft\Yii\Debug\Collector\EventCollector;
use Yiisoft\Yii\Debug\Collector\LogCollector;
use Yiisoft\Yii\Debug\Collector\ServiceCollector;
use Yiisoft\Yii\Debug\Collector\ContainerInterfaceProxy;
use Yiisoft\Yii\Debug\Collector\ContainerProxyConfig;
use Yiisoft\Yii\Debug\Collector\EventCollector;
use Yiisoft\Yii\Debug\Collector\EventDispatcherInterfaceProxy;
use Yiisoft\Yii\Debug\Collector\LogCollector;
use Yiisoft\Yii\Debug\Collector\LoggerInterfaceProxy;
use Yiisoft\Yii\Debug\Collector\ServiceCollector;
use Yiisoft\Yii\Debug\Collector\TimelineCollector;

class ContainerInterfaceProxyTest extends TestCase
{
Expand Down Expand Up @@ -72,7 +73,7 @@ public function testGetAndHasWithCallableServices(): void
],
],
$dispatcherMock,
new ServiceCollector(),
$this->createServiceCollector(),
$this->path,
1
);
Expand All @@ -89,7 +90,7 @@ public function testGetAndHasWithCallableServices(): void
public function testGetWithArrayConfigWithStringKeys(): void
{
$dispatcherMock = $this->getMockBuilder(EventDispatcherInterface::class)->getMock();
$serviceCollector = new ServiceCollector();
$serviceCollector = $this->createServiceCollector();
$serviceCollector->startup(); // activate collector

$config = new ContainerProxyConfig(
Expand Down Expand Up @@ -127,7 +128,7 @@ public function testGetWithoutConfig(): void
EventDispatcherInterface::class,
],
$dispatcherMock,
new ServiceCollector(),
$this->createServiceCollector(),
$this->path,
1
);
Expand Down Expand Up @@ -183,7 +184,7 @@ private function getConfig(): ContainerProxyConfig
],
],
$dispatcherMock,
new ServiceCollector(),
$this->createServiceCollector(),
$this->path,
1
);
Expand All @@ -201,4 +202,9 @@ private function getContainer(): Container
]);
return new Container($config);
}

protected function createServiceCollector(): ServiceCollector
{
return new ServiceCollector(new TimelineCollector());
}
}
18 changes: 12 additions & 6 deletions tests/Unit/Collector/ContainerProxyConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
use PHPUnit\Framework\TestCase;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
use Yiisoft\Yii\Debug\Collector\EventCollector;
use Yiisoft\Yii\Debug\Collector\LogCollector;
use Yiisoft\Yii\Debug\Collector\ServiceCollector;
use Yiisoft\Yii\Debug\Collector\ContainerProxyConfig;
use Yiisoft\Yii\Debug\Collector\EventCollector;
use Yiisoft\Yii\Debug\Collector\EventDispatcherInterfaceProxy;
use Yiisoft\Yii\Debug\Collector\LogCollector;
use Yiisoft\Yii\Debug\Collector\LoggerInterfaceProxy;
use Yiisoft\Yii\Debug\Collector\ServiceCollector;
use Yiisoft\Yii\Debug\Collector\TimelineCollector;

final class ContainerProxyConfigTest extends TestCase
{
Expand All @@ -23,13 +24,13 @@ public function testImmutability(): void
$dispatcherMock = $this->getMockBuilder(EventDispatcherInterface::class)->getMock();

$this->assertNotSame($config, $config->activate());
$this->assertNotSame($config, $config->withCollector(new ServiceCollector()));
$this->assertNotSame($config, $config->withCollector($this->createServiceCollector()));
$this->assertNotSame($config, $config->withLogLevel(1));
$this->assertNotSame($config, $config->withProxyCachePath('@tests/runtime'));
$this->assertNotSame(
$config,
$config->withDispatcher(
new EventDispatcherInterfaceProxy($dispatcherMock, new EventCollector())
new EventDispatcherInterfaceProxy($dispatcherMock, new EventCollector(new TimelineCollector()))
)
);
$this->assertNotSame(
Expand All @@ -51,7 +52,7 @@ public function testGetters(): void
LoggerInterface::class => [LoggerInterfaceProxy::class, LogCollector::class],
],
$dispatcherMock,
new ServiceCollector(),
$this->createServiceCollector(),
'@tests/runtime',
1
);
Expand Down Expand Up @@ -79,4 +80,9 @@ public function testGetters(): void
$this->assertFalse($config->hasDecoratedServiceArrayConfigWithStringKeys(LoggerInterface::class));
$this->assertFalse($config->hasDecoratedServiceCallableConfig(LoggerInterface::class));
}

protected function createServiceCollector(): ServiceCollector
{
return new ServiceCollector(new TimelineCollector());
}
}
3 changes: 2 additions & 1 deletion tests/Unit/Collector/EventCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Yiisoft\Yii\Debug\Collector\CollectorInterface;
use Yiisoft\Yii\Debug\Collector\EventCollector;
use Yiisoft\Yii\Debug\Collector\TimelineCollector;
use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase;
use Yiisoft\Yii\Debug\Tests\Unit\Support\DummyEvent;

Expand All @@ -21,7 +22,7 @@ protected function collectTestData(CollectorInterface $collector): void

protected function getCollector(): CollectorInterface
{
return new EventCollector();
return new EventCollector(new TimelineCollector());
}

protected function checkCollectedData(array $data): void
Expand Down
31 changes: 0 additions & 31 deletions tests/Unit/Collector/EventDispatcherProxyTest.php

This file was deleted.

3 changes: 2 additions & 1 deletion tests/Unit/Collector/LogCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Psr\Log\LogLevel;
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
use Yiisoft\Yii\Debug\Collector\LogCollector;
use Yiisoft\Yii\Debug\Collector\TimelineCollector;
use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase;

final class LogCollectorTest extends AbstractCollectorTestCase
Expand All @@ -21,6 +22,6 @@ protected function collectTestData(CollectorInterface $collector): void

protected function getCollector(): CollectorInterface
{
return new LogCollector();
return new LogCollector(new TimelineCollector());
}
}
3 changes: 2 additions & 1 deletion tests/Unit/Collector/MiddlewareCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Yiisoft\Middleware\Dispatcher\Event\BeforeMiddleware;
use Yiisoft\Middleware\Dispatcher\MiddlewareFactory;
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
use Yiisoft\Yii\Debug\Collector\TimelineCollector;
use Yiisoft\Yii\Debug\Collector\Web\MiddlewareCollector;
use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase;
use Yiisoft\Yii\Debug\Tests\Unit\Support\DummyMiddleware;
Expand All @@ -34,7 +35,7 @@ protected function collectTestData(CollectorInterface $collector): void

protected function getCollector(): CollectorInterface
{
return new MiddlewareCollector();
return new MiddlewareCollector(new TimelineCollector());
}

protected function checkCollectedData(array $data): void
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Collector/RequestCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
use Yiisoft\Yii\Debug\Collector\TimelineCollector;
use Yiisoft\Yii\Debug\Collector\Web\RequestCollector;
use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase;
use Yiisoft\Yii\Http\Event\AfterRequest;
Expand Down Expand Up @@ -59,7 +60,7 @@ protected function collectTestData(CollectorInterface $collector): void

protected function getCollector(): CollectorInterface
{
return new RequestCollector();
return new RequestCollector(new TimelineCollector());
}

protected function checkCollectedData(array $data): void
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Collector/ServiceCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use stdClass;
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
use Yiisoft\Yii\Debug\Collector\ServiceCollector;
use Yiisoft\Yii\Debug\Collector\TimelineCollector;
use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase;

final class ServiceCollectorTest extends AbstractCollectorTestCase
Expand All @@ -22,6 +23,6 @@ protected function collectTestData(CollectorInterface $collector): void

protected function getCollector(): CollectorInterface
{
return new ServiceCollector();
return new ServiceCollector(new TimelineCollector());
}
}
3 changes: 2 additions & 1 deletion tests/Unit/Collector/WebAppInfoCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
use Yiisoft\Yii\Debug\Collector\TimelineCollector;
use Yiisoft\Yii\Debug\Collector\Web\WebAppInfoCollector;
use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase;
use Yiisoft\Yii\Http\Event\AfterRequest;
Expand All @@ -33,7 +34,7 @@ protected function collectTestData(CollectorInterface $collector): void

protected function getCollector(): CollectorInterface
{
return new WebAppInfoCollector();
return new WebAppInfoCollector(new TimelineCollector());
}

protected function checkCollectedData(array $data): void
Expand Down

0 comments on commit 6d4db1b

Please sign in to comment.