mirror of
https://github.com/pestphp/pest.git
synced 2026-03-10 01:37:21 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 049da041b2 | |||
| 4d7aa2b98f | |||
| 3f854713e6 | |||
| 011bd3ba82 |
@ -46,6 +46,7 @@ $bootPest = (static function (): void {
|
|||||||
];
|
];
|
||||||
|
|
||||||
foreach ($composerAutoloadFiles as $file) {
|
foreach ($composerAutoloadFiles as $file) {
|
||||||
|
|
||||||
if (file_exists($file)) {
|
if (file_exists($file)) {
|
||||||
require_once $file;
|
require_once $file;
|
||||||
define('PHPUNIT_COMPOSER_INSTALL', $file);
|
define('PHPUNIT_COMPOSER_INSTALL', $file);
|
||||||
|
|||||||
@ -693,4 +693,17 @@ final class Expectation
|
|||||||
{
|
{
|
||||||
return ToBeUsedInNothing::make($this);
|
return ToBeUsedInNothing::make($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the given expectation dependency is an invokable class.
|
||||||
|
*/
|
||||||
|
public function toBeInvokable(): ArchExpectation
|
||||||
|
{
|
||||||
|
return Targeted::make(
|
||||||
|
$this,
|
||||||
|
fn (ObjectDescription $object): bool => $object->reflectionClass->hasMethod('__invoke'),
|
||||||
|
'to be invokable',
|
||||||
|
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class'))
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -365,6 +365,19 @@ final class OppositeExpectation
|
|||||||
throw InvalidExpectation::fromMethods(['not', 'toBeUsedInNothing']);
|
throw InvalidExpectation::fromMethods(['not', 'toBeUsedInNothing']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the given expectation dependency is not an invokable class.
|
||||||
|
*/
|
||||||
|
public function toBeInvokable(): ArchExpectation
|
||||||
|
{
|
||||||
|
return Targeted::make(
|
||||||
|
$this->original,
|
||||||
|
fn (ObjectDescription $object): bool => ! $object->reflectionClass->hasMethod('__invoke'),
|
||||||
|
'to not be invokable',
|
||||||
|
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle dynamic method calls into the original expectation.
|
* Handle dynamic method calls into the original expectation.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -6,7 +6,7 @@ namespace Pest;
|
|||||||
|
|
||||||
function version(): string
|
function version(): string
|
||||||
{
|
{
|
||||||
return '2.10.1';
|
return '2.11.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDirectory(string $file = ''): string
|
function testDirectory(string $file = ''): string
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
Pest Testing Framework 2.10.1.
|
Pest Testing Framework 2.11.0.
|
||||||
|
|
||||||
USAGE: pest <file> [options]
|
USAGE: pest <file> [options]
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
|
|
||||||
Pest Testing Framework 2.10.1.
|
Pest Testing Framework 2.11.0.
|
||||||
|
|
||||||
|
|||||||
@ -411,6 +411,14 @@
|
|||||||
✓ failures with custom message
|
✓ failures with custom message
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Features\Expect\toBeInvokable
|
||||||
|
✓ class is invokable
|
||||||
|
✓ opposite class is invokable
|
||||||
|
✓ class is invokable via a parent class
|
||||||
|
✓ class is invokable via a trait
|
||||||
|
✓ failure when the class is not invokable
|
||||||
|
✓ class is not invokable
|
||||||
|
|
||||||
PASS Tests\Features\Expect\toBeIterable
|
PASS Tests\Features\Expect\toBeIterable
|
||||||
✓ pass
|
✓ pass
|
||||||
✓ failures
|
✓ failures
|
||||||
@ -1186,4 +1194,4 @@
|
|||||||
WARN Tests\Visual\Version
|
WARN Tests\Visual\Version
|
||||||
- visual snapshot of help command output
|
- visual snapshot of help command output
|
||||||
|
|
||||||
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 838 passed (1939 assertions)
|
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 844 passed (1947 assertions)
|
||||||
29
tests/Features/Expect/toBeInvokable.php
Normal file
29
tests/Features/Expect/toBeInvokable.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Pest\Arch\Exceptions\ArchExpectationFailedException;
|
||||||
|
|
||||||
|
test('class is invokable')
|
||||||
|
->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsInvokable\\InvokableClass')
|
||||||
|
->toBeInvokable();
|
||||||
|
|
||||||
|
test('opposite class is invokable')
|
||||||
|
->throws(ArchExpectationFailedException::class)
|
||||||
|
->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsInvokable\\InvokableClass')
|
||||||
|
->not->toBeInvokable();
|
||||||
|
|
||||||
|
test('class is invokable via a parent class')
|
||||||
|
->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsInvokable\\InvokableClassViaParent')
|
||||||
|
->toBeInvokable();
|
||||||
|
|
||||||
|
test('class is invokable via a trait')
|
||||||
|
->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsInvokable\\InvokableClassViaTrait')
|
||||||
|
->toBeInvokable();
|
||||||
|
|
||||||
|
test('failure when the class is not invokable')
|
||||||
|
->throws(ArchExpectationFailedException::class)
|
||||||
|
->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsNotInvokable\\IsNotInvokableClass')
|
||||||
|
->toBeInvokable();
|
||||||
|
|
||||||
|
test('class is not invokable')
|
||||||
|
->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsNotInvokable\\IsNotInvokableClass')
|
||||||
|
->not->toBeInvokable();
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToBeInvokable\IsInvokable;
|
||||||
|
|
||||||
|
class InvokableClass
|
||||||
|
{
|
||||||
|
public function __invoke(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToBeInvokable\IsInvokable;
|
||||||
|
|
||||||
|
class InvokableClassViaParent extends ParentInvokableClass
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToBeInvokable\IsInvokable;
|
||||||
|
|
||||||
|
class InvokableClassViaTrait
|
||||||
|
{
|
||||||
|
use InvokableTrait;
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToBeInvokable\IsInvokable;
|
||||||
|
|
||||||
|
trait InvokableTrait
|
||||||
|
{
|
||||||
|
public function __invoke(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToBeInvokable\IsInvokable;
|
||||||
|
|
||||||
|
class ParentInvokableClass
|
||||||
|
{
|
||||||
|
public function __invoke(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToBeInvokable\IsNotInvokable;
|
||||||
|
|
||||||
|
class IsNotInvokableClass
|
||||||
|
{
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,7 +16,7 @@ $run = function () {
|
|||||||
|
|
||||||
test('parallel', function () use ($run) {
|
test('parallel', function () use ($run) {
|
||||||
expect($run('--exclude-group=integration'))
|
expect($run('--exclude-group=integration'))
|
||||||
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 827 passed (1924 assertions)')
|
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 833 passed (1932 assertions)')
|
||||||
->toContain('Parallel: 3 processes');
|
->toContain('Parallel: 3 processes');
|
||||||
})->skipOnWindows();
|
})->skipOnWindows();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user