chore: adjusts tests

This commit is contained in:
Nuno Maduro
2024-06-27 01:41:34 +01:00
parent 5c3bf469d5
commit 474b9b7e17
10 changed files with 41 additions and 14 deletions

View File

@ -19,7 +19,7 @@
"require": { "require": {
"php": "^8.2.0", "php": "^8.2.0",
"brianium/paratest": "^7.5.0", "brianium/paratest": "^7.5.0",
"nunomaduro/collision": "^8.1.1", "nunomaduro/collision": "8.x-dev",
"nunomaduro/termwind": "^2.0.1", "nunomaduro/termwind": "^2.0.1",
"pestphp/pest-plugin": "^3.0.0", "pestphp/pest-plugin": "^3.0.0",
"pestphp/pest-plugin-arch": "^3.0.0", "pestphp/pest-plugin-arch": "^3.0.0",

View File

@ -613,8 +613,6 @@ final class Expectation
/** /**
* Asserts that the given expectation target to use the given trait. * Asserts that the given expectation target to use the given trait.
*
* @param string $trait
*/ */
public function toUseTrait(string $trait): ArchExpectation public function toUseTrait(string $trait): ArchExpectation
{ {
@ -703,8 +701,6 @@ final class Expectation
); );
} }
/** /**
* Asserts that the given expectation target to implement the given interfaces. * Asserts that the given expectation target to implement the given interfaces.
* *

View File

@ -254,8 +254,6 @@ final class OppositeExpectation
/** /**
* Asserts that the given expectation target not to use the given trait. * Asserts that the given expectation target not to use the given trait.
*
* @param string $trait
*/ */
public function toUseTrait(string $trait): ArchExpectation public function toUseTrait(string $trait): ArchExpectation
{ {
@ -282,8 +280,8 @@ final class OppositeExpectation
return true; return true;
}, },
"not to use traits '" . implode("', '", $traits) . "'", "not to use traits '".implode("', '", $traits)."'",
FileLineFinder::where(fn(string $line): bool => str_contains($line, 'class')), FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')),
); );
} }

View File

@ -31,7 +31,7 @@ final class ExceptionTrace
$message = str_replace(self::UNDEFINED_METHOD, 'Call to undefined method ', $message); $message = str_replace(self::UNDEFINED_METHOD, 'Call to undefined method ', $message);
if (class_exists((string) $class) && (is_countable(class_parents($class)) ? count(class_parents($class)) : 0) > 0 && array_values(class_parents($class))[0] === TestCase::class) { // @phpstan-ignore-line if (class_exists((string) $class) && (is_countable(class_parents($class)) ? count(class_parents($class)) : 0) > 0 && array_values(class_parents($class))[0] === TestCase::class) { // @phpstan-ignore-line
$message .= '. Did you forget to use the [pest()->uses()] function? Read more at: https://pestphp.com/docs/configuring-tests'; $message .= '. Did you forget to use the [pest()->extend()] function? Read more at: https://pestphp.com/docs/configuring-tests';
} }
Reflection::setPropertyValue($throwable, 'message', $message); Reflection::setPropertyValue($throwable, 'message', $message);

View File

@ -11,6 +11,6 @@ final class NotesTestCaseFilter implements TestCaseMethodFilter
{ {
public function accept(TestCaseMethodFactory $factory): bool public function accept(TestCaseMethodFactory $factory): bool
{ {
return count($factory->notes) > 0; return $factory->notes !== [];
} }
} }

View File

@ -21,6 +21,7 @@
SELECTION OPTIONS: SELECTION OPTIONS:
--bail ........................... Stop execution upon first not-passed test --bail ........................... Stop execution upon first not-passed test
--todos ........................ Output to standard output the list of todos --todos ........................ Output to standard output the list of todos
--notes ......................... Output to standard output tests with notes
--retry Run non-passing tests first and stop execution upon first error or failure --retry Run non-passing tests first and stop execution upon first error or failure
--list-suites ................................... List available test suites --list-suites ................................... List available test suites
--testsuite [name] ......... Only run tests from the specified test suite(s) --testsuite [name] ......... Only run tests from the specified test suite(s)

View File

@ -928,6 +928,11 @@
✓ it can handle a non-defined exception ✓ it can handle a non-defined exception
✓ it can handle a class not found Error ✓ it can handle a class not found Error
PASS Tests\Features\Expect\toUseTrait
✓ pass
✓ failures
✓ not failures
PASS Tests\Features\Expect\unless PASS Tests\Features\Expect\unless
✓ it pass ✓ it pass
✓ it failures ✓ it failures
@ -992,6 +997,31 @@
✓ a "describe" group of tests → it is a test ✓ a "describe" group of tests → it is a test
✓ a "describe" group of tests → it is a higher order message test ✓ a "describe" group of tests → it is a higher order message test
PASS Tests\Features\Note
✓ it may have a static note
// This is before each static note
// This is a note
// This is before each runtime note
✓ it may have a runtime note
// This is before each static note
// This is before each runtime note
// This is a runtime note
✓ it may have static note and runtime note
// This is before each static note
// This is a static note
// This is before each runtime note
// This is a runtime note
✓ nested → it may have static note and runtime note
// This is describe static note
// This is a static note within describe
// This is before each runtime note
// This is a runtime note within describe
✓ multiple notes
// This is before each static note
// This is before each runtime note
// This is a runtime note
// This is another runtime note
NOTI Tests\Features\Notices NOTI Tests\Features\Notices
! notice → This is a notice description // tests/Features/Notices.php:4 ! notice → This is a notice description // tests/Features/Notices.php:4
! a "describe" group of tests → notice → This is a notice description // tests/Features/Notices.php:11 ! a "describe" group of tests → notice → This is a notice description // tests/Features/Notices.php:11
@ -1470,4 +1500,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, 24 skipped, 1049 passed (2577 assertions) Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 24 skipped, 1057 passed (2588 assertions, 18 notes)

View File

@ -29,6 +29,8 @@ describe('nested', function () {
})->note('This is describe static note'); })->note('This is describe static note');
test('multiple notes', function () { test('multiple notes', function () {
expect(true)->toBeTrue(true);
$this->note([ $this->note([
'This is a runtime note', 'This is a runtime note',
'This is another runtime note', 'This is another runtime note',

View File

@ -17,5 +17,5 @@ it('ensures the given closures reports the correct class name and suggests the [
$this->get(); $this->get();
})->throws( })->throws(
Error::class, Error::class,
'Call to undefined method Tests\Unit\Support\ExceptionTrace::get(). Did you forget to use the [uses()] function? Read more at: https://pestphp.com/docs/configuring-tests', 'Call to undefined method Tests\Unit\Support\ExceptionTrace::get(). Did you forget to use the [pest()->extend()] function? Read more at: https://pestphp.com/docs/configuring-tests',
); );

View File

@ -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: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 1035 passed (2545 assertions)') ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 1043 passed (2556 assertions)')
->toContain('Parallel: 3 processes'); ->toContain('Parallel: 3 processes');
})->skipOnWindows(); })->skipOnWindows();