public function decryption_throws_exception_if_creation_has_failed() { $called = false; SecureString::setBacking(function ($value) { throw new XPException('Something went wrong - intentionally.'); }, function ($value) { return null; }); // Creation may never throw exception try { $s = new SecureString('foo'); } catch (\Throwable $t) { $this->fail('Exception thrown where no exception may be thrown', $t, null); } // Buf if creation failed, an exception must be raised here: $s->getCharacters(); }