Files
pest/tests/Features/Expect/notToUse.php
T
Tiago Santos a6b81dbd73 fix: check each target in negated toUse (#1933)
* fix: check each target in negated toUse

A skipped class in expect([...]) made the positive rule fail,
so the negation passed even when another class used the dependency.

Fixes #1751

* test: update snapshots for notToUse

Negated toUse coverage adds 6 tests and 24 assertions,
so the success snapshot and parallel totals were stale.

---------

Co-authored-by: Tiago Santos <tsantos@lynixt.pt>
Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
2026-11-14 16:13:29 +05:30

39 lines
1.4 KiB
PHP

<?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);