]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix tests 3978/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Wed, 22 Mar 2017 12:26:18 +0000 (13:26 +0100)
committerRoeland Jago Douma <roeland@famdouma.nl>
Wed, 22 Mar 2017 19:14:18 +0000 (20:14 +0100)
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
tests/lib/Template/SCSSCacherTest.php

index b345c67387193679100245b351ce2544b006d8e2..898ea89cf4030ec66c0aad523a8d7ed6731e660b 100644 (file)
@@ -46,6 +46,8 @@ class SCSSCacherTest extends \Test\TestCase {
        protected $defaults;
        /** @var SCSSCacher */
        protected $scssCacher;
+       /** @var ICache|\PHPUnit_Framework_MockObject_MockObject */
+       protected $depsCache;
 
        protected function setUp() {
                parent::setUp();
@@ -53,13 +55,14 @@ class SCSSCacherTest extends \Test\TestCase {
                $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
                );
        }
 
@@ -70,11 +73,22 @@ class SCSSCacherTest extends \Test\TestCase {
                $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);
        }
@@ -85,66 +99,110 @@ class SCSSCacherTest extends \Test\TestCase {
                $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() {