Skip to content

Commit

Permalink
chore: adds more tests on native functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Aug 21, 2023
1 parent e3f51ae commit 8662a78
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Factories/LayerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function __construct(
public function make(LayerOptions $options, string $name, bool $onlyUserDefinedUses = true): Layer
{
$objects = array_map(function (ObjectDescription $object) use ($options): ObjectDescription {

if ($object instanceof VendorObjectDescription) {
return $object;
}
Expand Down
58 changes: 58 additions & 0 deletions tests/NativeFunctions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

use PHPUnit\Framework\ExpectationFailedException;

test('native functions', function () {
expect('Tests')->toUse('sleep');
expect('Tests')->not->toUse('die');

expect('die')->not->toBeUsed();
expect('die')->toBeUsedInNothing();

expect('sleep')->toBeUsedIn('Tests')
->and('die')->not->toBeUsedIn('Tests');

expect('die')->toOnlyBeUsedIn('Tests');
});

test('failure 1', function () {
expect('Tests')->toUse('die');
})->throws(
ExpectationFailedException::class,
"Expecting 'Tests' to use 'die'."
);

test('failure 2', function () {
expect('Tests')->not->toUse('sleep');
})->throws(
ExpectationFailedException::class,
"Expecting 'Tests' not to use 'sleep'."
);

test('failure 3', function () {
expect('sleep')->not->toBeUsed();
})->throws(
\Pest\Arch\Exceptions\ArchExpectationFailedException::class,
'Expecting \'sleep\' not to be used on \'Tests\Fixtures\Misc\HasSleepFunction\'.'
);

test('failure 4', function () {
expect('sleep')->toBeUsedInNothing();
})->throws(
\Pest\Arch\Exceptions\ArchExpectationFailedException::class,
'Expecting \'sleep\' not to be used on \'Tests\Fixtures\Misc\HasSleepFunction\'.'
);

test('failure 5', function () {
expect('die')->toBeUsedIn('Tests\Fixtures\Misc\HasSleepFunction');
})->throws(
ExpectationFailedException::class,
'Expecting \'Tests\Fixtures\Misc\HasSleepFunction\' to use \'die\'.',
);

test('failure 6', function () {
expect('sleep')->not->toBeUsedIn('Tests\Fixtures\Misc\HasSleepFunction');
})->throws(
ExpectationFailedException::class,
'Expecting \'sleep\' not to be used in \'Tests\Fixtures\Misc\HasSleepFunction\'.',
);
4 changes: 2 additions & 2 deletions tests/ToBeUsedInNothing.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
});

it('passes as aliases', function () {
expect([Env::class])->not->toBeUsed();
expect([Env::class, 'die'])->not->toBeUsed();
});

it('fails 1', function () {
Expand All @@ -34,7 +34,7 @@
expect(fn () => expect('sleep')->not->toBeUsed())->toThrowArchitectureViolation(
"Expecting 'sleep' not to be used on 'Tests\Fixtures\Misc\HasSleepFunction'.",
'tests/Fixtures/Misc/HasSleepFunction.php',
10
9,
);
});

Expand Down

0 comments on commit 8662a78

Please sign in to comment.