public function testGetUniqueFilename() { $filename = $this->dir . 'foo.txt'; touch($new = $this->downloader->getUniqueFilename($filename)); $this->assertEquals($this->dir . 'foo.txt', $new); touch($new = $this->downloader->getUniqueFilename($filename)); $this->assertEquals($this->dir . 'foo[1].txt', $new); $this->assertEquals($this->dir . 'foo[2].txt', $this->downloader->getUniqueFilename($filename)); }
/** * @param array $data * * @return \PHPUnit_Framework_MockObject_MockObject */ protected function getPlugin(array $data = []) { $plugin = $this->getMock('\\AnimeDb\\Bundle\\AppBundle\\Entity\\Plugin'); $plugin->expects($this->once())->method('getName')->will($this->returnValue('foo/bar')); $setters = ['title' => 'setTitle', 'description' => 'setDescription']; foreach ($setters as $key => $method) { if (empty($data[$key])) { $plugin->expects($this->never())->method($method); } else { $plugin->expects($this->once())->method($method)->with($data[$key])->will($this->returnSelf()); } } $this->downloader->expects(!empty($data['logo']) ? $this->once() : $this->never())->method('entity')->with($data['logo'], $plugin, true); return $plugin; }
/** * 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(); }
/** * @param string $url * @param EntityInterface $entity * * @return bool */ protected function uploadImageFromUrl($url, EntityInterface $entity) { return $this->downloader->image($url, $this->downloader->getRoot() . $entity->getWebPath()); }