From f3d2a8143a1345c31011617461ca326d73391b28 Mon Sep 17 00:00:00 2001 From: Katie Smith <108671517+ktsm-th@users.noreply.github.com> Date: Fri, 31 Jan 2025 16:22:20 +0000 Subject: [PATCH 1/3] add assertCount() --- src/Concerns/MakesAssertions.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Concerns/MakesAssertions.php b/src/Concerns/MakesAssertions.php index 0ca2ff633..1fd369084 100644 --- a/src/Concerns/MakesAssertions.php +++ b/src/Concerns/MakesAssertions.php @@ -249,6 +249,26 @@ public function assertSeeNothingIn($selector) return $this; } + /** + * Assert that a given element is present a given amount of times. + * + * @param string $selector + * @param int $expected + * @return $this + */ + public function assertCount($selector, $expected) + { + $fullSelector = $this->resolver->format($selector); + + PHPUnit::assertCount( + $expected, + $this->resolver->all($selector), + "Expected element [{$fullSelector}] exactly {$expected} times." + ); + + return $this; + } + /** * Assert that the given JavaScript expression evaluates to the given value. * From 54bb3adf0a255793527ebfa5b66274b81170617a Mon Sep 17 00:00:00 2001 From: Katie Smith <108671517+ktsm-th@users.noreply.github.com> Date: Fri, 31 Jan 2025 16:22:24 +0000 Subject: [PATCH 2/3] Update MakesAssertionsTest.php --- tests/Unit/MakesAssertionsTest.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/Unit/MakesAssertionsTest.php b/tests/Unit/MakesAssertionsTest.php index ebea4026a..22ba7b44d 100644 --- a/tests/Unit/MakesAssertionsTest.php +++ b/tests/Unit/MakesAssertionsTest.php @@ -1257,6 +1257,32 @@ public function test_assert_vue_contains_with_no_result() } } + public function test_assert_count() + { + $driver = m::mock(stdClass::class); + + $element1 = m::mock(RemoteWebElement::class); + $element2 = m::mock(RemoteWebElement::class); + + $resolver = m::mock(stdClass::class); + $resolver->shouldReceive('format')->with('foo')->andReturn('body foo'); + $resolver->shouldReceive('all')->with('foo')->andReturn([$element1, $element2]); + + $browser = new Browser($driver, $resolver); + + $browser->assertCount('foo', 2); + + try { + $browser->assertCount('foo', 3); + $this->fail(); + } catch (ExpectationFailedException $e) { + $this->assertStringContainsString( + 'Expected element [body foo] exactly 3 times.', + $e->getMessage() + ); + } + } + public function test_assert_script() { $driver = m::mock(stdClass::class); From 9aa3cb74ed37e7459dcb5321dcee8068b4b0fcdb Mon Sep 17 00:00:00 2001 From: Katie Smith <108671517+ktsm-th@users.noreply.github.com> Date: Fri, 31 Jan 2025 16:36:56 +0000 Subject: [PATCH 3/3] style ci --- src/Concerns/MakesAssertions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Concerns/MakesAssertions.php b/src/Concerns/MakesAssertions.php index 1fd369084..cb520653b 100644 --- a/src/Concerns/MakesAssertions.php +++ b/src/Concerns/MakesAssertions.php @@ -252,8 +252,8 @@ public function assertSeeNothingIn($selector) /** * Assert that a given element is present a given amount of times. * - * @param string $selector - * @param int $expected + * @param string $selector + * @param int $expected * @return $this */ public function assertCount($selector, $expected)