1
0
mirror of https://github.com/fzaninotto/Faker.git synced 2025-01-17 22:28:55 +01:00

Fix unit tests after previous refactoring

This commit is contained in:
Francois Zaninotto 2011-10-15 13:29:33 +02:00
parent 0e485bb1c5
commit 9ed3a255a7
2 changed files with 106 additions and 59 deletions

View File

@ -1,10 +1,12 @@
<?php
namespace Faker\Test;
require_once __DIR__ . '/../src/Generator.php';
use Faker\Generator;
class GeneratorTest extends PHPUnit_Framework_TestCase
class GeneratorTest extends \PHPUnit_Framework_TestCase
{
public function testGetFormatterReturnsCallable()
{
@ -59,64 +61,6 @@ class GeneratorTest extends PHPUnit_Framework_TestCase
$generator->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()
{

103
test/Provider/BaseTest.php Normal file
View File

@ -0,0 +1,103 @@
<?php
namespace Faker\Test\Provider;
require_once __DIR__ . '/../../src/Provider/Base.php';
use Faker\Provider\Base as BaseProvider;
class BaseTest extends \PHPUnit_Framework_TestCase
{
public function testRandomDigitReturnsInteger()
{
$this->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);
}
}