コード例 #1
0
 /**
  * @dataProvider getEntity
  *
  * @param \PHPUnit_Framework_MockObject_MockObject $entity
  * @param string $filename
  */
 public function testPrePersist(\PHPUnit_Framework_MockObject_MockObject $entity, $filename)
 {
     $this->args->expects($this->once())->method('getEntity')->will($this->returnValue($entity));
     if ($entity instanceof Item || $entity instanceof Image) {
         /* @var $entity \PHPUnit_Framework_MockObject_MockObject|Item|Image */
         $time = $this->getMock('\\DateTime');
         $time->expects($this->once())->method('format')->with('Y/m/d/His/')->will($this->returnValue('some/path'));
         if ($entity instanceof Item) {
             $entity->expects($this->once())->method('getDateAdd')->will($this->returnValue($time));
         } else {
             $item = $this->getMock('\\AnimeDb\\Bundle\\CatalogBundle\\Entity\\Item');
             $entity->expects($this->once())->method('getItem')->will($this->returnValue($item));
             $item->expects($this->once())->method('getDateAdd')->will($this->returnValue($time));
         }
         $entity->expects($this->at(1))->method('getFilename')->will($this->returnValue($filename));
         if ($filename) {
             $entity->expects($this->at(2))->method('getFilename')->will($this->returnValue($filename));
         }
         if (strpos($filename, 'tmp') !== false) {
             $entity->expects($this->at(3))->method('getFilename')->will($this->returnValue($filename));
             $entity->expects($this->at(6))->method('getFilename')->will($this->returnValue('new_filename'));
             $entity->expects($this->once())->method('setFilename')->with('some/path' . pathinfo($filename, PATHINFO_BASENAME));
             $entity->expects($this->once())->method('getDownloadPath')->will($this->returnValue('web'));
             $this->fs->expects($this->once())->method('copy')->with($this->root . 'web/' . $filename, $this->root . 'web/new_filename', true);
         }
     } else {
         $entity->expects($this->never())->method('getFilename');
     }
     $this->listener->prePersist($this->args);
 }
コード例 #2
0
ファイル: ConverterTest.php プロジェクト: Dossar/boltbse
 public function testFileIsNotBackedUp()
 {
     $this->fs->expects($this->once())->method('exists')->with($this->yamlFile)->will($this->returnValue(true));
     $this->fs->expects($this->never())->method('copy');
     $this->fs->expects($this->once())->method('dumpFile')->with($this->phpFile, $this->php);
     $this->converter->convertFile($this->yamlFile, false);
 }
コード例 #3
0
 public function testLoadSavedObject()
 {
     $className = uniqid('Tmp');
     $this->filesystem->expects($this->once())->method('exists')->with($this->equalTo('/tmp/' . $className . 'Serializer.php'))->will($this->returnValue(true));
     file_put_contents('/tmp/' . $className . 'Serializer.php', '<?php class ' . $className . 'Serializer {}');
     $serializer = $this->createCache()->load($className);
     $this->assertInstanceOf($className . 'Serializer', $serializer);
     unlink('/tmp/' . $className . 'Serializer.php');
 }
コード例 #4
0
 /**
  * Tests cacheAction() method.
  */
 public function testCacheAction()
 {
     // Given
     $this->filesystem->expects($this->once())->method('exists')->will($this->returnValue(true));
     $this->filesystem->expects($this->once())->method('remove');
     // When
     $response = $this->cache->cacheAction('token', 'translations');
     // Then
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response);
     $this->assertEquals(200, $response->getStatusCode(), 'Response should be 200');
     $this->assertEquals('ok', $response->getContent(), 'Response should return "OK"');
     $this->assertEquals(2, $response->headers->get('Content-Length'));
     $this->assertEquals('must-revalidate, no-cache, private', $response->headers->get('Cache-Control'));
 }
コード例 #5
0
ファイル: EntityTest.php プロジェクト: anime-db/app-bundle
 /**
  * @dataProvider getOldFiles
  *
  * @param array $files
  */
 public function testRemoveFile(array $files)
 {
     $that = $this;
     $root = $this->root . 'bar/';
     $entity = $this->getMock('\\AnimeDb\\Bundle\\AppBundle\\Service\\Downloader\\Entity\\EntityInterface');
     $entity->expects($this->atLeastOnce())->method('getFilename')->will($this->returnValue('baz'));
     $entity->expects($this->atLeastOnce())->method('getDownloadPath')->will($this->returnValue('bar'));
     $entity->expects($this->once())->method('getOldFilenames')->will($this->returnValue($files));
     /* @var $args \PHPUnit_Framework_MockObject_MockObject|LifecycleEventArgs */
     $args = $this->getMockBuilder('\\Doctrine\\ORM\\Event\\LifecycleEventArgs')->disableOriginalConstructor()->getMock();
     $args->expects($this->atLeastOnce())->method('getEntity')->will($this->returnValue($entity));
     $this->fs->expects($this->atLeastOnce())->method('remove')->will($this->returnCallback(function ($file) use($files, $root, $that) {
         $filename = pathinfo($file, PATHINFO_BASENAME);
         if ($filename == 'baz') {
             // origin file
             $that->assertEquals($root . 'baz', $file);
         } else {
             // old files
             $that->assertContains($filename, $files);
             $that->assertEquals($root . $filename, $file);
         }
     }));
     // test
     $this->listener->postRemove($args);
 }
 /**
  * @test
  */
 public function thatFileRemoves()
 {
     $this->fileInfo = $this->getFileInfoInstance(self::DUMMY_REAL_PATH, true, true);
     $this->localFileStorageService = $this->getLocalFileStorageServiceInstance($this->fileInfo);
     $this->fs->expects($this->once())->method('remove')->with($this->equalTo(self::DUMMY_REAL_PATH . DIRECTORY_SEPARATOR . self::DUMMY_FILENAME));
     $this->localFileStorageService->remove(self::DUMMY_FILENAME);
 }
コード例 #7
0
 public function testConfirmException()
 {
     $this->request->expects($this->once())->method('get')->with('token')->willReturn('awesome-token');
     $this->filesystem->expects($this->once())->method('exists')->with(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'awesome-token' . '.txt')->willReturn(true);
     $this->mollieAPIClient->payments = $this->payments;
     $this->payments->expects($this->once())->method('get')->with('test')->willThrowException(new Mollie_API_Exception());
     $this->assertFalse($this->mollieDriver->confirm($this->request));
 }
コード例 #8
0
ファイル: CssRewriterTest.php プロジェクト: blazarecki/lug
 /**
  * @expectedException \Lug\Component\Assetic\Exception\PathNotFoundException
  * @expectedExceptionMessage The asset "source_root/foo.jpg" could not be found.
  */
 public function testRewriteWithNonexistentSourcePath()
 {
     $asset = $this->createAssetMock();
     $asset->expects($this->once())->method('getSourceRoot')->will($this->returnValue($sourceRoot = 'source_root'));
     $asset->expects($this->exactly(2))->method('getSourcePath')->will($this->returnValue($sourcePath = 'source_path'));
     $asset->expects($this->once())->method('getTargetPath')->will($this->returnValue($targetPath = 'target_path'));
     $reference = $this->createReference($path = 'foo.jpg');
     $this->filesystem->expects($this->once())->method('exists')->with($this->identicalTo($sourceRoot . DIRECTORY_SEPARATOR . $path))->will($this->returnValue(false));
     $this->cssRewriter->rewrite($reference, $asset);
 }
コード例 #9
0
 /**
  * Tests the dump() method with an entity.
  */
 public function testDumpWithAnEntity()
 {
     if (!method_exists($this->filesystem, 'dumpFile')) {
         $this->markTestSkipped('Test skipped as Filesystem::dumpFile() is not available in this version.');
     }
     // Given
     $this->service->setRootDir('/unit/test/');
     $this->service->setFilename('feed.rss');
     $this->service->setEntity('Eko\\FeedBundle\\Tests\\Entity\\Writer\\FakeItemInterfaceEntity');
     $this->service->setDirection('ASC');
     $entity = $this->getMock('Eko\\FeedBundle\\Tests\\Entity\\Writer\\FakeItemInterfaceEntity');
     $repository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
     $repository->expects($this->once())->method('findBy')->will($this->returnValue([$entity, $entity]));
     $this->entityManager->expects($this->once())->method('getRepository')->will($this->returnValue($repository));
     $feed = $this->getMockBuilder('Eko\\FeedBundle\\Feed\\Feed')->disableOriginalConstructor()->getMock();
     $feed->expects($this->once())->method('addFromArray');
     $feed->expects($this->once())->method('render')->will($this->returnValue('XML content'));
     $this->feedManager->expects($this->once())->method('get')->will($this->returnValue($feed));
     $this->filesystem->expects($this->once())->method('dumpFile')->with('/unit/test/feed.rss', 'XML content');
     // When - Expects actions
     $this->service->dump();
 }
コード例 #10
0
 public function testPostUpdate()
 {
     $file1 = $this->root . 'foo/' . Storage::ID_FILE;
     $file2 = $this->root . 'bar/' . Storage::ID_FILE;
     $storage = $this->getMock('\\AnimeDb\\Bundle\\CatalogBundle\\Entity\\Storage');
     $storage->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(123));
     $storage->expects($this->atLeastOnce())->method('getPath')->will($this->returnValue('baz'));
     $storage->expects($this->once())->method('getOldPaths')->will($this->returnValue([dirname($file1) . '/', dirname($file2) . '/']));
     $this->fs->expects($this->at(0))->method('exists')->will($this->returnValue(true))->with($file1);
     $this->fs->expects($this->at(2))->method('exists')->will($this->returnValue(true))->with($file2);
     $this->fs->expects($this->at(4))->method('exists')->will($this->returnValue(true))->with('baz');
     $this->fs->expects($this->at(5))->method('exists')->will($this->returnValue(false))->with('baz' . Storage::ID_FILE);
     $this->fs->expects($this->at(1))->method('remove')->with($file1);
     $this->fs->expects($this->at(3))->method('remove')->with($file2);
     $this->fs->expects($this->once())->method('dumpFile')->with('baz' . Storage::ID_FILE, 123, 0666);
     $this->real_fs->dumpFile($file1, 123);
     $this->real_fs->dumpFile($file2, 123);
     $this->storage->postUpdate($this->getArgs($storage));
 }
コード例 #11
0
 /**
  * @param string $target
  * @param bool $is_successful
  * @param string $url
  */
 protected function download($target, $is_successful = true, $url = '')
 {
     $this->fs->expects($this->once())->method('mkdir')->with(dirname($target), 0755);
     $this->request->expects($this->once())->method('setResponseBody')->will($this->returnSelf())->with($target);
     $this->dialog($is_successful, $url);
 }
コード例 #12
0
ファイル: WsdlManagerTest.php プロジェクト: antrampa/crm
 /**
  * @param string $path
  */
 protected function assertClearCache($path)
 {
     $this->fs->expects($this->once())->method('exists')->with($path)->willReturn(true);
     $this->fs->expects($this->once())->method('remove')->with($path);
 }
コード例 #13
0
 public function testExecuteUpdateItself()
 {
     $tag = ['name' => '1.1.0-alpha', 'zipball_url' => 'http://example.com/tags/1.0.1.zip'];
     $dispatcher = $this->getMock('\\Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $local_dispatcher = $this->getMockBuilder('\\AnimeDb\\Bundle\\AnimeDbBundle\\Event\\Dispatcher')->disableOriginalConstructor()->getMock();
     $package = $this->getMock('\\Composer\\Package\\RootPackageInterface');
     // vars for closures
     $that = $this;
     $fs = $this->fs;
     $root_dir = $this->root_dir;
     $target = $this->target;
     $root_package = $this->package;
     // create files for Finder
     $this->fs->mkdir([$this->root_dir . 'app/cache', $this->root_dir . 'app/DoctrineMigrations/', $this->root_dir . 'app/Resources/views/', $this->root_dir . 'app/config/', $this->root_dir . 'src/Tests/', $this->root_dir . 'src/Console']);
     $this->fs->touch([$this->root_dir . 'app/bootstrap.php.cache', $this->root_dir . 'app/DoctrineMigrations/Version11111111111111_Demo.php', $this->root_dir . 'app/Resources/views/base.html.twig', $this->root_dir . 'app/config/config.yml', $this->root_dir . 'src/AnimeDbAnimeDbBundle.php', $this->root_dir . 'src/Tests/TestCaseWritable.php']);
     // init command
     $command = $this->getCommandToExecute($tag, '1.0.0', 0);
     $this->write(['Discovered a new version of the application: <info>' . $tag['name'] . '</info>', '<info>Update itself has been completed</info>', '<info>Update requirements has been completed</info>', '<info>Updating the application has been completed<info>']);
     $this->container->expects($this->at(2))->method('get')->will($this->returnValue($this->filesystem))->with('filesystem');
     $this->container->expects($this->at(3))->method('get')->will($this->returnValue($dispatcher))->with('event_dispatcher');
     $this->container->expects($this->at(4))->method('get')->will($this->returnValue($this->filesystem))->with('filesystem');
     $this->container->expects($this->at(8))->method('get')->will($this->returnValue($local_dispatcher))->with('anime_db.event_dispatcher');
     $this->container->expects($this->atLeastOnce())->method('getParameter')->will($this->returnValue($this->root_dir . 'app'))->with('kernel.root_dir');
     $this->composer->expects($this->once())->method('download')->will($this->returnCallback(function ($package, $_target) use($that, $target, $tag) {
         $that->assertEquals($target, $_target);
         // check package
         /* @var $package Package */
         $that->assertInstanceOf('\\Composer\\Package\\Package', $package);
         $that->assertEquals('anime-db/anime-db', $package->getName());
         $that->assertEquals(Composer::getVersionCompatible($tag['name']), $package->getVersion());
         $that->assertEquals($tag['name'], $package->getPrettyVersion());
         $that->assertEquals('zip', $package->getDistType());
         $that->assertEquals($tag['zipball_url'], $package->getDistUrl());
         $that->assertEquals('dist', $package->getInstallationSource());
     }));
     $this->composer->expects($this->once())->method('getPackageFromConfigFile')->with($this->target . '/composer.json')->will($this->returnValue($package));
     $this->composer->expects($this->once())->method('reload');
     $dispatcher->expects($this->once())->method('dispatch')->will($this->returnCallback(function ($name, $event) use($that, $target, $package, $root_package) {
         $that->assertEquals(StoreEvents::DOWNLOADED, $name);
         // check event
         /* @var $event Downloaded */
         $that->assertInstanceOf('\\AnimeDb\\Bundle\\AnimeDbBundle\\Event\\UpdateItself\\Downloaded', $event);
         $that->assertEquals($target, $event->getPath());
         $that->assertEquals($package, $event->getNewPackage());
         $that->assertEquals($root_package, $event->getOldPackage());
     }));
     $local_dispatcher->expects($this->once())->method('dispatch')->will($this->returnCallback(function ($name, $event) use($that, $package) {
         $that->assertEquals(StoreEvents::UPDATED, $name);
         /* @var $event Updated */
         $that->assertInstanceOf('\\AnimeDb\\Bundle\\AnimeDbBundle\\Event\\UpdateItself\\Updated', $event);
         $that->assertEquals($package, $event->getPackage());
     }));
     $this->filesystem->expects($this->at(0))->method('remove')->with($this->target);
     $this->filesystem->expects($this->at(1))->method('remove')->will($this->returnCallback(function ($finder) use($that, $fs, $root_dir) {
         $that->assertInstanceOf('\\Symfony\\Component\\Finder\\Finder', $finder);
         // test remove files from Finder
         $fs->remove($finder);
         $that->assertFileExists($root_dir . 'app/bootstrap.php.cache');
         $that->assertFileExists($root_dir . 'app/DoctrineMigrations/Version11111111111111_Demo.php');
         $that->assertFileExists($root_dir . 'app/Resources/views/base.html.twig');
         $that->assertFileExists($root_dir . 'app/config');
         $that->assertFileExists($root_dir . 'src/Console');
         $that->assertFileNotExists($root_dir . 'app/config/config.yml');
         $that->assertFileNotExists($root_dir . 'src/AnimeDbAnimeDbBundle.php');
         $that->assertFileNotExists($root_dir . 'src/Tests/TestCaseWritable.php');
     }));
     $this->filesystem->expects($this->at(3))->method('remove')->with($this->target);
     $this->filesystem->expects($this->once())->method('mirror')->with($this->target, $this->root_dir . 'app/../', null, ['override' => true, 'copy_on_windows' => true]);
     $command->run($this->input, $this->output);
     // test
 }