Exemple #1
0
 /**
  * @param string $name
  * @param array  $config For available options see Repository::$config
  * @param string $label
  *
  * @return Repository
  */
 public function createRepository($name, array $config, $label = null)
 {
     $repository = new Repository($name, $config);
     $repository->setLabel($label);
     $repository->init($this->container);
     $this->em->persist($repository);
     $this->em->flush();
     return $repository;
 }
Exemple #2
0
 public function testInterceptors()
 {
     $itc = new DummyInterceptor();
     $interceptorsProvider = \Phake::mock('Modera\\FileRepositoryBundle\\Intercepting\\InterceptorsProviderInterface');
     \Phake::when($interceptorsProvider)->getInterceptors($this->isInstanceOf(Repository::clazz()))->thenReturn([$itc]);
     $container = \Phake::mock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     \Phake::when($container)->get('modera_file_repository.intercepting.interceptors_provider')->thenReturn($interceptorsProvider);
     $repository = new Repository('foo', array('filesystem' => 'foo'));
     $repository->init($container);
     $splFile = new \SplFileInfo(__FILE__);
     $storedFile = \Phake::mock(StoredFile::clazz());
     // ---
     $this->assertEquals(0, count($itc->beforePutInvocations));
     $repository->beforePut($splFile);
     $this->assertEquals(1, count($itc->beforePutInvocations));
     $this->assertSame($splFile, $itc->beforePutInvocations[0][0]);
     $this->assertSame($repository, $itc->beforePutInvocations[0][1]);
     // ---
     $receivedInterceptor = null;
     $repository->beforePut($splFile, function ($interceptor) use(&$receivedInterceptor) {
         $receivedInterceptor = $interceptor;
         return false;
     });
     $this->assertSame($itc, $receivedInterceptor);
     $this->assertEquals(1, count($itc->beforePutInvocations));
     // ---
     $this->assertEquals(0, count($itc->onPutInvocations));
     $repository->onPut($storedFile, $splFile);
     $this->assertEquals(1, count($itc->onPutInvocations));
     $this->assertSame($storedFile, $itc->onPutInvocations[0][0]);
     $this->assertSame($splFile, $itc->onPutInvocations[0][1]);
     $this->assertSame($repository, $itc->onPutInvocations[0][2]);
     // ---
     $receivedInterceptor = null;
     $repository->onPut($storedFile, $splFile, function ($interceptor) use(&$receivedInterceptor) {
         $receivedInterceptor = $interceptor;
         return false;
     });
     $this->assertSame($itc, $receivedInterceptor);
     $this->assertEquals(1, count($itc->onPutInvocations));
     // ---
     $this->assertEquals(0, count($itc->afterPutInvocations));
     $repository->afterPut($storedFile, $splFile);
     $this->assertEquals(1, count($itc->afterPutInvocations));
     $this->assertSame($storedFile, $itc->afterPutInvocations[0][0]);
     $this->assertSame($splFile, $itc->afterPutInvocations[0][1]);
     $this->assertSame($repository, $itc->afterPutInvocations[0][2]);
     $receivedInterceptor = null;
     $repository->afterPut($storedFile, $splFile, function ($interceptor) use(&$receivedInterceptor) {
         $receivedInterceptor = $interceptor;
         return false;
     });
     $this->assertSame($itc, $receivedInterceptor);
     $this->assertEquals(1, count($itc->afterPutInvocations));
 }