public function testForKey()
 {
     $this->given($cause = new \Exception('some cause'))->when($exception = InvalidKeyException::forKey('foo', '', $cause))->then->object($exception)->isInstanceOf(InvalidKeyException::class)->integer($exception->getCode())->isEqualTo(0)->object($exception->getPrevious())->isIdenticalTo($cause);
     $this->given($exception = InvalidKeyException::forKey('bar'))->then->variable($exception->getPrevious())->isNull();
 }
Esempio n. 2
0
 /**
  * Validates that a key is valid.
  *
  * @param int|string $key
  *
  * @return bool
  *
  * @throws InvalidKeyException If the key is invalid.
  */
 protected function validateKey($key)
 {
     if (!is_string($key) && !is_int($key)) {
         throw InvalidKeyException::forKey($key);
     }
     return true;
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 protected function validateKey($key)
 {
     if (!is_int($key)) {
         throw InvalidKeyException::forKey($key, 'Expected a key of type integer. Got: %s');
     }
     return true;
 }