mirror of
https://github.com/pestphp/pest.git
synced 2026-03-09 17:27:22 +01:00
Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cc6c5bf199 | |||
| b88d9e8ff2 | |||
| 0fc232bbc7 | |||
| 7dcd42d113 | |||
| e79ffc6bad | |||
| 8ea425b266 | |||
| 3a0f6a1d09 | |||
| b9b90295fa | |||
| 9dabecacbf | |||
| 04fa6b6372 | |||
| a0d2856f51 | |||
| 55b9266648 | |||
| 4313a1ef20 | |||
| 005ef03845 | |||
| bbac28c9f4 | |||
| eb56483ba2 | |||
| 5d6b717c9a | |||
| e69899559d | |||
| e6fe968d44 | |||
| 678898efe7 | |||
| 14859a4c89 | |||
| 8a44d3f136 | |||
| be71d6918d | |||
| afb3dd459a | |||
| b6e3ffafa7 | |||
| 6c95f3d8cf | |||
| 2192373bec | |||
| dfcdaa3f8e | |||
| 79bc9e677f | |||
| 60b615ea6a | |||
| 8787481e40 | |||
| c24406259f |
34
CHANGELOG.md
34
CHANGELOG.md
@ -2,6 +2,40 @@
|
|||||||
|
|
||||||
## 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)
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- `toBeDigits` ([#911](https://github.com/pestphp/pest/pull/911))
|
||||||
|
- `toBeCamelCase`, `toBeKebabCase`, `toBeSnakeCase`, `toBeStudlyCase`, `toHaveSnakeCaseKeys`, `toHaveKebabCaseKeys`, `toHaveCamelCaseKeys`, `toHaveStudlyCaseKeys`` ([#921](https://github.com/pestphp/pest/pull/921))
|
||||||
|
- native functions support on `arch` expectations, e.g: `expect('sleep')->toBeUsed();` ([#4](https://github.com/pestphp/pest-plugin-arch/pull/4))
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- `phpunit.xml` stub ([#915](https://github.com/pestphp/pest/pull/915))
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Nested sequences ([#895](https://github.com/pestphp/pest/pull/895))
|
||||||
|
|
||||||
## [v2.15.0 (2023-08-17)](https://github.com/pestphp/pest/compare/v2.14.1...v2.15.0)
|
## [v2.15.0 (2023-08-17)](https://github.com/pestphp/pest/compare/v2.14.1...v2.15.0)
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@ -18,11 +18,11 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.1.0",
|
"php": "^8.1.0",
|
||||||
"brianium/paratest": "^7.2.5",
|
"brianium/paratest": "^7.2.6",
|
||||||
"nunomaduro/collision": "^7.8.1",
|
"nunomaduro/collision": "^7.8.1",
|
||||||
"nunomaduro/termwind": "^1.15.1",
|
"nunomaduro/termwind": "^1.15.1",
|
||||||
"pestphp/pest-plugin": "^2.0.1",
|
"pestphp/pest-plugin": "^2.1.1",
|
||||||
"pestphp/pest-plugin-arch": "^2.3.1",
|
"pestphp/pest-plugin-arch": "^2.3.3",
|
||||||
"phpunit/phpunit": "^10.3.2"
|
"phpunit/phpunit": "^10.3.2"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
@ -51,8 +51,8 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"pestphp/pest-dev-tools": "^2.16.0",
|
"pestphp/pest-dev-tools": "^2.16.0",
|
||||||
"pestphp/pest-plugin-type-coverage": "^2.0.0",
|
"pestphp/pest-plugin-type-coverage": "^2.2.0",
|
||||||
"symfony/process": "^6.3.2"
|
"symfony/process": "^6.3.4"
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"prefer-stable": true,
|
"prefer-stable": true,
|
||||||
|
|||||||
@ -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,6 +6,7 @@ namespace Pest\Mixins;
|
|||||||
|
|
||||||
use BadMethodCallException;
|
use BadMethodCallException;
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use Countable;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Error;
|
use Error;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
@ -264,7 +265,7 @@ final class Expectation
|
|||||||
public function toHaveCount(int $count, string $message = ''): self
|
public function toHaveCount(int $count, string $message = ''): self
|
||||||
{
|
{
|
||||||
if (! is_countable($this->value) && ! is_iterable($this->value)) {
|
if (! is_countable($this->value) && ! is_iterable($this->value)) {
|
||||||
InvalidExpectationValue::expected('string');
|
InvalidExpectationValue::expected('countable|iterable');
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert::assertCount($count, $this->value, $message);
|
Assert::assertCount($count, $this->value, $message);
|
||||||
@ -272,6 +273,23 @@ final class Expectation
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the size of the value and $expected are the same.
|
||||||
|
*
|
||||||
|
* @param Countable|iterable<mixed> $expected
|
||||||
|
* @return self<TValue>
|
||||||
|
*/
|
||||||
|
public function toHaveSameSize(Countable|iterable $expected, string $message = ''): self
|
||||||
|
{
|
||||||
|
if (! is_countable($this->value) && ! is_iterable($this->value)) {
|
||||||
|
InvalidExpectationValue::expected('countable|iterable');
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert::assertSameSize($expected, $this->value, $message);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the value contains the property $name.
|
* Asserts that the value contains the property $name.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -6,10 +6,10 @@ namespace Pest;
|
|||||||
|
|
||||||
function version(): string
|
function version(): string
|
||||||
{
|
{
|
||||||
return '2.16.0';
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Support;
|
namespace Pest\Support;
|
||||||
|
|
||||||
|
use function Pest\testDirectory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
@ -25,6 +27,10 @@ final class DatasetInfo
|
|||||||
|
|
||||||
public static function scope(string $file): string
|
public static function scope(string $file): string
|
||||||
{
|
{
|
||||||
|
if (Str::endsWith($file, testDirectory('Pest.php'))) {
|
||||||
|
return dirname($file);
|
||||||
|
}
|
||||||
|
|
||||||
if (self::isInsideADatasetsDirectory($file)) {
|
if (self::isInsideADatasetsDirectory($file)) {
|
||||||
return dirname($file, 2);
|
return dirname($file, 2);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
Pest Testing Framework 2.16.0.
|
Pest Testing Framework 2.17.0.
|
||||||
|
|
||||||
USAGE: pest <file> [options]
|
USAGE: pest <file> [options]
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
|
|
||||||
Pest Testing Framework 2.16.0.
|
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
|
||||||
@ -638,6 +643,7 @@
|
|||||||
|
|
||||||
PASS Tests\Features\Expect\toHaveCount
|
PASS Tests\Features\Expect\toHaveCount
|
||||||
✓ pass
|
✓ pass
|
||||||
|
✓ failures with invalid type
|
||||||
✓ failures
|
✓ failures
|
||||||
✓ failures with message
|
✓ failures with message
|
||||||
✓ not failures
|
✓ not failures
|
||||||
@ -694,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
|
||||||
@ -722,6 +730,13 @@
|
|||||||
✓ failures
|
✓ failures
|
||||||
✓ failures with message
|
✓ failures with message
|
||||||
✓ failures with message and Any matcher
|
✓ failures with message and Any matcher
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Features\Expect\toHaveSameSize
|
||||||
|
✓ failures with wrong type
|
||||||
|
✓ pass
|
||||||
|
✓ failures
|
||||||
|
✓ failures with message
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Features\Expect\toHaveSnakeCaseKeys
|
PASS Tests\Features\Expect\toHaveSnakeCaseKeys
|
||||||
@ -1007,6 +1022,9 @@
|
|||||||
✓ uses dataset with (1)
|
✓ uses dataset with (1)
|
||||||
✓ uses dataset with (2)
|
✓ uses dataset with (2)
|
||||||
✓ the right dataset is taken
|
✓ the right dataset is taken
|
||||||
|
✓ it can see datasets defined in Pest.php file with ('A')
|
||||||
|
✓ it can see datasets defined in Pest.php file with ('B')
|
||||||
|
✓ Pest.php dataset is taken
|
||||||
|
|
||||||
WARN Tests\Features\Skip
|
WARN Tests\Features\Skip
|
||||||
✓ it do not skips
|
✓ it do not skips
|
||||||
@ -1296,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, 916 passed (2190 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,11 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Pest\Exceptions\InvalidExpectationValue;
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
test('pass', function () {
|
test('pass', function () {
|
||||||
expect([1, 2, 3])->toHaveCount(3);
|
expect([1, 2, 3])->toHaveCount(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('failures with invalid type', function () {
|
||||||
|
expect('foo')->toHaveCount(3);
|
||||||
|
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [countable|iterable]');
|
||||||
|
|
||||||
test('failures', function () {
|
test('failures', function () {
|
||||||
expect([1, 2, 3])->toHaveCount(4);
|
expect([1, 2, 3])->toHaveCount(4);
|
||||||
})->throws(ExpectationFailedException::class);
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|||||||
@ -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');
|
||||||
|
|||||||
24
tests/Features/Expect/toHaveSameSize.php
Normal file
24
tests/Features/Expect/toHaveSameSize.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Pest\Exceptions\InvalidExpectationValue;
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
test('failures with wrong type', function () {
|
||||||
|
expect('foo')->toHaveSameSize([1]);
|
||||||
|
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [countable|iterable].');
|
||||||
|
|
||||||
|
test('pass', function () {
|
||||||
|
expect([1, 2, 3])->toHaveSameSize([4, 5, 6]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('failures', function () {
|
||||||
|
expect([1, 2, 3])->toHaveSameSize([1]);
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
|
test('failures with message', function () {
|
||||||
|
expect([1, 2, 3])->toHaveSameSize([1], 'oh no!');
|
||||||
|
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||||
|
|
||||||
|
test('not failures', function () {
|
||||||
|
expect([1, 2, 3])->not->toHaveSameSize([1]);
|
||||||
|
});
|
||||||
@ -10,3 +10,12 @@ test('uses dataset', function ($value) use ($state) {
|
|||||||
test('the right dataset is taken', function () use ($state) {
|
test('the right dataset is taken', function () use ($state) {
|
||||||
expect($state->text)->toBe('12');
|
expect($state->text)->toBe('12');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can see datasets defined in Pest.php file', function (string $value) use ($state) {
|
||||||
|
$state->text .= $value;
|
||||||
|
expect(true)->toBe(true);
|
||||||
|
})->with('dataset_in_pest_file');
|
||||||
|
|
||||||
|
test('Pest.php dataset is taken', function () use ($state) {
|
||||||
|
expect($state->text)->toBe('12AB');
|
||||||
|
});
|
||||||
|
|||||||
@ -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
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -37,3 +37,5 @@ function helper_returns_string()
|
|||||||
{
|
{
|
||||||
return 'string';
|
return 'string';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dataset('dataset_in_pest_file', ['A', 'B']);
|
||||||
|
|||||||
@ -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, 905 passed (2175 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