mirror of
https://github.com/pestphp/pest.git
synced 2026-03-10 09:47:23 +01:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cc6c5bf199 | |||
| b88d9e8ff2 | |||
| 0fc232bbc7 | |||
| 7dcd42d113 | |||
| e79ffc6bad | |||
| 8ea425b266 | |||
| 3a0f6a1d09 | |||
| b9b90295fa | |||
| 9dabecacbf | |||
| 04fa6b6372 | |||
| a0d2856f51 | |||
| bbac28c9f4 | |||
| e69899559d | |||
| e6fe968d44 | |||
| 678898efe7 |
18
CHANGELOG.md
18
CHANGELOG.md
@ -2,6 +2,24 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
## [v2.17.0 (2023-09-04)](https://github.com/pestphp/pest/compare/v2.16.1...v2.17.0)
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- `toHaveMethod` expectation ([#947](https://github.com/pestphp/pest/pull/947))
|
||||||
|
- `toHaveAttribute` expectation ([#934](https://github.com/pestphp/pest/pull/934))
|
||||||
|
|
||||||
|
## [v2.16.1 (2023-08-29)](https://github.com/pestphp/pest/compare/v2.16.0...v2.16.1)
|
||||||
|
|
||||||
|
> New changelog format starting this release.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
* `toHaveSameSize` expectation by @hungthai1401 in https://github.com/pestphp/pest/pull/924, https://github.com/pestphp/pest/pull/930
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
* Inconsistent type have count exception by @hungthai1401 in https://github.com/pestphp/pest/pull/923
|
||||||
|
* Datasets defined in `Pest.php`
|
||||||
|
|
||||||
## [v2.16.0 (2023-08-21)](https://github.com/pestphp/pest/compare/v2.15.0...v2.16.0)
|
## [v2.16.0 (2023-08-21)](https://github.com/pestphp/pest/compare/v2.15.0...v2.16.0)
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@ -78,6 +78,8 @@ final class BootFiles implements Bootstrapper
|
|||||||
|
|
||||||
private function bootDatasets(string $testsPath): void
|
private function bootDatasets(string $testsPath): void
|
||||||
{
|
{
|
||||||
|
assert(strlen($testsPath) > 0);
|
||||||
|
|
||||||
$files = (new PhpUnitFileIterator)->getFilesAsArray($testsPath, '.php');
|
$files = (new PhpUnitFileIterator)->getFilesAsArray($testsPath, '.php');
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
|||||||
@ -14,7 +14,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class NoDirtyTestsFound extends InvalidArgumentException implements ExceptionInterface, RenderlessEditor, RenderlessTrace, Panicable
|
final class NoDirtyTestsFound extends InvalidArgumentException implements ExceptionInterface, Panicable, RenderlessEditor, RenderlessTrace
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Renders the panic on the given output.
|
* Renders the panic on the given output.
|
||||||
|
|||||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest;
|
namespace Pest;
|
||||||
|
|
||||||
|
use Attribute;
|
||||||
use BadMethodCallException;
|
use BadMethodCallException;
|
||||||
use Closure;
|
use Closure;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
@ -501,6 +502,19 @@ final class Expectation
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the given expectation target has a specific method.
|
||||||
|
*/
|
||||||
|
public function toHaveMethod(string $method): ArchExpectation
|
||||||
|
{
|
||||||
|
return Targeted::make(
|
||||||
|
$this,
|
||||||
|
fn (ObjectDescription $object): bool => $object->reflectionClass->hasMethod($method),
|
||||||
|
'to have method',
|
||||||
|
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the given expectation target is enum.
|
* Asserts that the given expectation target is enum.
|
||||||
*/
|
*/
|
||||||
@ -833,4 +847,19 @@ final class Expectation
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the given expectation target to have the given attribute.
|
||||||
|
*
|
||||||
|
* @param class-string<Attribute> $attribute
|
||||||
|
*/
|
||||||
|
public function toHaveAttribute(string $attribute): ArchExpectation
|
||||||
|
{
|
||||||
|
return Targeted::make(
|
||||||
|
$this,
|
||||||
|
fn (ObjectDescription $object): bool => $object->reflectionClass->getAttributes($attribute) !== [],
|
||||||
|
"to have attribute '{$attribute}'",
|
||||||
|
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Expectations;
|
namespace Pest\Expectations;
|
||||||
|
|
||||||
|
use Attribute;
|
||||||
use Pest\Arch\Contracts\ArchExpectation;
|
use Pest\Arch\Contracts\ArchExpectation;
|
||||||
use Pest\Arch\Expectations\Targeted;
|
use Pest\Arch\Expectations\Targeted;
|
||||||
use Pest\Arch\Expectations\ToBeUsedIn;
|
use Pest\Arch\Expectations\ToBeUsedIn;
|
||||||
@ -149,6 +150,19 @@ final class OppositeExpectation
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the given expectation target does not have a specific method.
|
||||||
|
*/
|
||||||
|
public function toHaveMethod(string $method): ArchExpectation
|
||||||
|
{
|
||||||
|
return Targeted::make(
|
||||||
|
$this->original,
|
||||||
|
fn (ObjectDescription $object): bool => ! $object->reflectionClass->hasMethod($method),
|
||||||
|
'to not have method',
|
||||||
|
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the given expectation target is not enum.
|
* Asserts that the given expectation target is not enum.
|
||||||
*/
|
*/
|
||||||
@ -378,6 +392,21 @@ final class OppositeExpectation
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the given expectation target not to have the given attribute.
|
||||||
|
*
|
||||||
|
* @param class-string<Attribute> $attribute
|
||||||
|
*/
|
||||||
|
public function toHaveAttribute(string $attribute): ArchExpectation
|
||||||
|
{
|
||||||
|
return Targeted::make(
|
||||||
|
$this->original,
|
||||||
|
fn (ObjectDescription $object): bool => $object->reflectionClass->getAttributes($attribute) === [],
|
||||||
|
"to not have attribute '{$attribute}'",
|
||||||
|
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,10 +6,10 @@ namespace Pest;
|
|||||||
|
|
||||||
function version(): string
|
function version(): string
|
||||||
{
|
{
|
||||||
return '2.16.1';
|
return '2.17.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDirectory(string $file = ''): string
|
function testDirectory(string $file = ''): string
|
||||||
{
|
{
|
||||||
return TestSuite::getInstance()->testPath.'/'.$file;
|
return TestSuite::getInstance()->testPath.DIRECTORY_SEPARATOR.$file;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
Pest Testing Framework 2.16.1.
|
Pest Testing Framework 2.17.0.
|
||||||
|
|
||||||
USAGE: pest <file> [options]
|
USAGE: pest <file> [options]
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
|
|
||||||
Pest Testing Framework 2.16.1.
|
Pest Testing Framework 2.17.0.
|
||||||
|
|
||||||
|
|||||||
@ -630,6 +630,11 @@
|
|||||||
✓ failures with custom message
|
✓ failures with custom message
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Features\Expect\toHaveAttribute
|
||||||
|
✓ class has attribute
|
||||||
|
✓ opposite class has attribute
|
||||||
|
✓ class not has attribute
|
||||||
|
|
||||||
PASS Tests\Features\Expect\toHaveCamelCaseKeys
|
PASS Tests\Features\Expect\toHaveCamelCaseKeys
|
||||||
✓ pass
|
✓ pass
|
||||||
✓ failures
|
✓ failures
|
||||||
@ -695,10 +700,12 @@
|
|||||||
✓ it fails with message
|
✓ it fails with message
|
||||||
|
|
||||||
PASS Tests\Features\Expect\toHaveMethod
|
PASS Tests\Features\Expect\toHaveMethod
|
||||||
✓ pass
|
✓ class has method
|
||||||
✓ failures
|
✓ opposite class has method
|
||||||
✓ failures with message
|
✓ class has method via a parent class
|
||||||
✓ not failures
|
✓ class has method via a trait
|
||||||
|
✓ failure when the class has no method
|
||||||
|
✓ class has no method
|
||||||
|
|
||||||
PASS Tests\Features\Expect\toHaveMethods
|
PASS Tests\Features\Expect\toHaveMethods
|
||||||
✓ pass
|
✓ pass
|
||||||
@ -1307,4 +1314,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, 925 passed (2204 assertions)
|
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 930 passed (2200 assertions)
|
||||||
18
tests/Features/Expect/toHaveAttribute.php
Normal file
18
tests/Features/Expect/toHaveAttribute.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Pest\Arch\Exceptions\ArchExpectationFailedException;
|
||||||
|
|
||||||
|
test('class has attribute')
|
||||||
|
->expect('Tests\\Fixtures\\Arch\\ToHaveAttribute\\HaveAttribute')
|
||||||
|
->toHaveAttribute('Tests\\Fixtures\\Arch\\ToHaveAttribute\\Attributes\\AsAttribute');
|
||||||
|
|
||||||
|
test('opposite class has attribute')
|
||||||
|
->throws(ArchExpectationFailedException::class)
|
||||||
|
->expect('Tests\\Fixtures\\Arch\\ToHaveAttribute\\HaveAttribute')
|
||||||
|
->not
|
||||||
|
->toHaveAttribute('Tests\\Fixtures\\Arch\\ToHaveAttribute\\Attributes\\AsAttribute');
|
||||||
|
|
||||||
|
test('class not has attribute')
|
||||||
|
->expect('Tests\\Fixtures\\Arch\\ToHaveAttribute\\NotHaveAttribute')
|
||||||
|
->not
|
||||||
|
->toHaveAttribute('Tests\\Fixtures\\Arch\\ToHaveAttribute\\Attributes\\AsAttribute');
|
||||||
@ -1,28 +1,29 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
use Pest\Arch\Exceptions\ArchExpectationFailedException;
|
||||||
|
|
||||||
$object = new class
|
test('class has method')
|
||||||
{
|
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethod')
|
||||||
public function foo(): void
|
->toHaveMethod('foo');
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
test('pass', function () use ($object) {
|
test('opposite class has method')
|
||||||
expect($object)->toHaveMethod('foo')
|
->throws(ArchExpectationFailedException::class)
|
||||||
->and($object)->toHaveMethod('foo')
|
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethod')
|
||||||
->and($object)->not->toHaveMethod('fooNull');
|
->not->toHaveMethod('foo');
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () use ($object) {
|
test('class has method via a parent class')
|
||||||
expect($object)->toHaveMethod('bar');
|
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethodViaParent')
|
||||||
})->throws(ExpectationFailedException::class);
|
->toHaveMethod('foo');
|
||||||
|
|
||||||
test('failures with message', function () use ($object) {
|
test('class has method via a trait')
|
||||||
expect($object)->toHaveMethod(name: 'bar', message: 'oh no!');
|
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethodViaTrait')
|
||||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
->toHaveMethod('foo');
|
||||||
|
|
||||||
test('not failures', function () use ($object) {
|
test('failure when the class has no method')
|
||||||
expect($object)->not->toHaveMethod('foo');
|
->throws(ArchExpectationFailedException::class)
|
||||||
})->throws(ExpectationFailedException::class);
|
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasNoMethod\HasNoMethodClass')
|
||||||
|
->toHaveMethod('foo');
|
||||||
|
|
||||||
|
test('class has no method')
|
||||||
|
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasNoMethod\HasNoMethodClass')
|
||||||
|
->not->toHaveMethod('foo');
|
||||||
|
|||||||
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveAttribute\Attributes;
|
||||||
|
|
||||||
|
use Attribute;
|
||||||
|
|
||||||
|
#[Attribute()]
|
||||||
|
class AsAttribute
|
||||||
|
{
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveAttribute\HaveAttribute;
|
||||||
|
|
||||||
|
use Tests\Fixtures\Arch\ToHaveAttribute\Attributes\AsAttribute;
|
||||||
|
|
||||||
|
#[AsAttribute]
|
||||||
|
class HaveAttributeClass
|
||||||
|
{
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveAttribute\NotHaveAttribute;
|
||||||
|
|
||||||
|
class NotHaveAttributeClass
|
||||||
|
{
|
||||||
|
}
|
||||||
13
tests/Fixtures/Arch/ToHaveMethod/HasMethod/HasMethod.php
Normal file
13
tests/Fixtures/Arch/ToHaveMethod/HasMethod/HasMethod.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveMethod\HasMethod;
|
||||||
|
|
||||||
|
class HasMethod
|
||||||
|
{
|
||||||
|
public function foo(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveMethod\HasMethod;
|
||||||
|
|
||||||
|
trait HasMethodTrait
|
||||||
|
{
|
||||||
|
public function foo(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveMethod\HasMethod;
|
||||||
|
|
||||||
|
class HasMethodViaParent extends ParentHasMethodClass
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveMethod\HasMethod;
|
||||||
|
|
||||||
|
class HasMethodViaTrait
|
||||||
|
{
|
||||||
|
use HasMethodTrait;
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveMethod\HasMethod;
|
||||||
|
|
||||||
|
class ParentHasMethodClass
|
||||||
|
{
|
||||||
|
public function foo(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveMethod\HasNoMethod;
|
||||||
|
|
||||||
|
class HasNoMethodClass
|
||||||
|
{
|
||||||
|
public function bar(): 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, 914 passed (2189 assertions)')
|
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 919 passed (2185 assertions)')
|
||||||
->toContain('Parallel: 3 processes');
|
->toContain('Parallel: 3 processes');
|
||||||
})->skipOnWindows();
|
})->skipOnWindows();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user