Skip to content

Commit

Permalink
Improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed May 19, 2024
1 parent c738561 commit 25f15ff
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ChannelFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public function log($level, $message, array $context = []): void
*/
public function write(string $level, $message, array $context = []): void
{
/** @phpstan-ignore argument.type */
$this->log($level, $message, $context);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/AssertionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,10 @@ public function testAssertCurrentContextWithNonBoolReturnedFromClosure(): void
{
$log = new LogFake();

/** @phpstan-ignore argument.type */
$log->assertCurrentContext(fn () => 1);
self::assertFailsWithMessage(
/** @phpstan-ignore argument.type */
fn () => $log->assertCurrentContext(fn () => 0),
'Unexpected context found in the [stack] channel. Found [{}].'
);
Expand All @@ -530,8 +532,10 @@ public function testAssertLoggedFuncWithNonBoolReturnedFromClosure(): void
$log = new LogFake();
$log->info('xxxx');

/** @phpstan-ignore argument.type */
$log->assertLogged(fn () => 1);
self::assertFailsWithMessage(
/** @phpstan-ignore argument.type */
fn () => $log->assertLogged(fn () => 0),
'Expected log was not created in the [stack] channel.'
);
Expand Down
40 changes: 40 additions & 0 deletions tests/LogFakeApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,46 +180,86 @@ public function testDummyMethods(): void
});
$log->setEventDispatcher(new class() implements Dispatcher
{
/**
* @param \Closure|string|array<string> $events
* @param \Closure|string|array<\Closure>|null $listener
* @return void
*/
public function listen($events, $listener = null)
{
//
}

/**
* @param string $eventName
* @return bool
*/
public function hasListeners($eventName)
{
return false;
}

/**
* @param object|string $subscriber
* @return void
*/
public function subscribe($subscriber)
{
//
}

/**
* @param string|object $event
* @param mixed $payload
* @return mixed
*/
public function until($event, $payload = [])
{
return null;
}

/**
* @inheritdoc
* @param mixed $payload
* @param bool $halt
* @return array<array-key, mixed>|null
*/
public function dispatch($event, $payload = [], $halt = false)
{
return null;
}

/**
* @param string $event
* @param array<array-key, mixed> $payload
* @return void
*/
public function push($event, $payload = [])
{
//
}

/**
* @param string $event
* @return void
*/
public function flush($event)
{
//
}

/**
* @param string $event
* @return void
*/
public function forget($event)
{
//
}

/**
* @return void
*/
public function forgetPushed()
{
//
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ protected function setUp(): void
$app = Container::setInstance(new Container());

$app->singleton('config', fn () => new Repository(['logging' => ['default' => 'stack']]));
/** @phpstan-ignore argument.type */
$app->singleton('log', fn () => new LogManager($app));

/** @phpstan-ignore argument.type */
Facade::setFacadeApplication($app);
Facade::clearResolvedInstances();
}
Expand Down

0 comments on commit 25f15ff

Please sign in to comment.