/**
  * Transform to protection model.
  *
  * @param Entity $protection
  *
  * @return Config[]
  */
 public static function transform(Entity $protection)
 {
     $return = array();
     $path = sprintf(self::path, $protection->getDomain()->getPath(), $protection->getId());
     foreach ($protection->getProtectionuser() as $user) {
         /** @var EntityUser $user */
         $model = new Config();
         $model->setUsername($user->getUsername())->setPassword($user->getPassword())->setPath($path)->setId($user->getProtection()->getId());
         $return[] = $model;
     }
     return $return;
 }
 /**
  * Provides protections.
  *
  * @return array
  */
 public function dataProvider()
 {
     $domain = new Domain();
     $domain->setPath('/var/www/test.de');
     $protection = new Protection($domain);
     $user1 = new ProtectionUser($domain, $protection);
     $user2 = new ProtectionUser($domain, $protection);
     $user1->setUsername('test1')->setPassword('pw1');
     $user2->setUsername('test2')->setPassword('pw2');
     $collection = new ArrayCollection(array($user1, $user2));
     $protection->setProtectionuser($collection)->setId(1)->setPath('/var/www/test.de/htdocs/test');
     return array(array($protection));
 }
 /**
  * Test createAuthUserFile().
  */
 public function testCreateAuthUserFile()
 {
     $fs = new Filesystem();
     $fs->mkdir(sys_get_temp_dir() . '/conf');
     $domain = new Domain();
     $protection = new Protection($domain);
     $protectionuser = new ProtectionUser($domain, $protection);
     $domain->setPath(sys_get_temp_dir());
     $protection->setId(1)->setProtectionuser(new ArrayCollection(array($protectionuser)));
     $protectionuser->setUsername('test')->setPassword('tester')->setProtection($protection);
     $this->getService()->createAuthUserFile($protection);
     $this->assertFileExists(sys_get_temp_dir() . '/conf/authuser_1.passwd');
 }
 /**
  * Create auth user file for given protection.
  *
  * @param Protection $protection
  */
 public function createAuthUserFile(Protection $protection)
 {
     $path = sprintf('%s/conf/authuser_%s.passwd', $protection->getDomain()->getPath(), $protection->getId());
     $content = $this->renderAuthUserFile($this->transformEntity($protection));
     file_put_contents($path, $content);
 }