From 3a8099ae1fad5beaf6aaa9dea9db898d140c26d1 Mon Sep 17 00:00:00 2001 From: "Eric Richer eric.richer@vistoconsulting.com" Date: Mon, 16 Sep 2024 13:16:13 -0400 Subject: [PATCH] Moved tests to check that 'assertTemplateName' fails as intended when the template is not found and the 'assertNotTemplateName' fails when the template is found. to separate test cases. Signed-off-by: Eric Richer eric.richer@vistoconsulting.com --- .../AbstractControllerTestCaseTest.php | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php b/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php index 045466a..2495b66 100644 --- a/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php +++ b/test/PHPUnit/Controller/AbstractControllerTestCaseTest.php @@ -561,28 +561,36 @@ public function testSearchTemplatesVerifiesDeeplyNestedTemplateName(): void $this->assertTemplateName('child2'); $this->assertTemplateName('child3'); $this->assertNotTemplateName('foo'); + } + + /** + * Check that the assertion fails when template is NOT found where it was supposed to found + */ + public function testAssertTemplateNameFailsWhenNotFound(): void + { + $this->dispatch('/childview'); - // Check that the test fails when template is NOT found where it was supposed to found try { $this->assertTemplateName('foo'); - $receivedException = false; - } catch (Exception $exception) { - $receivedException = true; - } - if (! $receivedException) { - $this->fail('Expected Exception not thrown'); + } catch (ExpectationFailedException $exception) { + return; } + $this->fail('Expected Exception not thrown'); + } + + /** + * Check that the assertion fails when template is found where it was NOT supposed to found + */ + public function testAssertNotTemplateNameFailsWhenFound(): void + { + $this->dispatch('/childview'); - // Check when template is found where it was NOT supposed to found try { $this->assertNotTemplateName('child1'); - $receivedException = false; - } catch (Exception $exception) { - $receivedException = true; - } - if (! $receivedException) { - $this->fail('Expected Exception not thrown'); + } catch (ExpectationFailedException $exception) { + return; } + $this->fail('Expected Exception not thrown'); } public function testCustomResponseObject(): void