Пример #1
0
 /**
  * @param string|null $type If specified, return the type value. See {@see User::getAllowedTypes()} to see valid
  *                          type names; if is invalid will return en empty array. Otherwise return an array with a
  *                          random of types.
  *
  * @return array Array of user types.
  */
 public function userTypes($type = null)
 {
     $allowedTypes = User::getAllowedTypes();
     if (null === $type) {
         return BaseProvider::randomElements($allowedTypes, BaseProvider::numberBetween(1, count($allowedTypes)));
     }
     return isset($allowedTypes[$type]) ? [$allowedTypes[$type]] : [];
 }
Пример #2
0
 public function testRandomElements()
 {
     $this->assertCount(1, BaseProvider::randomElements(), 'Should work without any input');
     $empty = BaseProvider::randomElements(array(), 0);
     $this->assertInternalType('array', $empty);
     $this->assertCount(0, $empty);
     $shuffled = BaseProvider::randomElements(array('foo', 'bar', 'baz'), 3);
     $this->assertContains('foo', $shuffled);
     $this->assertContains('bar', $shuffled);
     $this->assertContains('baz', $shuffled);
 }