fileManager = $this->getMockBuilder(AbstractFileManager::class)->disableOriginalConstructor()->getMock(); } public function testGetFunctions(): void { $assetsExtension = $this ->getMockBuilder(AssetsExtension::class) ->setConstructorArgs([$this->fileManager]) ->setMethodsExcept(['getFunctions']) ->getMock(); $functions = $assetsExtension->getFunctions(); $this->assertCount(2, $functions); $this->assertEquals('absPath', $functions[0]->getName()); $this->assertEquals('toBase64Src', $functions[1]->getName()); } public function testAbsPath(): void { $assetsExtension = $this ->getMockBuilder(AssetsExtension::class) ->setConstructorArgs([$this->fileManager]) ->setMethodsExcept(['absPath']) ->getMock(); $publicDir = Path::getProjectDir(); $this->assertEquals( $publicDir . '/public/foo', $assetsExtension->absPath('foo') ); $this->assertEquals( $publicDir . '/public/foo/bar', $assetsExtension->absPath('foo/bar') ); $this->assertEquals( $publicDir . '/public', $assetsExtension->absPath('') ); } public function testToBase64Src(): void { $assetsExtension = $this ->getMockBuilder(AssetsExtension::class) ->setConstructorArgs([$this->fileManager]) ->setMethodsExcept(['toBase64Src']) ->getMock(); $file = $this->getMockBuilder(File::class)->getMock(); $file->method('getMimeType')->willReturn('mime'); $this->fileManager->method('read')->with($file)->willReturn('foo'); $this->assertEquals( 'data:mime;base64,' . base64_encode('foo'), $assetsExtension->toBase64Src($file) ); } }