From 8d11e4393c5020dd8ae0417e00a4f577d02e74b8 Mon Sep 17 00:00:00 2001 From: James Harris Date: Thu, 18 Sep 2014 09:46:01 +1000 Subject: [PATCH] Added tests for fluent-style returns. --- composer.lock | 14 ++++-------- src/PasswordGenerator.php | 18 ++++++++++----- src/PasswordGeneratorInterface.php | 4 ++++ test/suite/PasswordGeneratorTest.php | 33 ++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 16 deletions(-) diff --git a/composer.lock b/composer.lock index 1ca2930..803e930 100644 --- a/composer.lock +++ b/composer.lock @@ -104,7 +104,7 @@ { "name": "Ryan Chouinard", "email": "rchouinard@gmail.com", - "homepage": "http://ryanchouinard.com" + "homepage": "https://www.ryanchouinard.com" } ], "description": "Random data generator for PHP", @@ -1101,18 +1101,12 @@ "time": "2014-07-05 12:19:05" } ], - "aliases": [ - - ], + "aliases": [], "minimum-stability": "stable", - "stability-flags": [ - - ], + "stability-flags": [], "prefer-stable": false, "platform": { "php": ">=5.3" }, - "platform-dev": [ - - ] + "platform-dev": [] } diff --git a/src/PasswordGenerator.php b/src/PasswordGenerator.php index b80475e..f88d8fa 100644 --- a/src/PasswordGenerator.php +++ b/src/PasswordGenerator.php @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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; } diff --git a/src/PasswordGeneratorInterface.php b/src/PasswordGeneratorInterface.php index 6ca55f8..6f1971f 100644 --- a/src/PasswordGeneratorInterface.php +++ b/src/PasswordGeneratorInterface.php @@ -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); @@ -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); } diff --git a/test/suite/PasswordGeneratorTest.php b/test/suite/PasswordGeneratorTest.php index b3af8bb..39ac60b 100644 --- a/test/suite/PasswordGeneratorTest.php +++ b/test/suite/PasswordGeneratorTest.php @@ -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(