From adf9efffbce2768aaf966de46d6cc27c9b6d34fa Mon Sep 17 00:00:00 2001 From: Alice Williams <25745335+AliceKLWilliams@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:51:18 +0000 Subject: [PATCH] Use expect exception --- tests/Unit/PostQueryBuilderTest.php | 10 ++-------- tests/Unit/ScopedQueryBuilderTest.php | 12 +++--------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/tests/Unit/PostQueryBuilderTest.php b/tests/Unit/PostQueryBuilderTest.php index 8cb501d..46e2d68 100644 --- a/tests/Unit/PostQueryBuilderTest.php +++ b/tests/Unit/PostQueryBuilderTest.php @@ -51,15 +51,9 @@ public function can_create_a_builder_from_static_functions() */ public function throw_error_on_missing_static_function() { - $errorThrown = false; + $this->expectException(Throwable::class); - try { - Post::missingStaticFunction(); - } catch (Throwable $e) { - $errorThrown = true; - } - - $this->assertTrue($errorThrown); + Post::missingStaticFunction(); } private function assertQueryBuilder($function, $params, $postType) diff --git a/tests/Unit/ScopedQueryBuilderTest.php b/tests/Unit/ScopedQueryBuilderTest.php index 655231f..012ce62 100644 --- a/tests/Unit/ScopedQueryBuilderTest.php +++ b/tests/Unit/ScopedQueryBuilderTest.php @@ -115,16 +115,10 @@ public function can_pass_params_into_a_query_scope_on_post_object() */ public function missing_query_scope_throws_an_error() { - $errorThrown = false; + $this->expectException(Throwable::class); - try { - $builder = new ScopedQueryBuilder(PostWithQueryScope::class); - $builder->nonExistentScope(); - } catch (Throwable $e) { - $errorThrown = true; - } - - $this->assertTrue($errorThrown); + $builder = new ScopedQueryBuilder(PostWithQueryScope::class); + $builder->nonExistentScope(); } /** @test */