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

Updated constraints (used new interfaces) #12

Merged
merged 6 commits into from
Nov 21, 2023
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
23 changes: 0 additions & 23 deletions .github/workflows/phpstan-6.yaml

This file was deleted.

23 changes: 0 additions & 23 deletions .github/workflows/phpstan-7.yaml

This file was deleted.

23 changes: 0 additions & 23 deletions .github/workflows/phpstan-8.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PHPStan level 5
name: PHPStan level 9
on: push
jobs:
phpstan:
Expand All @@ -19,5 +19,5 @@ jobs:
uses: php-actions/phpstan@v3
with:
path: src/
level: 5
level: 9
php_version: '8.2'
4 changes: 2 additions & 2 deletions .github/workflows/quality.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Quality
name: Quality (PHPSpec level 8)
on: push
jobs:
cs-fixer:
Expand Down Expand Up @@ -34,5 +34,5 @@ jobs:
uses: php-actions/phpstan@v3
with:
path: src/
level: 3
level: 8
php_version: '8.2'
4 changes: 4 additions & 0 deletions src/BuilderTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ protected function tearDown(): void

protected function getBuilderCompilePath(): string
{
if ($this->fs === null) {
throw new \RuntimeException('The virtual file system was not initialized. The '.__METHOD__.' method should be called after the '.static::class.'::setUp() method was called and after the '.static::class.'::tearDown() method is called.');
}

return $this->fs->url();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Constraint/Builder/BuilderProducesCodeThat.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class BuilderProducesCodeThat extends UnaryOperator
{
public function __construct(
private readonly string $builderCompilePath,
$constraint,
mixed $constraint,
) {
parent::__construct($constraint);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Constraint/Pipeline/IteratesLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private function asIterator(iterable $iterable): \Iterator
return new \IteratorIterator($iterable);
}

public function matches($other): bool
public function matches(mixed $other): bool
{
$both = new \MultipleIterator(\MultipleIterator::MIT_NEED_ANY);

Expand All @@ -54,7 +54,7 @@ public function matches($other): bool
return !$iterator->valid();
}

protected function failureDescription($other): string
protected function failureDescription(mixed $other): string
{
return sprintf(
'%s iterates like %s',
Expand Down
19 changes: 11 additions & 8 deletions src/Constraint/Pipeline/PipelineExtractsLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

namespace Kiboko\Component\PHPUnitExtension\Constraint\Pipeline;

use Kiboko\Contract\Bucket\ResultBucketInterface;
use Kiboko\Contract\Pipeline\ExtractorInterface;
use Kiboko\Contract\Pipeline\NullRejection;
use Kiboko\Contract\Pipeline\NullState;
use Kiboko\Contract\Pipeline\NullStepRejection;
use Kiboko\Contract\Pipeline\NullStepState;
use Kiboko\Contract\Pipeline\PipelineRunnerInterface;
use PHPUnit\Framework\Constraint\Constraint;

Expand All @@ -26,9 +27,11 @@ public function __construct(
}

/**
* @param list<Type> $iterable
* @template ItemType
*
* @return \Iterator<Type>
* @param list<ItemType> $iterable
*
* @return \Iterator<ItemType>
*/
private function asIterator(iterable $iterable): \Iterator
{
Expand All @@ -50,7 +53,7 @@ private function passThroughCoroutine(): \Generator
}
}

public function matches($other): bool
public function matches(mixed $other): bool
{
$both = new \MultipleIterator(\MultipleIterator::MIT_NEED_ANY);

Expand All @@ -67,8 +70,8 @@ public function matches($other): bool
$iterator = $this->runner->run(
$this->asIterator($extract),
$this->passThroughCoroutine(),
new NullRejection(),
new NullState(),
new NullStepRejection(),
new NullStepState(),
);
$both->attachIterator($iterator);

Expand All @@ -82,7 +85,7 @@ public function matches($other): bool
return !$iterator->valid();
}

protected function failureDescription($other): string
protected function failureDescription(mixed $other): string
{
return sprintf(
'%s pipeline extracts like %s',
Expand Down
20 changes: 10 additions & 10 deletions src/Constraint/Pipeline/PipelineLoadsLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Kiboko\Contract\Pipeline\FlushableInterface;
use Kiboko\Contract\Pipeline\LoaderInterface;
use Kiboko\Contract\Pipeline\NullRejection;
use Kiboko\Contract\Pipeline\NullState;
use Kiboko\Contract\Pipeline\NullStepRejection;
use Kiboko\Contract\Pipeline\NullStepState;
use Kiboko\Contract\Pipeline\PipelineRunnerInterface;
use PHPUnit\Framework\Constraint\Constraint;

Expand Down Expand Up @@ -47,7 +47,7 @@ private function asIterator(iterable $iterable): \Iterator
return new \IteratorIterator($iterable);
}

public function matches($other): bool
public function matches(mixed $other): bool
{
$both = new \MultipleIterator(\MultipleIterator::MIT_NEED_ANY);

Expand All @@ -67,8 +67,8 @@ public function matches($other): bool
$this->runner->run(
$this->asIterator($this->source),
$other->load(),
new NullRejection(),
new NullState(),
new NullStepRejection(),
new NullStepState(),
)
);
$iterator->append(
Expand All @@ -78,16 +78,16 @@ public function matches($other): bool
yield;
yield $other->flush();
})(),
new NullRejection(),
new NullState(),
new NullStepRejection(),
new NullStepState(),
)
);
} else {
$iterator = $this->runner->run(
$this->asIterator($this->source),
$other->load(),
new NullRejection(),
new NullState(),
new NullStepRejection(),
new NullStepState(),
);
}
$both->attachIterator($iterator);
Expand All @@ -102,7 +102,7 @@ public function matches($other): bool
return !$iterator->valid();
}

protected function failureDescription($other): string
protected function failureDescription(mixed $other): string
{
return sprintf(
'%s pipeline loads like %s',
Expand Down
20 changes: 10 additions & 10 deletions src/Constraint/Pipeline/PipelineTransformsLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Kiboko\Component\PHPUnitExtension\Constraint\Pipeline;

use Kiboko\Contract\Pipeline\FlushableInterface;
use Kiboko\Contract\Pipeline\NullRejection;
use Kiboko\Contract\Pipeline\NullState;
use Kiboko\Contract\Pipeline\NullStepRejection;
use Kiboko\Contract\Pipeline\NullStepState;
use Kiboko\Contract\Pipeline\PipelineRunnerInterface;
use Kiboko\Contract\Pipeline\TransformerInterface;
use PHPUnit\Framework\Constraint\Constraint;
Expand Down Expand Up @@ -47,7 +47,7 @@ private function asIterator(iterable $iterable): \Iterator
return new \IteratorIterator($iterable);
}

public function matches($other): bool
public function matches(mixed $other): bool
{
$both = new \MultipleIterator(\MultipleIterator::MIT_NEED_ANY);

Expand All @@ -67,8 +67,8 @@ public function matches($other): bool
$this->runner->run(
$this->asIterator($this->source),
$other->transform(),
new NullRejection(),
new NullState(),
new NullStepRejection(),
new NullStepState(),
)
);
$iterator->append(
Expand All @@ -78,16 +78,16 @@ public function matches($other): bool
yield;
yield $other->flush();
})(),
new NullRejection(),
new NullState(),
new NullStepRejection(),
new NullStepState(),
)
);
} else {
$iterator = $this->runner->run(
$this->asIterator($this->source),
$other->transform(),
new NullRejection(),
new NullState(),
new NullStepRejection(),
new NullStepState(),
);
}
$both->attachIterator($iterator);
Expand All @@ -102,7 +102,7 @@ public function matches($other): bool
return !$iterator->valid();
}

protected function failureDescription($other): string
protected function failureDescription(mixed $other): string
{
return sprintf(
'%s pipeline transforms like %s',
Expand Down
25 changes: 11 additions & 14 deletions src/Constraint/Pipeline/PipelineWritesFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Kiboko\Contract\Pipeline\FlushableInterface;
use Kiboko\Contract\Pipeline\LoaderInterface;
use Kiboko\Contract\Pipeline\NullRejection;
use Kiboko\Contract\Pipeline\NullState;
use Kiboko\Contract\Pipeline\NullStepRejection;
use Kiboko\Contract\Pipeline\NullStepState;
use Kiboko\Contract\Pipeline\PipelineRunnerInterface;
use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\Constraint\FileExists;
Expand All @@ -22,8 +22,7 @@ public function __construct(
private readonly iterable $source,
private readonly string $expected,
private readonly PipelineRunnerInterface $runner,
) {
}
) {}

/**
* @param list<Type> $iterable
Expand All @@ -42,7 +41,7 @@ private function asIterator(iterable $iterable): \Iterator
return new \IteratorIterator($iterable);
}

public function matches($other): bool
public function matches(mixed $other): bool
{
if (!$other instanceof LoaderInterface) {
$this->fail($other, strtr('Expected an instance of %expected%, but got %actual%.', [
Expand All @@ -58,8 +57,8 @@ public function matches($other): bool
$this->runner->run(
$this->asIterator($this->source),
$other->load(),
new NullRejection(),
new NullState(),
new NullStepRejection(),
new NullStepState(),
)
);
$iterator->append(
Expand All @@ -69,28 +68,26 @@ public function matches($other): bool
yield;
yield $other->flush();
})(),
new NullRejection(),
new NullState(),
new NullStepRejection(),
new NullStepState(),
)
);
} else {
$iterator = $this->runner->run(
$this->asIterator($this->source),
$other->load(),
new NullRejection(),
new NullState(),
new NullStepRejection(),
new NullStepState(),
);
}

iterator_count($iterator);

$constraint = new FileExists();
$constraint->evaluate($this->expected);

return !$iterator->valid();
}

protected function failureDescription($other): string
protected function failureDescription(mixed $other): string
{
return sprintf(
'%s pipeline writes file %s',
Expand Down
Loading