/** * 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; }
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(); }