protected $defaults;
/** @var SCSSCacher */
protected $scssCacher;
+ /** @var ICache|\PHPUnit_Framework_MockObject_MockObject */
+ protected $depsCache;
protected function setUp() {
parent::setUp();
$this->appData = $this->createMock(IAppData::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->config = $this->createMock(IConfig::class);
+ $this->depsCache = $this->createMock(ICache::class);
$this->scssCacher = new SCSSCacher(
$this->logger,
$this->appData,
$this->urlGenerator,
$this->config,
\OC::$SERVERROOT,
- $this->createMock(ICache::class)
+ $this->depsCache
);
}
$file = $this->createMock(ISimpleFile::class);
$file->expects($this->any())->method('getSize')->willReturn(1);
$fileDeps = $this->createMock(ISimpleFile::class);
- $folder->expects($this->at(0))->method('getFile')->with('styles.css')->willReturn($file);
- $folder->expects($this->at(1))->method('getFile')->with('styles.css.deps')->willThrowException(new NotFoundException());
- $folder->expects($this->at(2))->method('getFile')->with('styles.css')->willReturn($file);
- $folder->expects($this->at(3))->method('getFile')->with('styles.css.deps')->willThrowException(new NotFoundException());
- $folder->expects($this->at(4))->method('newFile')->with('styles.css.deps')->willReturn($fileDeps);
+
+ $folder->method('getFile')
+ ->will($this->returnCallback(function($path) use ($file) {
+ if ($path === 'styles.css') {
+ return $file;
+ } else if ($path === 'styles.css.deps') {
+ throw new NotFoundException();
+ } else {
+ $this->fail();
+ }
+ }));
+ $folder->expects($this->once())
+ ->method('newFile')
+ ->with('styles.css.deps')
+ ->willReturn($fileDeps);
+
$actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
$this->assertTrue($actual);
}
$file = $this->createMock(ISimpleFile::class);
$file->expects($this->any())->method('getSize')->willReturn(1);
$fileDeps = $this->createMock(ISimpleFile::class);
- $folder->expects($this->at(0))->method('getFile')->with('styles.css')->willReturn($file);
- $folder->expects($this->at(1))->method('getFile')->with('styles.css.deps')->willThrowException(new NotFoundException());
- $folder->expects($this->at(2))->method('getFile')->with('styles.css')->willReturn($file);
- $folder->expects($this->at(3))->method('getFile')->with('styles.css.deps')->willThrowException(new NotFoundException());
- $folder->expects($this->at(4))->method('newFile')->with('styles.css.deps')->willReturn($fileDeps);
+
+ $folder->method('getFile')
+ ->will($this->returnCallback(function($path) use ($file) {
+ if ($path === 'styles.css') {
+ return $file;
+ } else if ($path === 'styles.css.deps') {
+ throw new NotFoundException();
+ } else {
+ $this->fail();
+ }
+ }));
+ $folder->expects($this->once())
+ ->method('newFile')
+ ->with('styles.css.deps')
+ ->willReturn($fileDeps);
+
$actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
$this->assertTrue($actual);
}
- public function testProcessCacheFile() {
+ public function testProcessCachedFile() {
$folder = $this->createMock(ISimpleFolder::class);
$this->appData->expects($this->once())->method('getFolder')->with('core')->willReturn($folder);
$file = $this->createMock(ISimpleFile::class);
- $file->expects($this->any())->method('getSize')->willReturn(1);
+ $file->expects($this->once())->method('getSize')->willReturn(1);
$fileDeps = $this->createMock(ISimpleFile::class);
$fileDeps->expects($this->any())->method('getSize')->willReturn(1);
$fileDeps->expects($this->once())->method('getContent')->willReturn('{}');
- $folder->expects($this->at(0))->method('getFile')->with('styles.css')->willReturn($file);
- $folder->expects($this->at(1))->method('getFile')->with('styles.css.deps')->willReturn($fileDeps);
+
+ $folder->method('getFile')
+ ->will($this->returnCallback(function($path) use ($file, $fileDeps) {
+ if ($path === 'styles.css') {
+ return $file;
+ } else if ($path === 'styles.css.deps') {
+ return $fileDeps;
+ } else {
+ $this->fail();
+ }
+ }));
+
$actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
$this->assertTrue($actual);
}
- public function testProcessCachedFile() {
+ public function testProcessCachedFileMemcache() {
$folder = $this->createMock(ISimpleFolder::class);
- $this->appData->expects($this->once())->method('getFolder')->with('core')->willReturn($folder);
+ $this->appData->expects($this->once())
+ ->method('getFolder')
+ ->with('core')
+ ->willReturn($folder);
+ $folder->method('getName')
+ ->willReturn('core');
+
$file = $this->createMock(ISimpleFile::class);
- $file->expects($this->once())->method('getSize')->willReturn(1);
- $fileDeps = $this->createMock(ISimpleFile::class);
- $fileDeps->expects($this->any())->method('getSize')->willReturn(1);
- $fileDeps->expects($this->once())->method('getContent')->willReturn('{}');
- $folder->expects($this->at(0))->method('getFile')->with('styles.css')->willReturn($file);
- $folder->expects($this->at(1))->method('getFile')->with('styles.css.deps')->willReturn($fileDeps);
+ $file->expects($this->once())
+ ->method('getSize')
+ ->willReturn(1);
+
+ $this->depsCache->method('get')
+ ->with('core-styles.css.deps')
+ ->willReturn('{}');
+
+ $folder->method('getFile')
+ ->will($this->returnCallback(function($path) use ($file) {
+ if ($path === 'styles.css') {
+ return $file;
+ } else if ($path === 'styles.css.deps') {
+ $this->fail();
+ } else {
+ $this->fail();
+ }
+ }));
+
$actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
$this->assertTrue($actual);
}
public function testIsCachedNoFile() {
$fileNameCSS = "styles.css";
- $fileNameSCSS = "styles.scss";
$folder = $this->createMock(ISimpleFolder::class);
- $path = \OC::$SERVERROOT . '/core/css/';
$folder->expects($this->at(0))->method('getFile')->with($fileNameCSS)->willThrowException(new NotFoundException());
- $actual = self::invokePrivate($this->scssCacher, 'isCached', [$fileNameCSS, $fileNameSCSS, $folder, $path]);
+ $actual = self::invokePrivate($this->scssCacher, 'isCached', [$fileNameCSS, $folder]);
$this->assertFalse($actual);
}
public function testIsCachedNoDepsFile() {
$fileNameCSS = "styles.css";
- $fileNameSCSS = "styles.scss";
$folder = $this->createMock(ISimpleFolder::class);
$file = $this->createMock(ISimpleFile::class);
- $path = \OC::$SERVERROOT . '/core/css/';
$file->expects($this->once())->method('getSize')->willReturn(1);
- $folder->expects($this->at(0))->method('getFile')->with($fileNameCSS)->willReturn($file);
- $folder->expects($this->at(1))->method('getFile')->with($fileNameCSS . '.deps')->willThrowException(new NotFoundException());
+ $folder->method('getFile')
+ ->will($this->returnCallback(function($path) use ($file) {
+ if ($path === 'styles.css') {
+ return $file;
+ } else if ($path === 'styles.css.deps') {
+ throw new NotFoundException();
+ } else {
+ $this->fail();
+ }
+ }));
- $actual = self::invokePrivate($this->scssCacher, 'isCached', [$fileNameCSS, $fileNameSCSS, $folder, $path]);
+ $actual = self::invokePrivate($this->scssCacher, 'isCached', [$fileNameCSS, $folder]);
$this->assertFalse($actual);
}
public function testCacheNoFile() {