Ejemplo n.º 1
0
 public function testMakeWithHugeJson()
 {
     $factory = new JobFactory();
     $huge = Str::random(2 ** 16);
     $this->setExpectedException(InvalidArgumentException::class);
     $factory->make('test.test', ['huge' => $huge], 7);
 }
Ejemplo n.º 2
0
 /**
  * Construct an instance of a DropdownFactory.
  */
 public function __construct()
 {
     parent::__construct();
     $this->hash = Str::random();
     $this->options = [];
     $this->right = false;
 }
Ejemplo n.º 3
0
 /**
  * Generate an HMAC key pair.
  *
  * @param int $generatePublicLength
  * @param int $generateSecretLength
  * @param string $algorithm
  *
  * @return KeyPair
  */
 public function generateHmac($generatePublicLength = 256, $generateSecretLength = 512, $algorithm = 'sha512')
 {
     $pair = new KeyPair();
     $pair->public_id = hash($algorithm, Str::random($generatePublicLength));
     $pair->secret_key = hash($algorithm, Str::random($generateSecretLength));
     $pair->type = KeyPairTypes::TYPE_HMAC;
     $pair->data = [];
     return $pair;
 }
Ejemplo n.º 4
0
 public function testVerify()
 {
     $hasher = new HmacHasher();
     $private = Str::random(256);
     $private2 = Str::random(256);
     $hash1 = $hasher->hash('this is a test', $private);
     $hash2 = $hasher->hash('another test', $private2);
     $this->assertEqualsMatrix([[true, $hasher->verify($hash1, 'this is a test', $private)], [false, $hasher->verify($hash1, 'this is a test', $private2)], [false, $hasher->verify($hash2, 'this is a test', $private)], [false, $hasher->verify($hash1, 'th1s 1s 4 t3st', $private)], [false, $hasher->verify($hash2, 'another test', $private)], [true, $hasher->verify($hash2, 'another test', $private2)]]);
 }
Ejemplo n.º 5
0
 public function testAssociativity()
 {
     // TODO: Ensure this is the right way to test this.
     $lowerCase = function ($string) {
         return Maybe::just(strtolower($string));
     };
     $camelCase = function ($string) {
         return Maybe::just('Camelcase: ' . Str::camel($string));
     };
     $this->assertEquals(Maybe::just('OMG_WHAT_IS_THIS')->bind($lowerCase)->bind($camelCase), Maybe::just('OMG_WHAT_IS_THIS')->bind(function ($x) use($lowerCase, $camelCase) {
         return $lowerCase($x)->bind($camelCase);
     }));
     $this->assertEquals(Maybe::nothing()->bind($lowerCase)->bind($camelCase), Maybe::nothing()->bind(function ($x) use($lowerCase, $camelCase) {
         return $lowerCase($x)->bind($camelCase);
     }));
     $this->assertEquals(Maybe::fromJust(Maybe::just('OMG_WHAT_IS_THIS')->bind($lowerCase)->bind($camelCase)), 'Camelcase: omgWhatIsThis');
 }
Ejemplo n.º 6
0
 /**
  * Get an environment variable or return the default if it is not defined.
  *
  * @param string $key
  * @param null|mixed|callable $default
  *
  * @return bool|mixed|null|string
  */
 public static function get($key, $default = null)
 {
     $value = static::getRaw($key, $default);
     if (is_string($value)) {
         // Convert some common values into their scalar types.
         switch (strtolower($value)) {
             case 'true':
                 return true;
             case 'false':
                 return false;
             case 'null':
                 return null;
         }
         // Strip "" if the string is wrapped in them.
         if (Str::beginsWith($value, '"') && Str::endsWith($value, '"')) {
             return substr($value, 1, -1);
         }
     }
     return $value;
 }
Ejemplo n.º 7
0
 public function testAppend()
 {
     $job = new Job();
     $job->task = 'test.test';
     $this->assertNull($job->message);
     $job->append('lol');
     $this->assertEquals("lol\n", $job->message);
     $job->append('omg');
     $this->assertEquals("lol\nomg\n", $job->message);
     $job->append('doge');
     $this->assertEquals("lol\nomg\ndoge\n", $job->message);
     $huge = Str::quickRandom(200000);
     $job->append($huge);
     $job->append($huge);
     $job->append('doge');
     $this->assertFalse(starts_with($job->message, "lol\nomg\ndoge\n"));
     $this->assertTrue(ends_with($job->message, "doge\n"));
 }
Ejemplo n.º 8
0
 /**
  * @return string
  */
 public function getLastName()
 {
     return Str::studly($this->lastName);
 }
Ejemplo n.º 9
0
 /**
  * Get all the API ResourceFactories for this application.
  *
  * @return ResourceFactory[]
  */
 public function getApiResources()
 {
     return Std::filter(function (ResourceFactory $resource) {
         foreach ($this->getApiPrefixes() as $prefix) {
             if (Str::beginsWith($resource->getPrefix(), $prefix)) {
                 return true;
             }
         }
         return false;
     }, $this->getResources());
 }
Ejemplo n.º 10
0
 /**
  * Get an array representation of this entity.
  *
  * @return array
  */
 public function toArray()
 {
     $result = [];
     ArrayList::of($this->getFillable())->append(ArrayList::of($this->getVisible()))->unique(SORT_STRING)->exceptValues($this->getHidden())->each(function ($key) use(&$result) {
         $getter = vsprintf('get%s', [Str::studly($key)]);
         if (method_exists($this, $getter)) {
             $result[$key] = $this->{$getter}();
             return;
         }
         $camel = Str::camel($key);
         $result[$key] = $this->{$camel};
     });
     return $result;
 }
Ejemplo n.º 11
0
 /**
  * Set properties of an object by only calling setters of array keys that
  * are set in the input array. Useful for parsing API responses into
  * entities.
  *
  * @param object $object
  * @param array $input
  * @param string[]|null $allowed
  */
 public static function callSetters($object, array $input, array $allowed = null)
 {
     $filtered = ArrayMap::of($input);
     if ($allowed !== null) {
         $filtered = $filtered->only($allowed);
     }
     $filtered->each(function ($value, $key) use(&$object) {
         $setterName = 'set' . Str::studly($key);
         $object->{$setterName}($value);
     });
 }
Ejemplo n.º 12
0
 public function testEndsWith()
 {
     $this->assertEqualsMatrix([[true, Str::endsWith('hello world', 'world')], [true, Str::endsWith('hello world', '')], [false, Str::endsWith('hello world', 'omg')], [false, Str::endsWith('hello world', 'hello world ')]]);
 }
 /**
  * Get a list of example responses for a specific method.
  *
  * @param string $methodName
  *
  * @return Response[]
  */
 public function getMethodExampleResponses($methodName)
 {
     $getterName = vsprintf('get%sExampleResponses', [Str::studly($methodName)]);
     if (method_exists($this, $getterName)) {
         return $this->{$getterName}();
     }
     return [];
 }