Fakerでテストデータ生成でざっくりと使い方や簡単なメソッドを紹介しましたが、一覧化してみました。
- Faker\Providor\Base
- Faker\Provider\Lorem
- Faker\Provider\DateTime
- Faker\Provider\Internet
- Faker\Provider\UserAgent
- Faker\Provider\Payment
- Faker\Provider\Color
- Faker\Provider\File
- Faker\Provider\Image
- Faker\Provider\Uuid
- Faker\Provider\Barcode
- Faker\Provider\Miscellaneous
- Faker\Provider\Biased
- Faker\Provider\HtmlLorem
Faker\Providor\Base
| Method | Type | Description | Example |
|---|---|---|---|
| randomDigit() | int | ランダムな数字(0-9)を取得 | 5 |
| randomDigitNot($except) | int | ランダムな数字(0-9)で$except以外を取得 | 7 |
| randomDigitNotNull() | int | ランダムな数字(1-9)を取得 | 9 |
| randomNumber($nbDigits = null, $strict = false) | int | $strictがfalseの場合は0〜桁数($nbDigis)、trueの場合は桁数のみのランダムな数値を取得。桁数がnullの場合は1と同義。 | 79907610 |
| randomFloat($nbMaxDecimals = null, $min = 0, $max = null) | float | 最小値($min)から最大値($max)までの間で、指定した小数点以下の桁数($nbMaxDecimals)の数値を取得 | 48.8932 |
| numberBetween($min = 1000, $max = 9000) | int | 範囲内のランダムな数値を取得 | 79907610 |
| randomLetter() | string | a-zのランダムな英小文字を取得 | “b” |
| randomElements($array = array (‘a’,’b’,’c’), $count = 1) | array | 指定した配列の中から$count数分だけ抽出して配列で取得 | array(“c”) |
| randomElement($array = array (“a”,”b”,”c”)) | string | 指定した配列の中から1つだけ取得 | “b” |
| shuffle(“hello, world”) | string | 指定した文字列をシャッフルして取得 | “rlo,h eoldlw” |
| shuffle(array(1, 2, 3)) | array | 指定した配列をシャッフルして取得 | array(2, 1, 3) |
| numerify(‘Hello ###’) | string | “Hello 609” | |
| lexify(‘Hello ???’) | string | “Hello wgt” | |
| bothify(‘Hello ##??’) | string | “Hello 42jz” | |
| asciify(‘Hello ***’) | string | “Hello R6+” | |
| regexify(‘[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}’) | string | “sm0@y8k96a.ej” |
Faker\Provider\Lorem
| Method | Type | Description | Example |
|---|---|---|---|
| word() | string | “aut” | |
| words($nb = 3, $asText = false) | array | array(‘porro’, ‘sed’, ‘magni’) | |
| sentence($nbWords = 6, $variableNbWords = true) | string | Sit vitae voluptas sint non voluptates. | |
| sentences($nb = 3, $asText = false) | array | array(“Optio quos qui illo error.”, “省略”, “省略”) | |
| paragraph($nbSentences = 3, $variableNbSentences = true) | string | ||
| paragraphs($nb = 3, $asText = false) | array | ||
| text($maxNbChars = 200) | string |
Faker\Provider\DateTime
| Method | Type | Description | Example |
|---|---|---|---|
| unixTime($max = ‘now’) | int | 0〜$maxまでのランダムなタイムスタンプを取得 | 1061306726 |
| dateTime($max = ‘now’, $timezone = null) | DateTime | タイムスタンプが0以上のランダムなDateTimeオブジェクトを取得 | |
| dateTimeAD($max = ‘now’, $timezone = null) | DateTime | 西暦1年1月1日から現在までのランダムなDateTimeオブジェクトを取得 | |
| iso8601($max = ‘now’) | string | ||
| date($format = ‘Y-m-d’, $max = ‘now’) | string | ||
| time($format = ‘H:i:s’, $max = ‘now’) | string | ||
| dateTimeBetween($startDate = ‘-30 years’, $endDate = ‘now’, $timezone = null) | DateTime | ||
| dateTimeInInterval($date = ‘-30 years’, $interval = ‘+5 days’, $timezone = null) | DateTime | ||
| dateTimeThisCentury($max = ‘now’, $timezone = null) | DateTime | 現在の世紀内のランダムなDateTimeオブジェクトを取得 | |
| dateTimeThisDecade($max = ‘now’, $timezone = null) | DateTime | 現在の10年内のランダムなDateTimeオブジェクトを取得 | |
| dateTimeThisYear($max = ‘now’, $timezone = null) | DateTime | 現在の年内のランダムなDateTimeオブジェクトを取得 | |
| dateTimeThisMonth($max = ‘now’, $timezone = null) | DateTime | 現在の月内のランダムなDateTimeオブジェクトを取得 | |
| amPm($max = ‘now’) | string | am | |
| dayOfMonth($max = ‘now’) | string | 22 | |
| dayOfWeek($max = ‘now’) | string | Tuesday | |
| month($max = ‘now’) | string | 7 | |
| monthName($max = ‘now’) | string | September | |
| year($max = ‘now’) | string | 1673 | |
| century() | string | XVII | |
| timezone() | string | Europe/Paris |
Faker\Provider\Internet
| Method | Type | Description | Example |
|---|---|---|---|
| email() | string | jdoe@acme.biz | |
| safeEmail() | string | jdoe@example.com | |
| freeEmail() | string | jdoe@gmail.com | |
| companyEmail() | string | jdoe@dawson.com | |
| freeEmailDomain() | string | gmail.com | |
| safeEmailDomain() | string | example.org | |
| userName() | string | jdoe | |
| password($minLength = 6, $maxLength = 20) | string | fY4èHdZv68 | |
| domainName() | string | tiramisu.com | |
| domainWord() | string | faber | |
| tld() | string | com | |
| url() | string | http://www.runolfsdottir.com/ | |
| slug($nbWords = 6, $variableNbWords = true) | string | aut-repellat-commodi-vel-itaque-nihil-id-saepe-nostrum | |
| ipv4() | string | 237.149.115.38 | |
| ipv6() | string | 35cd:186d:3e23:2986:ef9f:5b41:42a4:e6f1 | |
| localIpv4() | string | 10.1.1.17 | |
| macAddress() | string | 32:F1:39:2F:D6:18 |
Faker\Provider\UserAgent
| Method | Type | Description | Example |
|---|---|---|---|
| userAgent() | |||
| chrome() | |||
| firefox() | |||
| safari() | |||
| opera() | |||
| internetExplorer() |
Faker\Provider\Payment
| Method | Type | Description | Example |
|---|---|---|---|
| creditCardType() | string | MasterCard | |
| creditCardNumber($type = null, $formatted = false, $separator = ‘-‘) | string | 4485480221084675 | |
| creditCardExpirationDate($valid = true) | DateTime | ||
| tionDateString($valid = true, $expirationDateFormat = null) | string | 04/13 | |
| creditCardDetails($valid = true) | array | ||
| iban($countryCode = null, $prefix = ”, $length = null) | string | ||
| swiftBicNumber() | string |
Faker\Provider\Color
| Method | Type | Description | Example |
|---|---|---|---|
| hexColor() | string | #fa3cc2 | |
| safeHexColor() | string | #ff0044 | |
| rgbColorAsArray() | array | array(0,255,122) | |
| rgbColor() | string | 0,255,122 | |
| rgbCssColor() | string | rgb(0,255,122) | |
| rgbaCssColor() | string | rgba(0,255,122,0.8) | |
| safeColorName() | string | blue | |
| colorName() | string | NavajoWhite | |
| hslColor() | string | 340,50,20 | |
| hslColorAsArray() | array | array(340, 50, 20) |
Faker\Provider\File
| Method | Type | Description | Example |
|---|---|---|---|
| mimeType() | string | video/avi | |
| fileExtension() | string | avi | |
| file($sourceDirectory = ‘/tmp’, $targetDirectory = ‘/tmp’, $fullPath = true) | string |
Faker\Provider\Image
| Method | Type | Description | Example |
|---|---|---|---|
| imageUrl($width = 640, $height = 480, $category = null, $randomize = true, $word = null, $gray = false) | |||
| image($dir = null, $width = 640, $height = 480, $category = null, $fullPath = true, $randomize = true, $word = null, $gray = false) |
Faker\Provider\Uuid
| Method | Type | Description | Example |
|---|---|---|---|
| uuid() | string | 7e57d004-2b97-0e7a-b45f-5387367791cd |
Faker\Provider\Barcode
| Method | Type | Description | Example |
|---|---|---|---|
| ean13() | string | ||
| ean8() | string | ||
| isbn13() | string | ||
| isbn10() | string |
Faker\Provider\Miscellaneous
| Method | Type | Description | Example |
|---|---|---|---|
| boolean($chanceOfGettingTrue = 50) | bool | true | |
| md5() | string | cfcd208495d565ef66e7dff9f98764da | |
| sha1() | string | b5d86317c2a144cd04d0d7c03b2b02666fafadf2 | |
| sha256() | string | 85086017559ccc40638fcde2fecaf295e0de7ca51b7517b6aebeaaf75b4d4654 | |
| locale() | string | ja_JP | |
| countryCode() | string | JP | |
| languageCode() | string | ja | |
| currencyCode() | string | JPY | |
| emoji | string | ? |
Faker\Provider\Biased
| Method | Type | Description | Example |
|---|---|---|---|
| biasedNumberBetween($min = 0, $max = 100, $function = ‘sqrt’) | int |
Faker\Provider\HtmlLorem
| Method | Type | Description | Example |
|---|---|---|---|
| randomHtml($maxDepth = 4, $maxWidth = 4) | string |
