From 9ed3a255a71d689875bc0562cda6112f56845b71 Mon Sep 17 00:00:00 2001 From: Francois Zaninotto Date: Sat, 15 Oct 2011 13:29:33 +0200 Subject: [PATCH] Fix unit tests after previous refactoring --- test/GeneratorTest.php | 62 ++-------------------- test/Provider/BaseTest.php | 103 +++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 59 deletions(-) create mode 100644 test/Provider/BaseTest.php diff --git a/test/GeneratorTest.php b/test/GeneratorTest.php index 350d5ffb..e4c62b1e 100644 --- a/test/GeneratorTest.php +++ b/test/GeneratorTest.php @@ -1,10 +1,12 @@ addProvider($provider); $this->assertEquals('bazfoo', $generator->format('fooFormatterWithArguments', array('foo'))); } - - public function testRandomDigitReturnsInteger() - { - $this->assertTrue(is_integer(Generator::randomDigit())); - } - - public function testRandomDigitReturnsDigit() - { - $this->assertTrue(Generator::randomDigit() >= 0); - $this->assertTrue(Generator::randomDigit() < 10); - } - - public function testRandomLetterReturnsString() - { - $this->assertTrue(is_string(Generator::randomLetter())); - } - - public function testRandomLetterReturnsSingleLetter() - { - $this->assertEquals(1, strlen(Generator::randomLetter())); - } - - public function testRandomLetterReturnsLowercaseLetter() - { - $lowercaseLetters = 'abcdefghijklmnopqrstuvwxyz'; - $this->assertTrue(strpos($lowercaseLetters, Generator::randomLetter()) !== false); - } - - public function testRandomElementReturnsElementFromArray() - { - $elements = array('23', 'e', 32, '#'); - $this->assertContains(Generator::randomElement($elements), $elements); - } - - public function testNumerifyReturnsSameStringWhenItContainsNoHashSign() - { - $this->assertEquals('fooBar?', Generator::numerify('fooBar?')); - } - - public function testNumerifyReturnsStringWithHashSignsReplacedByDigits() - { - $this->assertRegExp('/foo\dBa\dr/', Generator::numerify('foo#Ba#r')); - } - - public function testLexifyReturnsSameStringWhenItContainsNoQuestionMark() - { - $this->assertEquals('fooBar#', Generator::lexify('fooBar#')); - } - - public function testNumerifyReturnsStringWithQuestionMarksReplacedByLetters() - { - $this->assertRegExp('/foo[a-z]Ba[a-z]r/', Generator::lexify('foo?Ba?r')); - } - - public function testBothifyCombinesNumerifyAndLexify() - { - $this->assertRegExp('/foo[a-z]Ba\dr/', Generator::bothify('foo?Ba#r')); - } public function testParseReturnsSameStringWhenItContainsNoCurlyBraces() { diff --git a/test/Provider/BaseTest.php b/test/Provider/BaseTest.php new file mode 100644 index 00000000..46e1c97b --- /dev/null +++ b/test/Provider/BaseTest.php @@ -0,0 +1,103 @@ +assertTrue(is_integer(TestProvider::randomDigit())); + } + + public function testRandomDigitReturnsDigit() + { + $this->assertTrue(TestProvider::randomDigit() >= 0); + $this->assertTrue(TestProvider::randomDigit() < 10); + } + + public function testRandomLetterReturnsString() + { + $this->assertTrue(is_string(TestProvider::randomLetter())); + } + + public function testRandomLetterReturnsSingleLetter() + { + $this->assertEquals(1, strlen(TestProvider::randomLetter())); + } + + public function testRandomLetterReturnsLowercaseLetter() + { + $lowercaseLetters = 'abcdefghijklmnopqrstuvwxyz'; + $this->assertTrue(strpos($lowercaseLetters, TestProvider::randomLetter()) !== false); + } + + public function testRandomElementReturnsElementFromArray() + { + $elements = array('23', 'e', 32, '#'); + $this->assertContains(TestProvider::randomElement($elements), $elements); + } + + public function testNumerifyReturnsSameStringWhenItContainsNoHashSign() + { + $this->assertEquals('fooBar?', TestProvider::numerify('fooBar?')); + } + + public function testNumerifyReturnsStringWithHashSignsReplacedByDigits() + { + $this->assertRegExp('/foo\dBa\dr/', TestProvider::numerify('foo#Ba#r')); + } + + public function testLexifyReturnsSameStringWhenItContainsNoQuestionMark() + { + $this->assertEquals('fooBar#', TestProvider::lexify('fooBar#')); + } + + public function testNumerifyReturnsStringWithQuestionMarksReplacedByLetters() + { + $this->assertRegExp('/foo[a-z]Ba[a-z]r/', TestProvider::lexify('foo?Ba?r')); + } + + public function testBothifyCombinesNumerifyAndLexify() + { + $this->assertRegExp('/foo[a-z]Ba\dr/', TestProvider::bothify('foo?Ba#r')); + } + +} + +class TestProvider extends BaseProvider +{ + public static function randomDigit() + { + return parent::randomDigit(); + } + + public static function randomLetter() + { + return parent::randomLetter(); + } + + public static function randomElement($array) + { + return parent::randomElement($array); + } + + public static function numerify($string) + { + return parent::numerify($string); + } + + public static function lexify($string) + { + return parent::lexify($string); + } + + public static function bothify($string) + { + return parent::bothify($string); + } + +} \ No newline at end of file