/** * @expectedException \Giftcards\Encryption\Profile\ProfileNotFoundException */ public function testGetWhereNotThere() { $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)->get($this->getFaker()->unique()->word); }
public function testSet() { $profile1 = new Profile($this->getFaker()->unique()->word, $this->getFaker()->unique()->word); $profile1Name = $this->getFaker()->unique()->word; $profile2 = new Profile($this->getFaker()->unique()->word, $this->getFaker()->unique()->word); $profile2Name = $this->getFaker()->unique()->word; $registry = new ProfileRegistry(); $registry->set($profile1Name, $profile1)->set($profile2Name, $profile2); $this->profileRegistryBuilder->set($profile1Name, $profile1)->set($profile2Name, $profile2->getCipher(), $profile2->getKeyName()); $this->assertEquals($registry, $this->profileRegistryBuilder->build()); }
public function testConfigureOptionsResolver() { $this->builder->configureOptionsResolver(\Mockery::mock('Symfony\\Component\\OptionsResolver\\OptionsResolver')->shouldReceive('setRequired')->once()->with(array('profile'))->andReturn(\Mockery::self())->getMock()->shouldReceive('setAllowedTypes')->once()->with(array('profile' => array('Giftcards\\Encryption\\Profile\\Profile')))->andReturn(\Mockery::self())->getMock()); $this->builderWithProfileRegistry->configureOptionsResolver(\Mockery::mock('Symfony\\Component\\OptionsResolver\\OptionsResolver')->shouldReceive('setRequired')->once()->with(array('profile'))->andReturn(\Mockery::self())->getMock()->shouldReceive('setAllowedTypes')->once()->with(array('profile' => array('Giftcards\\Encryption\\Profile\\Profile', 'string')))->andReturn(\Mockery::self())->getMock()->shouldReceive('setNormalizers')->once()->with(new EqualsMatcher(array('profile' => function () { })))->andReturn(\Mockery::self())->getMock()); $resolver = new OptionsResolver(); $this->builderWithProfileRegistry->configureOptionsResolver($resolver); $profile = new Profile($this->getFaker()->unique()->word, $this->getFaker()->unique()->word); $profileName = $this->getFaker()->unique()->word; $this->profileRegistry->set($profileName, $profile); $options = $resolver->resolve(array('profile' => $profileName)); $this->assertSame($options, $resolver->resolve(array('profile' => $profile))); $this->assertSame($profile, $options['profile']); }
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)))); }