From 824631971b01862706db1876ccc57523f4e589dd Mon Sep 17 00:00:00 2001 From: Rougin Gutib Date: Sat, 16 Nov 2024 16:03:54 +0800 Subject: [PATCH] Add unit tests for "setUsernameField", "setPasswordField" --- src/Authsum.php | 8 ++------ tests/AuthsumTest.php | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Authsum.php b/src/Authsum.php index 3bee720..f0a6357 100644 --- a/src/Authsum.php +++ b/src/Authsum.php @@ -17,7 +17,7 @@ class Authsum /** * @var string */ - protected $password; + protected $password = 'password'; /** * @var array @@ -32,7 +32,7 @@ class Authsum /** * @var string */ - protected $username; + protected $username = 'email'; /** * @param \Rougin\Authsum\Source\SourceInterface $source @@ -40,10 +40,6 @@ class Authsum public function __construct(SourceInterface $source) { $this->source = $source; - - $this->setPasswordField('password'); - - $this->setUsernameField('email'); } /** diff --git a/tests/AuthsumTest.php b/tests/AuthsumTest.php index 35f650e..045dfb1 100644 --- a/tests/AuthsumTest.php +++ b/tests/AuthsumTest.php @@ -25,6 +25,28 @@ public function doSetUp() $this->source = new BasicSource('hello', 'olleh'); } + /** + * @return void + */ + public function test_change_payload_fields() + { + $expected = 'Credentials matched!'; + + $auth = new Authsum($this->source); + + $auth->setUsernameField('username'); + + $auth->setPasswordField('pass'); + + $payload = array('username' => 'hello', 'pass' => 'olleh'); + + $valid = $auth->isValid($payload); + + $actual = $auth->getResult()->getText(); + + $this->assertEquals($expected, $actual); + } + /** * @return void */