Skip to content

Commit

Permalink
Update repo
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed May 18, 2024
1 parent df2b5c3 commit 1130984
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 89 deletions.
92 changes: 30 additions & 62 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,91 +38,59 @@ jobs:
- name: Check platform requirements
run: composer check-platform-reqs

- name: Pint
run: pint --test

- name: Check for unused dependencies
run: ./vendor/bin/composer-unused


- name: Check for soft dependencies
run: ./vendor/bin/composer-require-checker


- name: PHP-CS-Fixer
run: ./vendor/bin/php-cs-fixer fix --dry-run


- name: test coverage
run: |
./vendor/bin/phpunit --coverage-clover=coverage.xml
bash <(curl -s https://codecov.io/bash)
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}


# - name: Infection
# run: ./vendor/bin/infection --min-msi=100
# env:
# INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }}

- name: Infection
run: infection --show-mutations

- name: PHPStan
run: ./vendor/bin/phpstan
run: phpstan

tests:
runs-on: ubuntu-latest


name: "PHP: ${{ matrix.php }}; Prefer: ${{ matrix.prefer }}; PHPUnit: {{ matrix.phpunit }};"

name: 'PHP ${{ matrix.php }} Illuminate ${{ matrix.illuminate }} PHPUnit ${{ matrix.phpunit }}'
strategy:
matrix:
php: ['8.1', '8.2', '8.3']
phpunit: [^9.0, ^10.0, ^11.0]
laravel: [^9.0, ^10.0, ^11.0]
prefer: [prefer-lowest, prefer-stable]
exclude:
- laravel: ^11.0
php: '8.1'
- phpunit: ^11.0
php: '8.1'


illuminate: ['10', '11']
phpunit: ['10', '11']
steps:
- name: checkout code
uses: actions/checkout@v3

- name: Checkout code
uses: actions/checkout@v4

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT


- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.prefer }}-php-${{ matrix.php }}-phpunit-${{ matrix.phpunit }}-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-${{ matrix.prefer }}-php-${{ matrix.php }}-phpunit-${{ matrix.phpunit }}-

key: ${{ runner.os }}-php-${{ matrix.php }}-illuminate-${{ matrix.illuminate }}-phpunit-${{ matrix.phpunit }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-illuminate-${{ matrix.illuminate }}-phpunit-${{ matrix.phpunit }}-composer-

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none


- name: Require dependency version
run: composer require --no-update illuminate/collections:${{ matrix.laravel }} illuminate/contracts:${{ matrix.laravel }} illuminate/log:${{ matrix.laravel }} illuminate/support:${{ matrix.laravel }} illuminate/config:${{ matrix.laravel }} illuminate/container:${{ matrix.laravel }} phpunit/phpunit:${{ matrix.phpunit }}


- name: Install dependencies
run: composer update --${{ matrix.prefer }} --no-scripts


- name: Check platform requirements
run: composer check-platform-reqs


- name: Run tests
run: ./vendor/bin/phpunit
run: |
composer require --no-update \
illuminate/collections:^${{ matrix.illuminate }} \
illuminate/contracts:^${{ matrix.illuminate }} \
illuminate/log:^${{ matrix.illuminate }} \
illuminate/support:^${{ matrix.illuminate }} \
phpunit/phpunit:^${{ matrix.phpunit }}
composer require --no-update --dev \
illuminate/config:^${{ matrix.illuminate }} \
illuminate/container:^${{ matrix.illuminate }}
composer update
- name: Configure PHPUnit
run: "if [ -f './phpunit.${{ matrix.phpunit }}.xml' ]; then cp ./phpunit.${{ matrix.phpunit }}.xml ./phpunit.xml; fi"

- name: PHPUnit
run: ./vendor/bin/phpunit --do-not-cache-result
34 changes: 21 additions & 13 deletions src/ChannelFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function __construct(private string $name)

/**
* @link https://github.com/timacdonald/log-fake#dump Documentation
* @param (Closure(LogEntry): bool) $callback
*
* @param (Closure(LogEntry): bool) $callback
*/
public function dump(?Closure $callback = null): ChannelFake
{
Expand All @@ -53,9 +54,10 @@ public function dump(?Closure $callback = null): ChannelFake

/**
* @link https://github.com/timacdonald/log-fake#dd Documentation
* @codeCoverageIgnore
*
* @infection-ignore-all
* @param (Closure(LogEntry): bool) $callback
*
* @param (Closure(LogEntry): bool) $callback
*/
public function dd(?Closure $callback = null): never
{
Expand All @@ -66,7 +68,8 @@ public function dd(?Closure $callback = null): never

/**
* @link https://github.com/timacdonald/log-fake#assertlogged Documentation
* @param (Closure(LogEntry): bool) $callback
*
* @param (Closure(LogEntry): bool) $callback
*/
public function assertLogged(Closure $callback, ?string $message = null): ChannelFake
{
Expand All @@ -80,7 +83,8 @@ public function assertLogged(Closure $callback, ?string $message = null): Channe

/**
* @link https://github.com/timacdonald/log-fake#assertloggedtimes Documentation
* @param (Closure(LogEntry): bool) $callback
*
* @param (Closure(LogEntry): bool) $callback
*/
public function assertLoggedTimes(Closure $callback, int $times, ?string $message = null): ChannelFake
{
Expand All @@ -94,7 +98,8 @@ public function assertLoggedTimes(Closure $callback, int $times, ?string $messag

/**
* @link https://github.com/timacdonald/log-fake#assertnotlogged Documentation
* @param (Closure(LogEntry): bool) $callback
*
* @param (Closure(LogEntry): bool) $callback
*/
public function assertNotLogged(Closure $callback, ?string $message = null): ChannelFake
{
Expand Down Expand Up @@ -151,20 +156,21 @@ public function assertWasNotForgotten(?string $message = null): ChannelFake

/**
* @link https://github.com/timacdonald/log-fake#assertcurrentcontext Documentation
* @param (Closure(array<array-key, mixed>): bool)|array<array-key, mixed> $context
*
* @param (Closure(array<array-key, mixed>): bool)|array<array-key, mixed> $context
*/
public function assertCurrentContext(Closure|array $context, ?string $message = null): ChannelFake
{
if ($context instanceof Closure) {
PHPUnit::assertTrue(
(bool) $context($this->currentContext()),
$message ?? 'Unexpected context found in the [' . $this->name . '] channel. Found [' . json_encode((object) $this->currentContext(), JSON_THROW_ON_ERROR) . '].'
$message ?? 'Unexpected context found in the ['.$this->name.'] channel. Found ['.json_encode((object) $this->currentContext(), JSON_THROW_ON_ERROR).'].'
);
} else {
PHPUnit::assertSame(
$context,
$this->currentContext(),
'Expected to find the context [' . json_encode($context, JSON_THROW_ON_ERROR) . '] in the [' . $this->name . '] channel. Found [' . json_encode((object) $this->currentContext(), JSON_THROW_ON_ERROR) . '] instead.'
'Expected to find the context ['.json_encode($context, JSON_THROW_ON_ERROR).'] in the ['.$this->name.'] channel. Found ['.json_encode((object) $this->currentContext(), JSON_THROW_ON_ERROR).'] instead.'
);
}

Expand All @@ -188,8 +194,9 @@ public function log($level, $message, array $context = []): void

/**
* @see Logger::write()
* @param \Illuminate\Contracts\Support\Arrayable<array-key, mixed>|\Illuminate\Contracts\Support\Jsonable|\Illuminate\Support\Stringable|array<array-key, mixed>|string $message
* @param array<array-key, mixed> $context
*
* @param \Illuminate\Contracts\Support\Arrayable<array-key, mixed>|\Illuminate\Contracts\Support\Jsonable|\Illuminate\Support\Stringable|array<array-key, mixed>|string $message
* @param array<array-key, mixed> $context
*/
public function write(string $level, $message, array $context = []): void
{
Expand All @@ -198,7 +205,8 @@ public function write(string $level, $message, array $context = []): void

/**
* @see Logger::withContext()
* @param array<array-key, mixed> $context
*
* @param array<array-key, mixed> $context
*/
public function withContext(array $context = []): ChannelFake
{
Expand Down Expand Up @@ -250,7 +258,7 @@ public function setEventDispatcher(Dispatcher $dispatcher): void
}

/**
* @param (Closure(LogEntry): bool) $callback
* @param (Closure(LogEntry): bool) $callback
* @return Collection<int, LogEntry>
*/
private function logged(Closure $callback): Collection
Expand Down
26 changes: 16 additions & 10 deletions src/LogFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public static function bind(): LogFake

/**
* @link https://github.com/timacdonald/log-fake#dumpall Documentation
* @param (CLosure(LogEntry): bool) $callback
*
* @param (CLosure(LogEntry): bool) $callback
*/
public function dumpAll(?Closure $callback = null): LogFake
{
Expand All @@ -58,9 +59,10 @@ public function dumpAll(?Closure $callback = null): LogFake

/**
* @link https://github.com/timacdonald/log-fake#ddall Documentation
* @codeCoverageIgnore
*
* @infection-ignore-all
* @param (Closure(LogEntry): bool) $callback
*
* @param (Closure(LogEntry): bool) $callback
*/
public function ddAll(?Closure $callback = null): never
{
Expand All @@ -84,7 +86,8 @@ public function assertChannelIsCurrentlyForgotten(string $name, ?string $message

/**
* @see LogManager::build()
* @param array<string, mixed> $config
*
* @param array<string, mixed> $config
*/
public function build(array $config): ChannelFake
{
Expand All @@ -95,7 +98,8 @@ public function build(array $config): ChannelFake

/**
* @see LogManager::stack()
* @param array<int, string> $channels
*
* @param array<int, string> $channels
*/
public function stack(array $channels, ?string $channel = null): ChannelFake
{
Expand All @@ -106,7 +110,6 @@ public function stack(array $channels, ?string $channel = null): ChannelFake
return $this->stacks[$name]->clearContext();
}


/**
* @see LogManager::channel()
*/
Expand Down Expand Up @@ -164,6 +167,7 @@ public function forgetChannel(?string $driver = null): LogFake

/**
* @see LogManager::getChannels()
*
* @return array<string, ChannelFake>
*/
public function getChannels(): array
Expand All @@ -174,7 +178,8 @@ public function getChannels(): array
/**
* @see LogManager::log()
* @see LoggerInterface::log()
* @param mixed $level
*
* @param mixed $level
*/
public function log($level, $message, array $context = []): void
{
Expand All @@ -183,7 +188,8 @@ public function log($level, $message, array $context = []): void

/**
* @see LogManager::__call()
* @param array<string, mixed> $parameters
*
* @param array<string, mixed> $parameters
*/
public function __call(string $method, array $parameters): mixed
{
Expand Down Expand Up @@ -213,10 +219,10 @@ private function parseChannelDriver(?string $driver): string
}

/**
* @param array<int, string> $channels
* @param array<int, string> $channels
*/
private static function parseStackDriver(array $channels, ?string $channel): string
{
return 'stack::' . ($channel ?? 'unnamed') . ':' . Collection::make($channels)->sort()->implode(',');
return 'stack::'.($channel ?? 'unnamed').':'.Collection::make($channels)->sort()->implode(',');
}
}
3 changes: 2 additions & 1 deletion src/StackFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class StackFake extends ChannelFake
{
/**
* @link https://github.com/timacdonald/log-fake#assertcurrentcontext Documentation
* @param (Closure(array<array-key, mixed>): bool)|array<array-key, mixed> $context
*
* @param (Closure(array<array-key, mixed>): bool)|array<array-key, mixed> $context
*/
public function assertCurrentContext(Closure|array $context, ?string $message = null): StackFake
{
Expand Down
7 changes: 4 additions & 3 deletions tests/LogFakeApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public function testDummyMethods(): void
$log->extend('misc', function () {
//
});
$log->setEventDispatcher(new class () implements Dispatcher {
$log->setEventDispatcher(new class() implements Dispatcher
{
public function listen($events, $listener = null)
{
//
Expand Down Expand Up @@ -468,7 +469,8 @@ public function testItCanLogStringableObjects(): void
{
$log = new LogFake();
$callable = new CallableFake(fn () => true);
$log->info(new class () implements Stringable {
$log->info(new class() implements Stringable
{
public function __toString(): string
{
return 'expected message';
Expand Down Expand Up @@ -521,7 +523,6 @@ public function testItCanClearContext(): void
}, 1);
}


public function testItCanFakeOnDemandChannels(): void
{
$log = new LogFake();
Expand Down

0 comments on commit 1130984

Please sign in to comment.