mirror of
https://github.com/fzaninotto/Faker.git
synced 2025-03-20 07:19:50 +01:00
parent
297943fa19
commit
73180ceac4
@ -39,7 +39,7 @@ class Lorem extends \Faker\Provider\Base
|
||||
* @param integer $nbWords around how many words the sentence should contain
|
||||
* @return string
|
||||
*/
|
||||
public function sentence($nbWords = 6)
|
||||
public static function sentence($nbWords = 6)
|
||||
{
|
||||
$words = static::words($nbWords + mt_rand(-2, 2));
|
||||
$words[0] = ucwords($words[0]);
|
||||
@ -54,7 +54,7 @@ class Lorem extends \Faker\Provider\Base
|
||||
* @param integer $nb how many sentences to return
|
||||
* @return array
|
||||
*/
|
||||
public function sentences($nb = 3)
|
||||
public static function sentences($nb = 3)
|
||||
{
|
||||
$sentences = array();
|
||||
for ($i=0; $i < $nb; $i++) {
|
||||
@ -70,7 +70,7 @@ class Lorem extends \Faker\Provider\Base
|
||||
* @param integer $nbSentences around how many sentences the paragraph should contain
|
||||
* @return string
|
||||
*/
|
||||
public function paragraph($nbSentences = 3)
|
||||
public static function paragraph($nbSentences = 3)
|
||||
{
|
||||
return join(static::sentences($nbSentences + mt_rand(-1, 1)), ' ');
|
||||
}
|
||||
@ -82,7 +82,7 @@ class Lorem extends \Faker\Provider\Base
|
||||
* @param integer $nb how many paragraphs to return
|
||||
* @return array
|
||||
*/
|
||||
public function paragraphs($nb = 3)
|
||||
public static function paragraphs($nb = 3)
|
||||
{
|
||||
$paragraphs = array();
|
||||
for ($i=0; $i < $nb; $i++) {
|
||||
@ -104,12 +104,13 @@ class Lorem extends \Faker\Provider\Base
|
||||
$text = array();
|
||||
$size = 0;
|
||||
while ($size < $maxNbChars) {
|
||||
$paragraph = self::paragraph();
|
||||
$paragraph = ($size ? "\n" : '') . static::paragraph();
|
||||
$text []= $paragraph;
|
||||
$size += strlen($paragraph);
|
||||
}
|
||||
array_pop($text);
|
||||
|
||||
return join($text, "\n");
|
||||
return join($text, '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
27
test/Faker/Provider/LoremTest.php
Normal file
27
test/Faker/Provider/LoremTest.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Faker\Test\Provider;
|
||||
|
||||
use Faker\Provider\Lorem;
|
||||
use Faker\Generator;
|
||||
|
||||
class LoremTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testText()
|
||||
{
|
||||
$generator = new Generator();
|
||||
$provider = new TestableLorem($generator);
|
||||
$singleParagraph = 'This is a test paragraph.';
|
||||
$this->assertEquals($singleParagraph, $provider->text(51));
|
||||
$this->assertEquals($singleParagraph . "\n" . $singleParagraph, $provider->text(52));
|
||||
}
|
||||
}
|
||||
|
||||
class TestableLorem extends Lorem
|
||||
{
|
||||
public static function paragraph($nbSentences = 3)
|
||||
{
|
||||
// 25 characters
|
||||
return 'This is a test paragraph.';
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user