Skip to content
Open
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
22 changes: 19 additions & 3 deletions src/Expectations/OppositeExpectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,25 @@ public function toUse(array|string $targets): ArchExpectation
/** @var Expectation<array<int, string>|string> $original */
$original = $this->original;

return GroupArchExpectation::fromExpectations($original, array_map(fn (string $target): SingleArchExpectation => ToUse::make($original, $target)->opposite(
fn (): never => $this->throwExpectationFailedException('toUse', $target),
), is_string($targets) ? [$targets] : $targets));
/** @var array<int, string> $subjects */
$subjects = is_string($original->value) ? [$original->value] : $original->value;
$dependencies = is_string($targets) ? [$targets] : $targets;

/** @var array<int, SingleArchExpectation> $expectations */
$expectations = [];

foreach ($subjects as $subject) {
$subjectExpectation = new Expectation($original->value);
$subjectExpectation->value = $subject;

foreach ($dependencies as $dependency) {
$expectations[] = ToUse::make($subjectExpectation, $dependency)->opposite(
fn (): never => $this->throwExpectationFailedException('toUse', $dependency),
);
}
}

return GroupArchExpectation::fromExpectations($original, $expectations);
}

public function toHaveFileSystemPermissions(string $permissions): ArchExpectation
Expand Down
10 changes: 9 additions & 1 deletion tests/.snapshots/success.txt
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,14 @@
PASS Tests\Features\Expect\not
✓ not property calls

PASS Tests\Features\Expect\notToUse
✓ single target negation fails when the target uses the dependency
✓ single target negation passes when the target does not use the dependency
✓ multi target negation fails when any target uses the dependency
✓ multi target negation passes when no target uses the dependency
✓ multi target negation fails when any target uses any listed dependency
✓ positive to use still fails when one target skips the dependency

PASS Tests\Features\Expect\pipes
✓ pipe is applied and can stop pipeline
✓ pipe is run and can let the pipeline keep going
Expand Down Expand Up @@ -2321,4 +2329,4 @@
✓ pass with dataset with ('my-datas-set-value')
✓ within describe → pass with dataset with ('my-datas-set-value')

Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 37 skipped, 1648 passed (3649 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 37 skipped, 1654 passed (3673 assertions)
38 changes: 38 additions & 0 deletions tests/Features/Expect/notToUse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

use PHPUnit\Framework\ExpectationFailedException;
use Tests\Fixtures\Arch\NotToUse\AlsoClean;
use Tests\Fixtures\Arch\NotToUse\Clean;
use Tests\Fixtures\Arch\NotToUse\Dependency;
use Tests\Fixtures\Arch\NotToUse\OtherDependency;
use Tests\Fixtures\Arch\NotToUse\UsesDependency;

test('single target negation fails when the target uses the dependency')
->throws(ExpectationFailedException::class)
->expect(UsesDependency::class)
->not->toUse(Dependency::class);

test('single target negation passes when the target does not use the dependency')
->expect(Clean::class)
->not->toUse(Dependency::class);

test('multi target negation fails when any target uses the dependency')
->throws(ExpectationFailedException::class)
->expect([UsesDependency::class, Clean::class])
->not->toUse(Dependency::class);

test('multi target negation passes when no target uses the dependency')
->expect([Clean::class, AlsoClean::class])
->not->toUse(Dependency::class);

test('multi target negation fails when any target uses any listed dependency')
->throws(ExpectationFailedException::class)
->expect([UsesDependency::class, Clean::class])
->not->toUse([Dependency::class, OtherDependency::class]);

test('positive to use still fails when one target skips the dependency')
->throws(ExpectationFailedException::class)
->expect([UsesDependency::class, Clean::class])
->toUse(Dependency::class);
7 changes: 7 additions & 0 deletions tests/Fixtures/Arch/NotToUse/AlsoClean.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

namespace Tests\Fixtures\Arch\NotToUse;

final class AlsoClean {}
7 changes: 7 additions & 0 deletions tests/Fixtures/Arch/NotToUse/Clean.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

namespace Tests\Fixtures\Arch\NotToUse;

final class Clean {}
7 changes: 7 additions & 0 deletions tests/Fixtures/Arch/NotToUse/Dependency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

namespace Tests\Fixtures\Arch\NotToUse;

final class Dependency {}
7 changes: 7 additions & 0 deletions tests/Fixtures/Arch/NotToUse/OtherDependency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

namespace Tests\Fixtures\Arch\NotToUse;

final class OtherDependency {}
13 changes: 13 additions & 0 deletions tests/Fixtures/Arch/NotToUse/UsesDependency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Tests\Fixtures\Arch\NotToUse;

final class UsesDependency
{
public function make(): Dependency
{
return new Dependency;
}
}
2 changes: 1 addition & 1 deletion tests/Visual/Parallel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
$output = $run('--exclude-group=integration');
$output = implode("\n", array_slice(explode("\n", (string) $output), -10));

$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 29 skipped, 1622 passed (3577 assertions)';
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 29 skipped, 1628 passed (3601 assertions)';

expect($output)
->toContain("Tests: {$expected}")
Expand Down