From 2e411893d2e8808139e0ea4f83fb157fb636de65 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 18 Jul 2024 20:43:39 +0100 Subject: [PATCH] feat: adds `toHaveLineCountLessThan` --- src/Expectation.php | 13 +++++++++++++ src/Expectations/OppositeExpectation.php | 8 ++++++++ tests/.snapshots/success.txt | 6 +++++- tests/Features/Expect/toHaveLineCountLessThan.php | 12 ++++++++++++ tests/Visual/Parallel.php | 2 +- 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/Features/Expect/toHaveLineCountLessThan.php diff --git a/src/Expectation.php b/src/Expectation.php index ce108428..55fa626e 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -447,6 +447,19 @@ final class Expectation ); } + /** + * Asserts that the given expectation target to have line count less than the given number. + */ + public function toHaveLineCountLessThan(int $lines): ArchExpectation + { + return Targeted::make( + $this, + fn (ObjectDescription $object): bool => count(file($object->path)) < $lines, + sprintf('to have less than %d lines of code', $lines), + FileLineFinder::where(fn (string $line): bool => str_contains($line, 'toHaveLineCountLessThan(1000); +}); + +it('fails', function () { + expect(Expectation::class)->toHaveLineCountLessThan(10); +})->throws(ArchExpectationFailedException::class); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index f29178c0..222eba3c 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, 13 todos, 19 skipped, 1052 passed (2579 assertions)') + ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 1054 passed (2582 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows();