Compare commits

...

12 Commits

Author SHA1 Message Date
47f2ae32c1 release: v2.13.0 2023-08-09 12:14:39 +01:00
306b7eb2a6 feat: adds ddWhen and ddUnless 2023-08-09 12:14:32 +01:00
02f72aabb2 Merge pull request #860 from devajmeireles/feature/add-dd-conditionally
Feature: Introducing The Ability to Dump Conditionally
2023-08-09 10:50:53 +00:00
e3a21384e6 release: v2.12.2 2023-08-07 10:29:25 +01:00
331381eed5 release: v2.12.1 2023-08-07 10:26:55 +01:00
75a7d77a80 Updates snapshots 2023-08-07 10:22:58 +01:00
cc242a50d1 chore: bump dependencies 2023-08-07 09:39:13 +01:00
704acbf6de Merge pull request #898 from dylanbr/allow_tests_to_be_extended
TestSuiteLoader will always consider classes from the current file
2023-08-06 22:59:52 +00:00
7baa48e068 TestSuiteLoader will always consider classes from the current file 2023-08-05 13:06:00 +02:00
b00bc4d5ea applying enhancement to use single dd function 2023-07-17 19:11:06 -03:00
8abc0d1920 applying enhancement to use ddWhen inside ddUnless 2023-07-17 14:12:54 -03:00
ea967b439f Feature: Introducing The Ability to Dump Conditionally 2023-07-17 11:08:00 -03:00
12 changed files with 111 additions and 8 deletions

View File

@ -2,6 +2,12 @@
## Unreleased
## [v2.12.2 (2023-08-07)](https://github.com/pestphp/pest/compare/v2.12.0...v2.12.2)
### Fixed
- Running tests from `uses` parent class ([#898](https://github.com/pestphp/pest/pull/898))
## [v2.12.0 (2023-08-02)](https://github.com/pestphp/pest/compare/v2.11.0...v2.12.0)
### Added

View File

@ -18,8 +18,8 @@
],
"require": {
"php": "^8.1.0",
"brianium/paratest": "^7.2.4",
"nunomaduro/collision": "^7.8.0",
"brianium/paratest": "^7.2.5",
"nunomaduro/collision": "^7.8.1",
"nunomaduro/termwind": "^1.15.1",
"pestphp/pest-plugin": "^2.0.1",
"pestphp/pest-plugin-arch": "^2.2.3",

View File

@ -60,6 +60,11 @@ final class TestSuiteLoader
*/
private static array $loadedClasses = [];
/**
* @psalm-var array<string, array<class-string>>
*/
private static array $loadedClassesByFilename = [];
/**
* @psalm-var list<class-string>
*/
@ -97,6 +102,17 @@ final class TestSuiteLoader
self::$loadedClasses = array_merge($loadedClasses, self::$loadedClasses);
foreach ($loadedClasses as $loadedClass) {
$reflection = new ReflectionClass($loadedClass);
$filename = $reflection->getFileName();
self::$loadedClassesByFilename[$filename] = [
$loadedClass,
...self::$loadedClassesByFilename[$filename] ?? [],
];
}
$loadedClasses = array_merge(self::$loadedClassesByFilename[$suiteClassFile] ?? [], $loadedClasses);
if (empty($loadedClasses)) {
return $this->exceptionFor($suiteClassName, $suiteClassFile);
}

View File

@ -127,6 +127,40 @@ final class Expectation
exit(1);
}
/**
* Dump the expectation value when the result of the condition is truthy.
*
* @param (\Closure(TValue): bool)|bool $condition
* @return self<TValue>
*/
public function ddWhen(Closure|bool $condition, mixed ...$arguments): Expectation
{
$condition = $condition instanceof Closure ? $condition($this->value) : $condition;
if (! $condition) {
return $this;
}
$this->dd(...$arguments);
}
/**
* Dump the expectation value when the result of the condition is falsy.
*
* @param (\Closure(TValue): bool)|bool $condition
* @return self<TValue>
*/
public function ddUnless(Closure|bool $condition, mixed ...$arguments): Expectation
{
$condition = $condition instanceof Closure ? $condition($this->value) : $condition;
if ($condition) {
return $this;
}
$this->dd(...$arguments);
}
/**
* Send the expectation value to Ray along with all given arguments.
*

View File

@ -6,7 +6,7 @@ namespace Pest;
function version(): string
{
return '2.12.0';
return '2.13.0';
}
function testDirectory(string $file = ''): string

View File

@ -1,5 +1,5 @@
Pest Testing Framework 2.12.0.
Pest Testing Framework 2.13.0.
USAGE: pest <file> [options]

View File

@ -1,3 +1,3 @@
Pest Testing Framework 2.12.0.
Pest Testing Framework 2.13.0.

View File

@ -1015,9 +1015,15 @@
PASS Tests\PHPUnit\CustomAffixes\snakecasespec
✓ it runs file names like snake_case_spec.php
PASS Tests\CustomTestCase\ChildTest
✓ override method
PASS Tests\CustomTestCase\ExecutedTest
✓ that gets executed
PASS Tests\CustomTestCase\ParentTest
✓ override method
PASS Tests\PHPUnit\CustomTestCase\UsesPerDirectory
✓ closure was bound to CustomTestCase
@ -1210,4 +1216,4 @@
WARN Tests\Visual\Version
- visual snapshot of help command output
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 860 passed (1975 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 862 passed (1977 assertions)

View File

@ -19,7 +19,13 @@
↓ something todo later chained
↓ something todo later chained and with function body
PASS Tests\CustomTestCase\ChildTest
✓ override method
PASS Tests\CustomTestCase\ExecutedTest
✓ that gets executed
Tests: 13 todos, 1 passed (1 assertions)
PASS Tests\CustomTestCase\ParentTest
✓ override method
Tests: 13 todos, 3 passed (3 assertions)

View File

@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace Tests\CustomTestCase;
class ChildTest extends ParentTest
{
private function getEntity(): bool
{
return true;
}
}

View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Tests\CustomTestCase;
use function PHPUnit\Framework\assertTrue;
use PHPUnit\Framework\TestCase;
class ParentTest extends TestCase
{
private function getEntity(): bool
{
return false;
}
/** @test */
public function testOverrideMethod(): void
{
assertTrue($this->getEntity() || true);
}
}

View File

@ -16,7 +16,7 @@ $run = function () {
test('parallel', function () use ($run) {
expect($run('--exclude-group=integration'))
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 849 passed (1960 assertions)')
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 851 passed (1962 assertions)')
->toContain('Parallel: 3 processes');
})->skipOnWindows();