Exemplo n.º 1
0
 public function testDecrypt()
 {
     $cipherText1 = $this->getFaker()->unique()->word;
     $plainText1 = $this->getFaker()->unique()->word;
     $this->cipherRegistry->get($this->cipher1Name)->shouldReceive('decipher')->once()->with($cipherText1, $this->keySource->get($this->key1Name))->andReturn($plainText1);
     $this->serializerDeserializer->shouldReceive('deserialize')->once()->with($cipherText1)->andReturn(new CipherText($cipherText1, $this->profileRegistry->get($this->profile1Name)));
     $this->assertEquals($plainText1, $this->encryptor->decrypt($cipherText1));
     $this->cipherRegistry->get($this->cipher1Name)->shouldReceive('decipher')->once()->with($cipherText1, $this->keySource->get($this->key1Name))->andReturn($plainText1);
     $this->serializerDeserializer->shouldReceive('deserialize')->once()->with($cipherText1)->andReturn(new CipherText($cipherText1, $this->profileRegistry->get($this->profile1Name)));
     $this->assertEquals($plainText1, $this->encryptor->decrypt($cipherText1, $this->profile1Name));
     $cipherText2 = $this->getFaker()->unique()->word;
     $plainText2 = $this->getFaker()->unique()->word;
     $this->cipherRegistry->get($this->cipher2Name)->shouldReceive('decipher')->once()->with($cipherText2, $this->keySource->get($this->key2Name))->andReturn($plainText2);
     $this->assertEquals($plainText2, $this->encryptor->decrypt(new CipherText($cipherText2, $this->profileRegistry->get($this->profile2Name))));
 }
Exemplo n.º 2
0
 public function testGettersSetters()
 {
     $profile1 = new Profile($this->getFaker()->word, $this->getFaker()->word);
     $profile1Name = $this->getFaker()->unique()->word;
     $profile2 = new Profile($this->getFaker()->word, $this->getFaker()->word);
     $profile2Name = $this->getFaker()->unique()->word;
     $profile3 = new Profile($this->getFaker()->word, $this->getFaker()->word);
     $profile3Name = $this->getFaker()->unique()->word;
     $this->registry->set($profile1Name, $profile1)->set($profile2Name, $profile2)->set($profile3Name, $profile3);
     $this->assertTrue($this->registry->has($profile1Name));
     $this->assertSame($profile1, $this->registry->get($profile1Name));
     $this->assertTrue($this->registry->has($profile2Name));
     $this->assertSame($profile2, $this->registry->get($profile2Name));
     $this->assertTrue($this->registry->has($profile3Name));
     $this->assertSame($profile3, $this->registry->get($profile3Name));
     $this->assertSame(array($profile1Name => $profile1, $profile2Name => $profile2, $profile3Name => $profile3), $this->registry->all());
 }