/**
  * Deletes function definitions that are not defined in a snapshot.
  *
  * @param  Snapshot         $snapshot
  * @throws RuntimeException when the uopz_delete() function is not available
  * @see    https://github.com/krakjoe/uopz
  */
 public function restoreFunctions(Snapshot $snapshot)
 {
     if (!function_exists('uopz_delete')) {
         throw new RuntimeException('The uopz_delete() function is required for this operation');
     }
     $functions = get_defined_functions();
     foreach (array_diff($functions['user'], $snapshot->functions()) as $function) {
         uopz_delete($function);
     }
 }
Exemplo n.º 2
0
 /**
  * @covers CodeCollab\Encryption\Defusev2\Key::generate
  */
 public function testGenerateThrowsOnCryptoError()
 {
     if (!function_exists('uopz_backup')) {
         $this->markTestSkipped('uopz extension is not installed.');
         return;
     }
     uopz_backup('random_bytes');
     uopz_delete('random_bytes');
     $this->expectException(CryptoException::class);
     $this->key->generate();
     uopz_restore('random_bytes');
 }
Exemplo n.º 3
0
 /**
  * @covers CodeCollab\Encryption\Defuse\Key::generate
  */
 public function testGenerateThrowsOnCryptoErrorThrowsCryptoExceptionBecauseOfObsoleteEncryptionMethod()
 {
     if (!function_exists('uopz_backup')) {
         $this->markTestSkipped('uopz extension is not installed.');
         return;
     }
     uopz_backup('mcrypt_create_iv');
     uopz_delete('mcrypt_create_iv');
     $this->expectException(CryptoException::class);
     $this->expectExceptionMessage('New messages should not be encrypted using the v1 branch of defuse/crypto.');
     $this->key->generate();
     uopz_restore('mcrypt_create_iv');
 }
Exemplo n.º 4
0
 /**
  * @covers CodeCollab\Encryption\Defuse\Decryptor::__construct
  * @covers CodeCollab\Encryption\Defuse\Decryptor::decrypt
  */
 public function testDecryptThrowsOnOpensslGetCipherMethodsNotAvailable()
 {
     if (!function_exists('uopz_backup')) {
         $this->markTestSkipped('uopz extension is not installed.');
         return;
     }
     uopz_backup('openssl_get_cipher_methods');
     uopz_delete('openssl_get_cipher_methods');
     $this->expectException(CryptoException::class);
     $decryptor = new Decryptor(base64_decode('iikuhrV0bgDuN8496EbSFA=='));
     $decryptor->decrypt('ciphertext');
     uopz_restore('openssl_get_cipher_methods');
 }