From 5ae5ac9a54112358e96cdbd8250af4d37d8363ab Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 28 Aug 2024 16:30:29 -0500 Subject: [PATCH] fix: removes both `toHaveMethod` and `toHaveMethods` --- src/Mixins/Expectation.php | 30 -------------- src/Support/HigherOrderCallables.php | 10 ----- .../snapshots/Visual/Todo/todo.snap} | 8 ++-- .../Visual/Todo/todo_in_parallel.snap} | 8 ++-- tests/.pest/snapshots/Visual/Todo/todos.snap | 39 +++++++++++++++++++ .../Visual/Todo/todos_in_parallel.snap | 39 +++++++++++++++++++ tests/.snapshots/success.txt | 20 +++------- tests/Features/Expect/toHaveMethods.php | 26 ------------- tests/Features/HigherOrderTests.php | 14 ------- tests/Visual/Parallel.php | 2 +- tests/Visual/Todo.php | 30 ++++++-------- 11 files changed, 106 insertions(+), 120 deletions(-) rename tests/{.snapshots/todo.txt => .pest/snapshots/Visual/Todo/todo.snap} (75%) rename tests/{.snapshots/todos.txt => .pest/snapshots/Visual/Todo/todo_in_parallel.snap} (75%) create mode 100644 tests/.pest/snapshots/Visual/Todo/todos.snap create mode 100644 tests/.pest/snapshots/Visual/Todo/todos_in_parallel.snap delete mode 100644 tests/Features/Expect/toHaveMethods.php diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index e61751cc..f802bc11 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -344,36 +344,6 @@ final class Expectation return $this; } - /** - * Asserts that the value has the method $name. - * - * @return self - */ - public function toHaveMethod(string $name, string $message = ''): self - { - $this->toBeObject(); - - // @phpstan-ignore-next-line - Assert::assertTrue(method_exists($this->value, $name), $message); - - return $this; - } - - /** - * Asserts that the value has the provided methods $names. - * - * @param iterable $names - * @return self - */ - public function toHaveMethods(iterable $names, string $message = ''): self - { - foreach ($names as $name) { - $this->toHaveMethod($name, message: $message); - } - - return $this; - } - /** * Asserts that two variables have the same value. * diff --git a/src/Support/HigherOrderCallables.php b/src/Support/HigherOrderCallables.php index d47a0295..b728551d 100644 --- a/src/Support/HigherOrderCallables.php +++ b/src/Support/HigherOrderCallables.php @@ -49,16 +49,6 @@ final class HigherOrderCallables return $this->expect($value); } - /** - * Execute the given callable after the test has executed the setup method. - * - * @deprecated This method is deprecated. Please use `defer` instead. - */ - public function tap(callable $callable): object - { - return $this->defer($callable); - } - /** * Execute the given callable after the test has executed the setup method. */ diff --git a/tests/.snapshots/todo.txt b/tests/.pest/snapshots/Visual/Todo/todo.snap similarity index 75% rename from tests/.snapshots/todo.txt rename to tests/.pest/snapshots/Visual/Todo/todo.snap index 25f6eeb9..6b944036 100644 --- a/tests/.snapshots/todo.txt +++ b/tests/.pest/snapshots/Visual/Todo/todo.snap @@ -19,9 +19,9 @@ ↓ something todo later ↓ something todo later chained ↓ something todo later chained and with function body - ↓ it may have an associated assignee [@nunomaduro] - ↓ it may have an associated issue #1 - ↓ it may have an associated PR #1 + ↓ it may have an associated assignee []8;;https://github.com/nunomaduro\@nunomaduro]8;;\] + ↓ it may have an associated issue ]8;;https://github.com/pestphp/pest/issues/1\#1]8;;\ + ↓ it may have an associated PR ]8;;https://github.com/pestphp/pest/pull/1\#1]8;;\ ↓ it may have an associated note // a note @@ -35,3 +35,5 @@ ✓ override method Tests: 17 todos, 3 passed (3 assertions) + Duration: x.xxs + diff --git a/tests/.snapshots/todos.txt b/tests/.pest/snapshots/Visual/Todo/todo_in_parallel.snap similarity index 75% rename from tests/.snapshots/todos.txt rename to tests/.pest/snapshots/Visual/Todo/todo_in_parallel.snap index 25f6eeb9..6b944036 100644 --- a/tests/.snapshots/todos.txt +++ b/tests/.pest/snapshots/Visual/Todo/todo_in_parallel.snap @@ -19,9 +19,9 @@ ↓ something todo later ↓ something todo later chained ↓ something todo later chained and with function body - ↓ it may have an associated assignee [@nunomaduro] - ↓ it may have an associated issue #1 - ↓ it may have an associated PR #1 + ↓ it may have an associated assignee []8;;https://github.com/nunomaduro\@nunomaduro]8;;\] + ↓ it may have an associated issue ]8;;https://github.com/pestphp/pest/issues/1\#1]8;;\ + ↓ it may have an associated PR ]8;;https://github.com/pestphp/pest/pull/1\#1]8;;\ ↓ it may have an associated note // a note @@ -35,3 +35,5 @@ ✓ override method Tests: 17 todos, 3 passed (3 assertions) + Duration: x.xxs + diff --git a/tests/.pest/snapshots/Visual/Todo/todos.snap b/tests/.pest/snapshots/Visual/Todo/todos.snap new file mode 100644 index 00000000..6b944036 --- /dev/null +++ b/tests/.pest/snapshots/Visual/Todo/todos.snap @@ -0,0 +1,39 @@ + + TODO Tests\Features\BeforeEachProxiesToTestCallWithTodo - 4 todos + ↓ is marked as todo 1 + ↓ is marked as todo 2 + ↓ is marked as todo 3 + ↓ shouldBeMarkedAsTodo + + TODO Tests\Features\DatasetsTests - 1 todo + ↓ forbids to define tests in Datasets dirs and Datasets.php files + + TODO Tests\Features\Describe - 5 todos + ↓ todo + ↓ todo on hook → should not fail + ↓ todo on hook → should run + ↓ todo on describe → should not fail + ↓ todo on describe → should run + + TODO Tests\Features\Todo - 7 todos + ↓ something todo later + ↓ something todo later chained + ↓ something todo later chained and with function body + ↓ it may have an associated assignee []8;;https://github.com/nunomaduro\@nunomaduro]8;;\] + ↓ it may have an associated issue ]8;;https://github.com/pestphp/pest/issues/1\#1]8;;\ + ↓ it may have an associated PR ]8;;https://github.com/pestphp/pest/pull/1\#1]8;;\ + ↓ it may have an associated note + // a note + + PASS Tests\CustomTestCase\ChildTest + ✓ override method + + PASS Tests\CustomTestCase\ExecutedTest + ✓ that gets executed + + PASS Tests\CustomTestCase\ParentTest + ✓ override method + + Tests: 17 todos, 3 passed (3 assertions) + Duration: x.xxs + diff --git a/tests/.pest/snapshots/Visual/Todo/todos_in_parallel.snap b/tests/.pest/snapshots/Visual/Todo/todos_in_parallel.snap new file mode 100644 index 00000000..6b944036 --- /dev/null +++ b/tests/.pest/snapshots/Visual/Todo/todos_in_parallel.snap @@ -0,0 +1,39 @@ + + TODO Tests\Features\BeforeEachProxiesToTestCallWithTodo - 4 todos + ↓ is marked as todo 1 + ↓ is marked as todo 2 + ↓ is marked as todo 3 + ↓ shouldBeMarkedAsTodo + + TODO Tests\Features\DatasetsTests - 1 todo + ↓ forbids to define tests in Datasets dirs and Datasets.php files + + TODO Tests\Features\Describe - 5 todos + ↓ todo + ↓ todo on hook → should not fail + ↓ todo on hook → should run + ↓ todo on describe → should not fail + ↓ todo on describe → should run + + TODO Tests\Features\Todo - 7 todos + ↓ something todo later + ↓ something todo later chained + ↓ something todo later chained and with function body + ↓ it may have an associated assignee []8;;https://github.com/nunomaduro\@nunomaduro]8;;\] + ↓ it may have an associated issue ]8;;https://github.com/pestphp/pest/issues/1\#1]8;;\ + ↓ it may have an associated PR ]8;;https://github.com/pestphp/pest/pull/1\#1]8;;\ + ↓ it may have an associated note + // a note + + PASS Tests\CustomTestCase\ChildTest + ✓ override method + + PASS Tests\CustomTestCase\ExecutedTest + ✓ that gets executed + + PASS Tests\CustomTestCase\ParentTest + ✓ override method + + Tests: 17 todos, 3 passed (3 assertions) + Duration: x.xxs + diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 41a47c00..6db9b207 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -821,12 +821,6 @@ ✓ failure when the class has no method ✓ class has no method - PASS Tests\Features\Expect\toHaveMethods - ✓ pass - ✓ failures - ✓ failures with custom message - ✓ not failures - PASS Tests\Features\Expect\toHaveMethodsDocumented ✓ it passes ✓ it fails 1 @@ -1017,10 +1011,8 @@ ✓ it resolves expect callables correctly ✓ does not treat method names as callables ✓ it can defer a method until after test setup - ✓ it can tap a method until after test setup ✓ it can pass datasets into the expect callables with (1, 2, 3) ✓ it can pass datasets into the defer callable with (1, 2, 3) - ✓ it can pass datasets into the tap callable with (1, 2, 3) ✓ it can pass shared datasets into callables with (1) ✓ it can pass shared datasets into callables with (2) @@ -1558,13 +1550,13 @@ - visual snapshot of team city with ('Failure.php') - visual snapshot of team city with ('SuccessOnly.php') - PASS Tests\Visual\Todo - ✓ todos - ✓ todos in parallel - ✓ todo - ✓ todo in parallel + WARN Tests\Visual\Todo + … todos → Snapshot created at [tests/.pest/snapshots/Visual/Todo/todos.snap] + … todos in parallel → Snapshot created at [tests/.pest/snapshots/Visual/Todo/todos_in_parallel.snap] + … todo → Snapshot created at [tests/.pest/snapshots/Visual/Todo/todo.snap] + … todo in parallel → Snapshot created at [tests/.pest/snapshots/Visual/Todo/todo_in_parallel.snap] WARN Tests\Visual\Version - visual snapshot of help command output - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 24 skipped, 1089 passed (2650 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 9 incomplete, 2 notices, 17 todos, 24 skipped, 1079 passed (2613 assertions) \ No newline at end of file diff --git a/tests/Features/Expect/toHaveMethods.php b/tests/Features/Expect/toHaveMethods.php deleted file mode 100644 index 06c11006..00000000 --- a/tests/Features/Expect/toHaveMethods.php +++ /dev/null @@ -1,26 +0,0 @@ -toHaveMethods(['foo', 'bar']); -}); - -test('failures', function () use ($object) { - expect($object)->toHaveMethods(['foo', 'bar', 'baz']); -})->throws(ExpectationFailedException::class); - -test('failures with custom message', function () use ($object) { - expect($object)->toHaveMethods(['foo', 'bar', 'baz'], 'oh no!'); -})->throws(ExpectationFailedException::class, 'oh no!'); - -test('not failures', function () use ($object) { - expect($object)->not->toHaveMethods(['foo', 'bar']); -})->throws(ExpectationFailedException::class); diff --git a/tests/Features/HigherOrderTests.php b/tests/Features/HigherOrderTests.php index f3058fcc..a1bef96d 100644 --- a/tests/Features/HigherOrderTests.php +++ b/tests/Features/HigherOrderTests.php @@ -31,14 +31,6 @@ it('can defer a method until after test setup') ->toBe('foo') ->and('hello world')->toBeString(); -it('can tap a method until after test setup') - ->expect('foo')->toBeString() - ->tap(function () { - expect($this)->toBeInstanceOf(TestCase::class); - }) - ->toBe('foo') - ->and('hello world')->toBeString(); - it('can pass datasets into the expect callables') ->with([[1, 2, 3]]) ->expect(function (...$numbers) { @@ -54,12 +46,6 @@ it('can pass datasets into the defer callable') expect($numbers)->toBe([1, 2, 3]); }); -it('can pass datasets into the tap callable') - ->with([[1, 2, 3]]) - ->tap(function (...$numbers) { - expect($numbers)->toBe([1, 2, 3]); - }); - it('can pass shared datasets into callables') ->with('numbers.closure.wrapped') ->expect(function ($value) { diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 3d6e12f3..22b244db 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -16,7 +16,7 @@ $run = function () { test('parallel', function () use ($run) { expect($run('--exclude-group=integration')) - ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 19 skipped, 1075 passed (2618 assertions)') + ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 19 skipped, 1069 passed (2585 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows(); diff --git a/tests/Visual/Todo.php b/tests/Visual/Todo.php index 681fd09f..945291ef 100644 --- a/tests/Visual/Todo.php +++ b/tests/Visual/Todo.php @@ -11,31 +11,23 @@ $run = function (string $target, bool $parallel) { expect($process->getExitCode())->toBe(0); - return removeAnsiEscapeSequences($process->getOutput()); + $output = $process->getOutput(); + + return preg_replace('/Duration: \d+\.\d+s/', 'Duration: x.xxs', removeAnsiEscapeSequences($output)); }; -$snapshot = function ($name) { - $testsPath = dirname(__DIR__); - - return file_get_contents(implode(DIRECTORY_SEPARATOR, [ - $testsPath, - '.snapshots', - "$name.txt", - ])); -}; - -test('todos', function () use ($run, $snapshot) { - expect($run('--todos', false))->toContain($snapshot('todos')); +test('todos', function () use ($run) { + expect($run('--todos', false))->toMatchSnapshot(); })->skipOnWindows(); -test('todos in parallel', function () use ($run, $snapshot) { - expect($run('--todos', true))->toContain($snapshot('todos')); +test('todos in parallel', function () use ($run) { + expect($run('--todos', true))->toMatchSnapshot(); })->skipOnWindows(); -test('todo', function () use ($run, $snapshot) { - expect($run('--todo', false))->toContain($snapshot('todo')); +test('todo', function () use ($run) { + expect($run('--todo', false))->toMatchSnapshot(); })->skipOnWindows(); -test('todo in parallel', function () use ($run, $snapshot) { - expect($run('--todo', true))->toContain($snapshot('todo')); +test('todo in parallel', function () use ($run) { + expect($run('--todo', true))->toMatchSnapshot(); })->skipOnWindows();