コード例 #1
0
 /**
  * @dataProvider getEntity
  *
  * @param bool $is_successful
  * @param string $entity
  */
 public function testEntity($is_successful, $entity)
 {
     $file = $this->dir . 'bar/foo';
     $url = 'http://example.com/test/foo';
     mkdir($this->dir . 'bar');
     file_put_contents($file, base64_decode(self::IMAGE));
     $this->download($file, $is_successful, $url);
     /* @var $entity \PHPUnit_Framework_MockObject_MockObject|EntityInterface */
     $entity = $this->getMock($entity);
     $entity->expects($this->once())->method('setFilename')->with('foo');
     $entity->expects($this->once())->method('getFilename')->will($this->returnValue('foo'));
     $entity->expects($this->once())->method('getDownloadPath')->will($this->returnValue('bar'));
     // test
     $actual = $this->downloader->entity($url, $entity, true);
     $this->assertEquals($is_successful, $actual);
 }
コード例 #2
0
ファイル: Package.php プロジェクト: anime-db/app-bundle
 /**
  * Add plugin from package.
  *
  * @param ComposerPackage $package
  */
 protected function addPackage(ComposerPackage $package)
 {
     $plugin = $this->rep->find($package->getName());
     // create new plugin if not exists
     if (!$plugin) {
         $plugin = new Plugin();
         $plugin->setName($package->getName());
     }
     list($vendor, $package) = explode('/', $plugin->getName());
     try {
         $data = $this->client->getPlugin($vendor, $package);
         $plugin->setTitle($data['title'])->setDescription($data['description']);
         if ($data['logo']) {
             $this->downloader->entity($data['logo'], $plugin, true);
         }
     } catch (\Exception $e) {
         // is not a critical error
     }
     $this->em->persist($plugin);
     $this->em->flush();
 }