From: Roeland Jago Douma Date: Wed, 22 Mar 2017 12:26:18 +0000 (+0100) Subject: Fix tests X-Git-Tag: v12.0.0beta1~332^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=35a21b418061cb8e4b1cad6b9cae6f659d7869f4;p=nextcloud-server.git Fix tests Signed-off-by: Roeland Jago Douma --- diff --git a/tests/lib/Template/SCSSCacherTest.php b/tests/lib/Template/SCSSCacherTest.php index b345c673871..898ea89cf40 100644 --- a/tests/lib/Template/SCSSCacherTest.php +++ b/tests/lib/Template/SCSSCacherTest.php @@ -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() {