summaryrefslogtreecommitdiffstats
path: root/Core/Tests/Exception/CustomUserMessageAuthenticationExceptionTest.php
diff options
context:
space:
mode:
authorFabien Potencier <fabien.potencier@gmail.com>2015-09-28 09:00:41 +0200
committerFabien Potencier <fabien.potencier@gmail.com>2015-09-28 09:00:41 +0200
commit8ba7579a2fe5b384f10c20427e08bade4baf980d (patch)
tree7bd1b832fe6c43c1d5d0fbc47759957a45f3cd4b /Core/Tests/Exception/CustomUserMessageAuthenticationExceptionTest.php
parent9b36490e86af00e50a5124cbdb63e57450235afa (diff)
parent1a66cae1aaed170da367d81c9fdc1f83cf6c3018 (diff)
downloadsymfony-security-8ba7579a2fe5b384f10c20427e08bade4baf980d.zip
symfony-security-8ba7579a2fe5b384f10c20427e08bade4baf980d.tar.gz
symfony-security-8ba7579a2fe5b384f10c20427e08bade4baf980d.tar.bz2
feature #15882 Easier Custom Authentication errors (weaverryan)
This PR was merged into the 2.8 branch. Discussion ---------- Easier Custom Authentication errors | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | not yet This makes failing authentication with a custom message much easier: ```php throw CustomAuthenticationException::createWithSafeMessage( 'That was a ridiculous username' ); // or $e = new CustomAuthenticationException(); $e->setSafeMessage('That was a ridiculous username'); throw $e; ``` Currently, to do this, you'd need to create a new sub-class of `AuthenticationException`, which is way more work than it needs to be. The original design was so that all messages exposed are safe, which is why I've named the methods like I have. Thanks! Commits ------- d7c1463 Adding a class to make it easier to set custom authentication error messages
Diffstat (limited to 'Core/Tests/Exception/CustomUserMessageAuthenticationExceptionTest.php')
-rw-r--r--Core/Tests/Exception/CustomUserMessageAuthenticationExceptionTest.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/Core/Tests/Exception/CustomUserMessageAuthenticationExceptionTest.php b/Core/Tests/Exception/CustomUserMessageAuthenticationExceptionTest.php
new file mode 100644
index 0000000..408dd2a
--- /dev/null
+++ b/Core/Tests/Exception/CustomUserMessageAuthenticationExceptionTest.php
@@ -0,0 +1,26 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Security\Core\Tests\Exception;
+
+use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
+
+class CustomUserMessageAuthenticationExceptionTest extends \PHPUnit_Framework_TestCase
+{
+ public function testConstructWithSAfeMessage()
+ {
+ $e = new CustomUserMessageAuthenticationException('SAFE MESSAGE', array('foo' => true));
+
+ $this->assertEquals('SAFE MESSAGE', $e->getMessageKey());
+ $this->assertEquals(array('foo' => true), $e->getMessageData());
+ $this->assertEquals('SAFE MESSAGE', $e->getMessage());
+ }
+}