/** * @expectedException \Giftcards\Encryption\Cipher\CipherNotFoundException */ public function testGetWithMissingEncryptor() { $encryptor1Name = $this->getFaker()->unique()->word; $encryptor1 = \Mockery::mock('Giftcards\\Encryption\\Cipher\\CipherInterface')->shouldReceive('getName')->andReturn($encryptor1Name)->getMock(); $encryptor2Name = $this->getFaker()->unique()->word; $encryptor2 = \Mockery::mock('Giftcards\\Encryption\\Cipher\\CipherInterface')->shouldReceive('getName')->andReturn($encryptor2Name)->getMock(); $this->assertSame($this->registry, $this->registry->add($encryptor1)); $this->assertSame($this->registry, $this->registry->add($encryptor2)); $this->assertSame($encryptor1, $this->registry->get($encryptor1Name)); $this->registry->get($this->getFaker()->unique()->word); }
public function setUp() { $this->cipherRegistry = new CipherRegistry(); $this->keySource = \Mockery::mock('Giftcards\\Encryption\\Key\\SourceInterface'); $this->profileRegistry = new ProfileRegistry(); $this->serializerDeserializer = \Mockery::mock('Giftcards\\Encryption\\CipherText\\Serializer\\SerializerDeserializerInterface'); $this->key1Name = $this->getFaker()->unique()->word; $this->key2Name = $this->getFaker()->unique()->word; $this->cipher1Name = $this->getFaker()->unique()->word; $this->cipher2Name = $this->getFaker()->unique()->word; $this->profile1Name = $this->getFaker()->unique()->word; $this->profile2Name = $this->getFaker()->unique()->word; $this->cipherRegistry->add(\Mockery::mock('Giftcards\\Encryption\\Cipher\\CipherInterface')->shouldReceive('getName')->andReturn($this->cipher1Name)->getMock())->add(\Mockery::mock('Giftcards\\Encryption\\Cipher\\CipherInterface')->shouldReceive('getName')->andReturn($this->cipher2Name)->getMock()); $this->keySource->shouldReceive('get')->with($this->key1Name)->andReturn($this->getFaker()->unique()->word)->getMock()->shouldReceive('get')->with($this->key2Name)->andReturn($this->getFaker()->unique()->word)->getMock(); $this->profileRegistry->set($this->profile1Name, new Profile($this->cipher1Name, $this->key1Name))->set($this->profile2Name, new Profile($this->cipher2Name, $this->key2Name)); $this->encryptor = new Encryptor($this->cipherRegistry, $this->keySource, $this->profileRegistry, $this->serializerDeserializer, $this->defaultProfile = $this->profile2Name); }
public function testBuild() { $cipherRegistry = new CipherRegistry(); $cipherRegistry->add(new MysqlAes())->add(new NoOp()); $keySource = new ChainSource(); $profileRegistry = new ProfileRegistry(); $serializerDeserializer = new ChainSerializerDeserializer(); $this->assertEquals(new Encryptor($cipherRegistry, $keySource, $profileRegistry, $serializerDeserializer, null), $this->encryptorBuilder->build()); }
public function testBuild() { $cipher1 = \Mockery::mock('Giftcards\\Encryption\\Cipher\\CipherInterface')->shouldReceive('getName')->andReturn('cipher1')->getMock(); $cipher2 = \Mockery::mock('Giftcards\\Encryption\\Cipher\\CipherInterface')->shouldReceive('getName')->andReturn('cipher2')->getMock(); $this->builder->add($cipher1)->add($cipher2); $cipherRegistry = new CipherRegistry(); $cipherRegistry->add($cipher1)->add($cipher2); $this->assertEquals($cipherRegistry, $this->builder->build()); }