Skip to content

Commit

Permalink
Add unit tests for "setUsernameField", "setPasswordField"
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Nov 16, 2024
1 parent 643657d commit 8246319
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/Authsum.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Authsum
/**
* @var string
*/
protected $password;
protected $password = 'password';

/**
* @var array<string, string>
Expand All @@ -32,18 +32,14 @@ class Authsum
/**
* @var string
*/
protected $username;
protected $username = 'email';

/**
* @param \Rougin\Authsum\Source\SourceInterface $source
*/
public function __construct(SourceInterface $source)
{
$this->source = $source;

$this->setPasswordField('password');

$this->setUsernameField('email');
}

/**
Expand Down
22 changes: 22 additions & 0 deletions tests/AuthsumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 8246319

Please sign in to comment.