mirror of
https://github.com/fzaninotto/Faker.git
synced 2025-03-20 23:39:51 +01:00
Merge pull request #136 from Dynom/addingProviderOverrideTest
Adding provider override test
This commit is contained in:
commit
202c851747
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
vendor
|
||||
composer.lock
|
@ -1,5 +1,7 @@
|
||||
language: php
|
||||
php: 5.3
|
||||
before_script:
|
||||
- composer install --dev
|
||||
php:
|
||||
- 5.3
|
||||
- 5.4
|
||||
script: phpunit
|
||||
|
@ -53,7 +53,7 @@ class Generator
|
||||
*/
|
||||
public function parse($string)
|
||||
{
|
||||
return preg_replace_callback('/\{\{\s?(\w+)\s?\}\}/', array($this, 'callFormatWithMatches'), $string);
|
||||
return preg_replace_callback('/\{\{\s?(\w+)\s?\}\}/u', array($this, 'callFormatWithMatches'), $string);
|
||||
}
|
||||
|
||||
protected function callFormatWithMatches($matches)
|
||||
|
@ -136,8 +136,8 @@ class Base
|
||||
*/
|
||||
public static function numerify($string = '###')
|
||||
{
|
||||
$string = preg_replace_callback('/\#/', 'static::randomDigit', $string);
|
||||
$string = preg_replace_callback('/\%/', 'static::randomDigitNotNull', $string);
|
||||
$string = preg_replace_callback('/\#/u', 'static::randomDigit', $string);
|
||||
$string = preg_replace_callback('/\%/u', 'static::randomDigitNotNull', $string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
@ -150,7 +150,7 @@ class Base
|
||||
*/
|
||||
public static function lexify($string = '????')
|
||||
{
|
||||
return preg_replace_callback('/\?/', 'static::randomLetter', $string);
|
||||
return preg_replace_callback('/\?/u', 'static::randomLetter', $string);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,7 @@ class Internet extends \Faker\Provider\Base
|
||||
{
|
||||
$format = static::randomElement(static::$emailFormats);
|
||||
|
||||
return preg_replace('/\s/', '', $this->generator->parse($format));
|
||||
return preg_replace('/\s/u', '', $this->generator->parse($format));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -37,7 +37,7 @@ class Internet extends \Faker\Provider\Base
|
||||
*/
|
||||
public final function safeEmail()
|
||||
{
|
||||
return preg_replace('/\s/', '', $this->userName() . '@' . static::safeEmailDomain());
|
||||
return preg_replace('/\s/u', '', $this->userName() . '@' . static::safeEmailDomain());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,7 +45,7 @@ class Internet extends \Faker\Provider\Base
|
||||
*/
|
||||
public function freeEmail()
|
||||
{
|
||||
return preg_replace('/\s/', '', $this->userName() . '@' . static::freeEmailDomain());
|
||||
return preg_replace('/\s/u', '', $this->userName() . '@' . static::freeEmailDomain());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,7 +53,7 @@ class Internet extends \Faker\Provider\Base
|
||||
*/
|
||||
public function companyEmail()
|
||||
{
|
||||
return preg_replace('/\s/', '', $this->userName() . '@' . $this->domainName());
|
||||
return preg_replace('/\s/u', '', $this->userName() . '@' . $this->domainName());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,7 +103,7 @@ class Internet extends \Faker\Provider\Base
|
||||
$company = $this->generator->format('company');
|
||||
$companyElements = explode(' ', $company);
|
||||
$company = $companyElements[0];
|
||||
$company = preg_replace('/\W/', '', $company);
|
||||
$company = preg_replace('/\W/u', '', $company);
|
||||
|
||||
return static::toLower($company);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class Internet extends \Faker\Provider\Internet
|
||||
$company = $this->generator->format('company');
|
||||
$companyElements = explode(' ', $company);
|
||||
$company = $companyElements[0];
|
||||
$company = preg_replace('/\W/', '', $company);
|
||||
$company = preg_replace('/\W/u', '', $company);
|
||||
|
||||
return $company;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class Internet extends \Faker\Provider\Internet
|
||||
$company = $this->generator->format('company');
|
||||
$companyElements = explode(' ', $company);
|
||||
$company = $companyElements[0];
|
||||
$company = preg_replace('/\W/', '', $company);
|
||||
$company = preg_replace('/\W/u', '', $company);
|
||||
|
||||
return static::toLower(static::toAscii($company));
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class Internet extends \Faker\Provider\Internet
|
||||
$company = $this->generator->format('company');
|
||||
$companyElements = explode(' ', $company);
|
||||
$company = $companyElements[0];
|
||||
$company = preg_replace('/\W/', '', $company);
|
||||
$company = preg_replace('/\W/u', '', $company);
|
||||
|
||||
return static::toLower(static::toAscii($company));
|
||||
}
|
||||
|
@ -58,8 +58,8 @@ class Address extends \Faker\Provider\en_US\Address
|
||||
{
|
||||
$string = static::randomElement(static::$postcode);
|
||||
|
||||
$string = preg_replace_callback('/\#/', 'static::randomDigit', $string);
|
||||
$string = preg_replace_callback('/\?/', 'static::randomPostcodeLetter', $string);
|
||||
$string = preg_replace_callback('/\#/u', 'static::randomDigit', $string);
|
||||
$string = preg_replace_callback('/\?/u', 'static::randomPostcodeLetter', $string);
|
||||
|
||||
return static::toUpper($string);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class Internet extends \Faker\Provider\Internet
|
||||
$company = $this->generator->format('company');
|
||||
$companyElements = explode(' ', $company);
|
||||
$company = $companyElements[0];
|
||||
$company = preg_replace('/\W/', '', $company);
|
||||
$company = preg_replace('/\W/u', '', $company);
|
||||
|
||||
return static::toLower(static::toAscii($company));
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class Internet extends \Faker\Provider\Internet
|
||||
$company = $this->generator->format('company');
|
||||
$companyElements = explode(' ', $company);
|
||||
$company = $companyElements[0];
|
||||
$company = preg_replace('/\W/', '', $company);
|
||||
$company = preg_replace('/\W/u', '', $company);
|
||||
|
||||
return static::toLower(static::toAscii($company));
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class Internet extends \Faker\Provider\Internet
|
||||
$company = $this->generator->format('company');
|
||||
$companyElements = explode(' ', $company);
|
||||
$company = $companyElements[0];
|
||||
$company = preg_replace('/\W/', '', $company);
|
||||
$company = preg_replace('/\W/u', '', $company);
|
||||
|
||||
return static::toLower(static::toAscii($company));
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class Internet extends \Faker\Provider\Internet
|
||||
$company = $this->generator->format('company');
|
||||
$companyElements = explode(' ', $company);
|
||||
$company = $companyElements[0];
|
||||
$company = preg_replace('/,/', '', $company);
|
||||
$company = preg_replace('/,/u', '', $company);
|
||||
|
||||
return $company;
|
||||
}
|
||||
|
186
test/Faker/Provider/ProviderOverrideTest.php
Normal file
186
test/Faker/Provider/ProviderOverrideTest.php
Normal file
@ -0,0 +1,186 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Mark van der Velden <mark@dynom.nl>
|
||||
*/
|
||||
|
||||
namespace Faker\Test\Provider;
|
||||
|
||||
use Faker;
|
||||
|
||||
/**
|
||||
* Class ProviderOverrideTest
|
||||
*
|
||||
* @package Faker\Test\Provider
|
||||
*
|
||||
* This class tests a large portion of all locale specific providers. It does not test the entire stack, because each
|
||||
* locale specific provider (can) has specific implementations. The goal of this test is to test the common denominator
|
||||
* and to try to catch possible invalid multi-byte sequences.
|
||||
*/
|
||||
class ProviderOverrideTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Constants with regular expression patterns for testing the output.
|
||||
*
|
||||
* Regular expressions are sensitive for malformed strings (e.g.: strings with incorrect encodings) so by using
|
||||
* PCRE for the tests, even though they seem fairly pointless, we test for incorrect encodings also.
|
||||
*/
|
||||
const TEST_STRING_REGEX = '/.+/u';
|
||||
|
||||
/**
|
||||
* Slightly more specific for e-mail, the point isn't to properly validate e-mails.
|
||||
*/
|
||||
const TEST_EMAIL_REGEX = '/^(.+)@(.+)$/ui';
|
||||
|
||||
/**
|
||||
* @dataProvider localeDataProvider
|
||||
* @param string $locale
|
||||
*/
|
||||
public function testAddress($locale = null)
|
||||
{
|
||||
$faker = Faker\Factory::create($locale);
|
||||
|
||||
$this->assertRegExp(static::TEST_STRING_REGEX, $faker->city);
|
||||
$this->assertRegExp(static::TEST_STRING_REGEX, $faker->postcode);
|
||||
$this->assertRegExp(static::TEST_STRING_REGEX, $faker->address);
|
||||
$this->assertRegExp(static::TEST_STRING_REGEX, $faker->country);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider localeDataProvider
|
||||
* @param string $locale
|
||||
*/
|
||||
public function testCompany($locale = null)
|
||||
{
|
||||
$faker = Faker\Factory::create($locale);
|
||||
|
||||
$this->assertRegExp(static::TEST_STRING_REGEX, $faker->company);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider localeDataProvider
|
||||
* @param string $locale
|
||||
*/
|
||||
public function testDateTime($locale = null)
|
||||
{
|
||||
$faker = Faker\Factory::create($locale);
|
||||
|
||||
$this->assertRegExp(static::TEST_STRING_REGEX, $faker->century);
|
||||
$this->assertRegExp(static::TEST_STRING_REGEX, $faker->timezone);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider localeDataProvider
|
||||
* @param string $locale
|
||||
*/
|
||||
public function testInternet($locale = null)
|
||||
{
|
||||
$faker = Faker\Factory::create($locale);
|
||||
|
||||
$this->assertRegExp(static::TEST_STRING_REGEX, $faker->userName);
|
||||
|
||||
$this->assertRegExp(static::TEST_EMAIL_REGEX, $faker->email);
|
||||
$this->assertRegExp(static::TEST_EMAIL_REGEX, $faker->safeEmail);
|
||||
$this->assertRegExp(static::TEST_EMAIL_REGEX, $faker->freeEmail);
|
||||
$this->assertRegExp(static::TEST_EMAIL_REGEX, $faker->companyEmail);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider localeDataProvider
|
||||
* @param string $locale
|
||||
*/
|
||||
public function testPerson($locale = null)
|
||||
{
|
||||
$faker = Faker\Factory::create($locale);
|
||||
|
||||
$this->assertRegExp(static::TEST_STRING_REGEX, $faker->name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider localeDataProvider
|
||||
* @param string $locale
|
||||
*/
|
||||
public function testPhoneNumber($locale = null)
|
||||
{
|
||||
$faker = Faker\Factory::create($locale);
|
||||
|
||||
$this->assertRegExp(static::TEST_STRING_REGEX, $faker->phoneNumber);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider localeDataProvider
|
||||
* @param string $locale
|
||||
*/
|
||||
public function testUserAgent($locale = null)
|
||||
{
|
||||
$faker = Faker\Factory::create($locale);
|
||||
|
||||
$this->assertRegExp(static::TEST_STRING_REGEX, $faker->userAgent);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider localeDataProvider
|
||||
*
|
||||
* @param null $locale
|
||||
* @param string $locale
|
||||
*/
|
||||
public function testUuid($locale = null)
|
||||
{
|
||||
$faker = Faker\Factory::create($locale);
|
||||
|
||||
$this->assertRegExp(static::TEST_STRING_REGEX, $faker->uuid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function localeDataProvider()
|
||||
{
|
||||
$locales = $this->getAllLocales();
|
||||
$data = array();
|
||||
|
||||
foreach ($locales as $locale) {
|
||||
$data[] = array(
|
||||
$locale
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all locales as array values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getAllLocales()
|
||||
{
|
||||
static $locales = array();
|
||||
|
||||
if ( ! empty($locales)) {
|
||||
return $locales;
|
||||
}
|
||||
|
||||
// Finding all PHP files in the xx_XX directories
|
||||
$providerDir = __DIR__ .'/../../../src/Faker/Provider';
|
||||
foreach (glob($providerDir .'/*_*/*.php') as $file) {
|
||||
$localisation = basename(dirname($file));
|
||||
|
||||
if (isset($locales[ $localisation ])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$locales[ $localisation ] = $localisation;
|
||||
}
|
||||
|
||||
return $locales;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user