Skip to content

Commit

Permalink
Added tests for fluent-style returns.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Sep 17, 2014
1 parent 8c6171e commit 8d11e43
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 16 deletions.
14 changes: 4 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions src/PasswordGenerator.php
Expand Up @@ -32,11 +32,12 @@ public function minimumLength()
*
* @param integer $length The minimum length of generated passwords.
*
* @return PasswordGenerator
* @return PasswordGenerator This object.
*/
public function setMinimumLength($length)
{
$this->minimumLength = $length;

return $this;
}

Expand All @@ -55,11 +56,12 @@ public function maximumLength()
*
* @param integer $length The maximum length of generated passwords.
*
* @return PasswordGenerator
* @return PasswordGenerator This object.
*/
public function setMaximumLength($length)
{
$this->maximumLength = $length;

return $this;
}

Expand All @@ -79,12 +81,13 @@ public function allowUppercase()
*
* @param boolean $allow True if uppercase characters are allowed.
*
* @return PasswordGenerator
* @return PasswordGenerator This object.
*/
public function setAllowUppercase($allow)
{
$this->allowUppercase = $allow;
$this->characterSet = null;

return $this;
}

Expand All @@ -103,12 +106,13 @@ public function allowDigits()
*
* @param boolean $allow True if digits are allowed.
*
* @return PasswordGenerator
* @return PasswordGenerator This object.
*/
public function setAllowDigits($allow)
{
$this->allowDigits = $allow;
$this->characterSet = null;

return $this;
}

Expand All @@ -130,12 +134,13 @@ public function allowSymbols()
*
* @param boolean $allow True if symbols are allowed.
*
* @return PasswordGenerator
* @return PasswordGenerator This object.
*/
public function setAllowSymbols($allow)
{
$this->allowSymbols = $allow;
$this->characterSet = null;

return $this;
}

Expand All @@ -157,12 +162,13 @@ public function allowAmbiguousCharacters()
*
* @param boolean $allow True if ambiguous characters are allowed.
*
* @return PasswordGenerator
* @return PasswordGenerator This object.
*/
public function setAllowAmbiguousCharacters($allow)
{
$this->allowAmbiguousCharacters = $allow;
$this->characterSet = null;

return $this;
}

Expand Down
4 changes: 4 additions & 0 deletions src/PasswordGeneratorInterface.php
Expand Up @@ -24,6 +24,8 @@ public function minimumLength();
* Set the minimum length of generated passwords.
*
* @param integer $length The minimum length of generated passwords.
*
* @return PasswordGeneratorInterface This object.
*/
public function setMinimumLength($length);

Expand All @@ -38,6 +40,8 @@ public function maximumLength();
* Set the maximum length of generated passwords.
*
* @param integer $length The maximum length of generated passwords.
*
* @return PasswordGeneratorInterface This object.
*/
public function setMaximumLength($length);
}
33 changes: 33 additions & 0 deletions test/suite/PasswordGeneratorTest.php
Expand Up @@ -12,6 +12,39 @@ public function setUp()
$this->generator = new PasswordGenerator($this->random);
}

public function testMutatorsReturnThis()
{
$this->assertSame(
$this->generator,
$this->generator->setMinimumLength(10)
);

$this->assertSame(
$this->generator,
$this->generator->setMaximumLength(20)
);

$this->assertSame(
$this->generator,
$this->generator->setAllowUppercase(true)
);

$this->assertSame(
$this->generator,
$this->generator->setAllowDigits(true)
);

$this->assertSame(
$this->generator,
$this->generator->setAllowSymbols(true)
);

$this->assertSame(
$this->generator,
$this->generator->setAllowAmbiguousCharacters(true)
);
}

public function testDefaultCharacterSet()
{
$this->assertSame(
Expand Down

0 comments on commit 8d11e43

Please sign in to comment.