Ejemplo n.º 1
0
 public function testWrite()
 {
     $path = '/test';
     $filename = 'MyClass.php';
     $generatedClassProvider = Mockery::mock(GeneratedClassMetaDataProvider::class);
     $generatedClassProvider->shouldReceive('getFilePath')->times(1)->withNoArgs()->andReturn($path);
     $generatedClassProvider->shouldReceive('getFilenameShort')->times(1)->withNoArgs()->andReturn($filename);
     $cacheWriter = new CacheWriter(self::$cacheDir);
     $cacheWriter->write($generatedClassProvider, 'test');
     $fileContents = file_get_contents(self::$cacheDir . '/retrofit' . $path . '/' . $filename);
     $this->assertEquals("<?php\ntest", $fileContents);
 }
Ejemplo n.º 2
0
 /**
  * Creates cache file based on registered services
  *
  * If debug is false, it will only create the cache file if it doesn't already exist
  *
  * @return int Number of services cached
  */
 public function createCache()
 {
     $lockHandler = new LockHandler(self::RETROFIT_LOCK_FILE);
     $lockHandler->lock(true);
     // loop through registered services and write to file
     foreach ($this->services as $service) {
         $classMetaDataProvider = new ClassMetaDataProvider($service);
         $generatedClassMetaDataProvider = new GeneratedClassMetaDataProvider($classMetaDataProvider);
         $generatedClass = $this->restClientGenerator->generate($classMetaDataProvider, $generatedClassMetaDataProvider);
         $this->cacheWriter->write($generatedClassMetaDataProvider, $generatedClass);
     }
     $lockHandler->release();
     return count($this->services);
 }