Skip to content

Commit

Permalink
Explicit the use of the boolean() provider to vary the type of data g…
Browse files Browse the repository at this point in the history
…enerated
  • Loading branch information
fzaninotto committed Oct 30, 2011
1 parent b41c916 commit cab6806
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 58 deletions.
97 changes: 56 additions & 41 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,34 +270,34 @@ The following script generates a valid XML document:
```php
<?php
require_once '/path/to/Faker/src/autoload.php';
$generator = Faker\Factory::create();
$faker = Faker\Factory::create();
?>
<?xml version="1.0" encoding="UTF-8"?>
<contacts>
<?php for ($i=0; $i < 10; $i++): ?>
<contact firstName="<?php echo $generator->firstName ?>" lastName="<?php echo $generator->lastName ?>" email="<?php echo $generator->email ?>"/>
<phone number="<?php echo $generator->phoneNumber ?>"/>
<?php if (mt_rand(0,3) == 0): ?>
<birth date="<?php echo $generator->dateTimeThisCentury->format('Y-m-d') ?>" place="<?php echo $generator->city ?>"/>
<contact firstName="<?php echo $faker->firstName ?>" lastName="<?php echo $faker->lastName ?>" email="<?php echo $faker->email ?>"/>
<phone number="<?php echo $faker->phoneNumber ?>"/>
<?php if ($faker->boolean(25)): ?>
<birth date="<?php echo $faker->dateTimeThisCentury->format('Y-m-d') ?>" place="<?php echo $faker->city ?>"/>
<?php endif; ?>
<address>
<street><?php echo $generator->streetAddress ?></street>
<city><?php echo $generator->city ?></city>
<postcode><?php echo $generator->postcode ?></postcode>
<state><?php echo $generator->state ?></state>
<street><?php echo $faker->streetAddress ?></street>
<city><?php echo $faker->city ?></city>
<postcode><?php echo $faker->postcode ?></postcode>
<state><?php echo $faker->state ?></state>
</address>
<company name="<?php echo $generator->company ?>" catchPhrase="<?php echo $generator->catchPhrase ?>">
<?php if (mt_rand(0,2) == 0): ?>
<offer><?php echo $generator->bs ?></offer>
<company name="<?php echo $faker->company ?>" catchPhrase="<?php echo $faker->catchPhrase ?>">
<?php if ($faker->boolean(33)): ?>
<offer><?php echo $faker->bs ?></offer>
<?php endif; ?>
<?php if (mt_rand(0,3) == 0): ?>
<director name="<?php echo $generator->name ?>" />
<?php if ($faker->boolean(33)): ?>
<director name="<?php echo $faker->name ?>" />
<?php endif; ?>
</company>
<?php if (mt_rand(0,5) == 0): ?>
<?php if ($faker->boolean(15)): ?>
<details>
<![CDATA[
<?php echo $generator->text(400) ?>
<?php echo $faker->text(400) ?>
]]>
</details>
<?php endif; ?>
Expand Down Expand Up @@ -396,51 +396,66 @@ Aut asperiores nihil eius repellendus. Vero nihil corporis voluptatem explicabo
</contact>
<contact firstName="Rene" lastName="Spencer" email="[email protected]"/>
<phone number="715.222.0095x175"/>
<birth date="2008-07-25" place="Zulaufborough"/>
<birth date="2008-08-07" place="Zulaufborough"/>
<address>
<street>478 Daisha Landing Apt. 510</street>
<city>West Lizethhaven</city>
<postcode>30566-5362</postcode>
<state>WestVirginia</state>
</address>
<company name="Wiza Inc" catchPhrase="Persevering reciprocal approach">
<director name="Roel DuBuque" />
<offer>orchestrate dynamic networks</offer>
<director name="Erwin Nienow" />
</company>
<details>
<![CDATA[
Dolorem consequatur voluptates unde optio unde. Accusantium dolorem est est architecto impedit. Corrupti et provident quo.
Reprehenderit dolores aut quidem suscipit repudiandae corporis error. Molestiae enim aperiam illo.
Et similique qui non expedita quia dolorum. Ex rem incidunt ea accusantium temporibus minus non.
]]>
</details>
</contact>
<contact firstName="Erwin" lastName="Nienow" email="[email protected]"/>
<phone number="+87(6)0704857083"/>
<birth date="2009-02-11" place="Estrellaside"/>
<contact firstName="Alessandro" lastName="Hagenes" email="[email protected]"/>
<phone number="1-284-958-6768"/>
<address>
<street>0920 Adah Skyway</street>
<city>South Kristopher</city>
<postcode>62693</postcode>
<state>Mississippi</state>
<street>1251 Koelpin Mission</street>
<city>North Revastad</city>
<postcode>81620</postcode>
<state>Maryland</state>
</address>
<company name="Jakubowski Inc" catchPhrase="Secured object-oriented conglomeration">
<company name="Stiedemann-Bruen" catchPhrase="Re-engineered 24/7 success">
</company>
</contact>
<contact firstName="Zoie" lastName="Murazik" email="[email protected]"/>
<phone number="(179)927-3745"/>
<contact firstName="Novella" lastName="Rutherford" email="[email protected]"/>
<phone number="(091)825-7971"/>
<address>
<street>91758 Sienna Burg Apt. 791</street>
<city>Murrayfurt</city>
<postcode>44284</postcode>
<state>Virginia</state>
<street>6396 Langworth Hills Apt. 446</street>
<city>New Carlos</city>
<postcode>89399-0268</postcode>
<state>Wyoming</state>
</address>
<company name="Schmitt-Moore" catchPhrase="Robust modular software">
<director name="Brianne Fahey" />
<company name="Stroman-Legros" catchPhrase="Expanded 4thgeneration moratorium">
<director name="Earlene Bayer" />
</company>
</contact>
<contact firstName="Claud" lastName="Rosenbaum" email="[email protected]"/>
<phone number="203.581.7085x587"/>
<contact firstName="Andreane" lastName="Mann" email="[email protected]"/>
<phone number="941-659-9982x5689"/>
<birth date="1934-02-21" place="Stantonborough"/>
<address>
<street>165 Bogisich Unions Apt. 630</street>
<city>Corwinhaven</city>
<postcode>57971</postcode>
<state>Virginia</state>
<street>2246 Kreiger Station Apt. 291</street>
<city>Kaydenmouth</city>
<postcode>11397-1072</postcode>
<state>Wyoming</state>
</address>
<company name="Mann, Price and Hartmann" catchPhrase="Versatile mobile securedline">
<company name="Lebsack, Bernhard and Kiehn" catchPhrase="Persevering actuating framework">
<offer>grow sticky portals</offer>
</company>
<details>
<![CDATA[
Quia dolor ut quia error libero. Enim facilis iusto earum et minus rerum assumenda. Quia doloribus et reprehenderit ut. Occaecati voluptatum dolor voluptatem vitae qui velit quia.
Fugiat non in itaque sunt nobis totam. Sed nesciunt est deleniti cumque alias. Repudiandae quo aut numquam modi dicta libero.
]]>
</details>
</contact>
</contacts>
```
Expand Down
34 changes: 17 additions & 17 deletions test/test.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
<?php
require_once __DIR__ . '/../src/autoload.php';

$generator = Faker\Factory::create();
$generator->seed(5);
$faker = Faker\Factory::create();
$faker->seed(5);
?>
<?xml version="1.0" encoding="UTF-8"?>
<contacts>
<?php for ($i=0; $i < 10; $i++): ?>
<contact firstName="<?php echo $generator->firstName ?>" lastName="<?php echo $generator->lastName ?>" email="<?php echo $generator->email ?>"/>
<phone number="<?php echo $generator->phoneNumber ?>"/>
<?php if (mt_rand(0,3) == 0): ?>
<birth date="<?php echo $generator->dateTimeThisCentury->format('Y-m-d') ?>" place="<?php echo $generator->city ?>"/>
<contact firstName="<?php echo $faker->firstName ?>" lastName="<?php echo $faker->lastName ?>" email="<?php echo $faker->email ?>"/>
<phone number="<?php echo $faker->phoneNumber ?>"/>
<?php if ($faker->boolean(25)): ?>
<birth date="<?php echo $faker->dateTimeThisCentury->format('Y-m-d') ?>" place="<?php echo $faker->city ?>"/>
<?php endif; ?>
<address>
<street><?php echo $generator->streetAddress ?></street>
<city><?php echo $generator->city ?></city>
<postcode><?php echo $generator->postcode ?></postcode>
<state><?php echo $generator->state ?></state>
<street><?php echo $faker->streetAddress ?></street>
<city><?php echo $faker->city ?></city>
<postcode><?php echo $faker->postcode ?></postcode>
<state><?php echo $faker->state ?></state>
</address>
<company name="<?php echo $generator->company ?>" catchPhrase="<?php echo $generator->catchPhrase ?>">
<?php if (mt_rand(0,2) == 0): ?>
<offer><?php echo $generator->bs ?></offer>
<company name="<?php echo $faker->company ?>" catchPhrase="<?php echo $faker->catchPhrase ?>">
<?php if ($faker->boolean(33)): ?>
<offer><?php echo $faker->bs ?></offer>
<?php endif; ?>
<?php if (mt_rand(0,3) == 0): ?>
<director name="<?php echo $generator->name ?>" />
<?php if ($faker->boolean(33)): ?>
<director name="<?php echo $faker->name ?>" />
<?php endif; ?>
</company>
<?php if (mt_rand(0,5) == 0): ?>
<?php if ($faker->boolean(15)): ?>
<details>
<![CDATA[
<?php echo $generator->text(400) ?>
<?php echo $faker->text(400) ?>
]]>
</details>
<?php endif; ?>
Expand Down

0 comments on commit cab6806

Please sign in to comment.