예제 #1
2
파일: UserTest.php 프로젝트: ndrx-io/elude
 public function __construct($name = null, array $data = array(), $dataName = '')
 {
     $this->faker = \Faker\Factory::create();
     if (is_null(self::$password)) {
         self::$password = $this->faker->password();
     }
     parent::__construct($name, $data, $dataName);
 }
예제 #2
0
 public function testState()
 {
     $state = $this->faker->state();
     $this->assertNotEmpty($state);
     $this->assertInternalType('string', $state);
     $this->assertRegExp('/[A-Z][a-z]+/', $state);
 }
예제 #3
0
 /**
  * @covers \Glue\Storage\Index::save
  */
 public function testSave()
 {
     $data = implode(' ', $this->faker->sentences());
     $result = $this->index->save($this->faker->uuid, $this->testData['length'], strlen($data));
     $this->assertNotEquals(false, $result);
     $this->assertInternalType('int', $result);
 }
예제 #4
0
 public function testLastKanaNameReturnsNagisa()
 {
     $faker = new Generator();
     $faker->addProvider(new Person($faker));
     $faker->seed(1);
     $this->assertEquals('ナギサ', $faker->lastKanaName);
 }
예제 #5
0
 public function createExpense(AcceptanceTester $I)
 {
     $I->wantTo('Create an expense');
     $vendorName = $this->faker->name;
     $clientEmail = $this->faker->safeEmail;
     $amount = $this->faker->numberBetween(10, 20);
     // create vendor
     $I->amOnPage('/vendors/create');
     $I->fillField(['name' => 'name'], $vendorName);
     $I->click('Save');
     $I->see($vendorName);
     $vendorId = $I->grabFromDatabase('vendors', 'id', ['name' => $vendorName]);
     // create client
     $I->amOnPage('/clients/create');
     $I->fillField(['name' => 'contacts[0][email]'], $clientEmail);
     $I->click('Save');
     $I->see($clientEmail);
     // create expense
     $I->amOnPage('/expenses/create');
     $I->fillField(['name' => 'amount'], $amount);
     $I->selectDropdown($I, $vendorName, '.vendor-select .dropdown-toggle');
     $I->selectDropdown($I, $clientEmail, '.client-select .dropdown-toggle');
     $I->click('Save');
     $I->seeInDatabase('expenses', ['vendor_id' => $vendorId]);
     // invoice expense
     $I->executeJS('submitAction(\'invoice\')');
     $I->click('Save');
     $I->wait(1);
     $I->see($clientEmail);
     $I->see($amount);
 }
예제 #6
0
 public function testAreaSuffix()
 {
     $areaSuffix = $this->faker->areaSuffix();
     $this->assertNotEmpty($areaSuffix);
     $this->assertInternalType('string', $areaSuffix);
     $this->assertRegExp('/[A-Z][a-z]+/', $areaSuffix);
 }
예제 #7
0
 /**
  * Test the validity of Canadian postcode
  */
 public function testPostcode()
 {
     $postcode = $this->faker->postcode();
     $this->assertNotEmpty($postcode);
     $this->assertInternalType('string', $postcode);
     $this->assertRegExp('/^[A-Za-z]\\d[A-Za-z][ -]?\\d[A-Za-z]\\d$/', $postcode);
 }
예제 #8
0
 public static function generateProducts(\Faker\Generator $generator)
 {
     $title_words = $generator->words(mt_rand(2, 5));
     $title = implode(' ', $title_words);
     $price = mt_rand(1, 10000);
     return array('title' => $title, 'price' => $price);
 }
예제 #9
0
 /**
  * @return array
  */
 public function getArgs()
 {
     $path = $this->getTemporaryPath();
     $paragraphs = $this->faker->paragraphs(rand(5, 50), true);
     $this->filesystem->dumpFile($path, $paragraphs);
     return [$path];
 }
 public function test(TestCase $test, Generator $faker)
 {
     $value = $faker->randomElement(array_filter(array_keys($this->items)), function ($value) {
         return !!$value;
     });
     return $test->select($value, $this->name);
 }
예제 #11
0
 public function testIdNumber()
 {
     $faker = new Generator();
     $faker->addProvider(new Person($faker));
     $faker->seed(2);
     $this->assertRegExp('/^[А-Я]{2}\\d{8}$/u', $faker->idNumber);
 }
예제 #12
0
 public function testPostCodeIsValid()
 {
     $main = '[1-9]{1}[0-9]{2}[0,1,4,5,9]{1}';
     $pattern = "/^({$main})|({$main}-[0-9]{3})+\$/";
     $postcode = $this->faker->postcode();
     $this->assertSame(preg_match($pattern, $postcode), 1, $postcode);
 }
예제 #13
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $shops = $this->shopRepository->findAll();
     // assign 3 shipping plans with 3 shipping optinos each to 80% of shops
     foreach ($shops as $shop) {
         if ($this->faker->boolean(20)) {
             continue;
         }
         /** @var Shop $shop */
         $shop->shippingPlans()->saveMany(factory(ShippingPlan::class, 3)->make())->each(function ($shippingPlan) {
             /** @var ShippingPlan $shippingPlan */
             $shippingPlan->shippingOptions()->saveMany(factory(ShippingOption::class, 3)->make());
         });
     }
     // assign shipping plan to each product if owner has any
     // or 0 if owner doesn't
     $products = $this->productRepository->with('owner.shippingPlans')->findAll();
     foreach ($products as $product) {
         /** @var Seller $seller */
         $seller = $product->seller;
         if ($seller->shippingPlans->count()) {
             /** @var Product $product */
             $product->shippingPlans()->attach($seller->shippingPlans->random()->id);
         }
     }
 }
예제 #14
0
 public function testBirthNumber()
 {
     $faker = new Generator();
     $faker->addProvider(new Person($faker));
     $faker->addProvider(new Miscellaneous($faker));
     for ($i = 0; $i < 1000; $i++) {
         $birthNumber = $faker->birthNumber();
         $birthNumber = str_replace('/', '', $birthNumber);
         // check date
         $year = intval(substr($birthNumber, 0, 2), 10);
         $month = intval(substr($birthNumber, 2, 2), 10);
         $day = intval(substr($birthNumber, 4, 2), 10);
         // make 4 digit year from 2 digit representation
         $year += $year < 54 ? 2000 : 1900;
         // adjust special cases for month
         if ($month > 50) {
             $month -= 50;
         }
         if ($year >= 2004 && $month > 20) {
             $month -= 20;
         }
         $this->assertTrue(checkdate($month, $day, $year), "Birth number {$birthNumber}: date {$year}/{$month}/{$day} is invalid.");
         // check CRC if presented
         if (strlen($birthNumber) == 10) {
             $crc = intval(substr($birthNumber, -1), 10);
             $refCrc = intval(substr($birthNumber, 0, -1), 10) % 11;
             if ($refCrc == 10) {
                 $refCrc = 0;
             }
             $this->assertEquals($crc, $refCrc, "Birth number {$birthNumber}: checksum {$crc} doesn't match expected {$refCrc}.");
         }
     }
 }
예제 #15
0
 public function setUp()
 {
     $faker = new Generator();
     $faker->addProvider(new Address($faker));
     $faker->addProvider(new Person($faker));
     $this->faker = $faker;
 }
예제 #16
0
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testTextMinLength()
 {
     $generator = new Generator();
     $generator->addProvider(new Text($generator));
     $generator->seed(0);
     $generator->realText(9);
 }
예제 #17
0
 /**
  *
  */
 public function testPostcode()
 {
     $postcode = $this->faker->postcode();
     $this->assertNotEmpty($postcode);
     $this->assertInternalType('string', $postcode);
     $this->assertRegExp('@^(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW]) ?[0-9][ABD-HJLNP-UW-Z]{2})$@i', $postcode);
 }
예제 #18
0
 public function testVatIsValid()
 {
     $vat = $this->faker->vat();
     $unspacedVat = $this->faker->vat(false);
     $this->assertRegExp('/^(BE 0\\d{9})$/', $vat);
     $this->assertRegExp('/^(BE0\\d{9})$/', $unspacedVat);
 }
예제 #19
0
 public function testUuidExpectedSeed()
 {
     $faker = new Generator();
     $faker->seed(123);
     $this->assertEquals("8e2e0c84-50dd-367c-9e66-f3ab455c78d6", BaseProvider::uuid());
     $this->assertEquals("073eb60a-902c-30ab-93d0-a94db371f6c8", BaseProvider::uuid());
 }
예제 #20
0
 public function testEmailIsValid()
 {
     $email = $this->faker->email();
     $this->assertNotFalse(filter_var($email, FILTER_VALIDATE_EMAIL));
     $this->assertNotEmpty($email);
     $this->assertInternalType('string', $email);
 }
예제 #21
0
 public function setUp()
 {
     $faker = new Generator();
     $faker->addProvider(new Barcode($faker));
     $faker->seed(0);
     $this->faker = $faker;
 }
예제 #22
0
 public function setUp()
 {
     $faker = new Generator();
     $faker->seed(1);
     $faker->addProvider(new DateTime($faker));
     $faker->addProvider(new Person($faker));
     $this->faker = $faker;
 }
예제 #23
0
 public function setUp()
 {
     $faker = new Generator();
     $faker->addProvider(new Person($faker));
     $faker->addProvider(new Internet($faker));
     $faker->addProvider(new Company($faker));
     $this->faker = $faker;
 }
예제 #24
0
 /**
  * @covers \Glue\Storage::save
  */
 public function testSave()
 {
     $data = implode(' ', $this->faker->sentences());
     $result = $this->storage->save($this->faker->uuid, $data);
     $this->assertNotEquals(false, $result);
     $this->assertInternalType('int', $result);
     $this->assertEquals(strlen($data), $result);
 }
 /**
  * {@inheritdoc}
  */
 protected function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefault('name', function (Options $options) {
         return $this->faker->words(3, true);
     })->setDefault('code', function (Options $options) {
         return StringInflector::nameToCode($options['name']);
     });
 }
예제 #26
0
 public function testSkillFormatter()
 {
     $faker = new Generator();
     $faker->addProvider(new Skill($faker));
     $skills = Skill::getProgLanguages();
     $skill = $faker->progLanguage;
     $this->assertTrue(in_array($skill, $skills));
 }
예제 #27
0
 /**
  * @param FactoryInterface $routeFactory
  */
 public function __construct(FactoryInterface $routeFactory, RepositoryInterface $staticContentRepository)
 {
     $this->routeFactory = $routeFactory;
     $this->faker = \Faker\Factory::create();
     $this->optionsResolver = (new OptionsResolver())->setDefault('name', function (Options $options) {
         return StringInflector::nameToCode($this->faker->words(3, true));
     })->setDefault('content', LazyOption::randomOne($staticContentRepository))->setAllowedTypes('content', ['string', StaticContent::class])->setNormalizer('content', LazyOption::findOneBy($staticContentRepository, 'name'));
 }
 /**
  * @return Generator
  */
 private function faker()
 {
     if (null === $this->faker) {
         $this->faker = Factory::create('en_US');
         $this->faker->seed(9000);
     }
     return $this->faker;
 }
예제 #29
0
 public function setUp()
 {
     $faker = new Generator();
     $faker->addProvider(new BaseProvider($faker));
     $faker->addProvider(new DateTimeProvider($faker));
     $faker->addProvider(new PersonProvider($faker));
     $faker->addProvider(new PaymentProvider($faker));
     $this->faker = $faker;
 }
예제 #30
0
 public function testRandomHtmlReturnsValidHTMLString()
 {
     $faker = new Generator();
     $faker->addProvider(new HtmlLorem($faker));
     $node = $faker->randomHtml(6, 10);
     $dom = new \DOMDocument();
     $error = $dom->loadHTML($node);
     $this->assertTrue($error);
 }