From db71398bd6d506e34c2939e8feade2b1800bd52a Mon Sep 17 00:00:00 2001 From: Aidas Klimas Date: Mon, 9 Dec 2024 15:05:44 +0200 Subject: [PATCH] fix tests --- test/Unit/FileTest.php | 11 +++++------ test/Unit/FustyRequestTest.php | 9 ++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/test/Unit/FileTest.php b/test/Unit/FileTest.php index 61bf181..05b8f1f 100644 --- a/test/Unit/FileTest.php +++ b/test/Unit/FileTest.php @@ -245,8 +245,6 @@ public function testFile_deleteChunks() */ public function testFile_saveChunk() { - //// Setup test - // Setup temporary file $tmpDir = new vfsStreamDirectory('tmp'); $tmpFile = vfsStream::newFile('tmpFile'); @@ -257,18 +255,19 @@ public function testFile_saveChunk() // Mock File to use rename instead of move_uploaded_file $request = new Request($this->requestArr, $this->filesArr['file']); - $file = $this->createMock('Flow\File'); //, ['_move_uploaded_file'], [$this->config, $request]); + $file = $this->createPartialMock(File::class, ['_move_uploaded_file']); $file->expects($this->once()) ->method('_move_uploaded_file') - ->will($this->returnCallback(static function ($filename, $destination) { + ->willReturnCallback(static function (string $filename, string $destination): bool { return rename($filename, $destination); - })); + }); + $file->__construct($this->config, $request); + // Expected destination file $expDstFile = $this->vfs->url().DIRECTORY_SEPARATOR.sha1($request->getIdentifier()).'_1'; //// Accrual test - $this->assertFalse(file_exists($expDstFile)); $this->assertTrue(file_exists($tmpFile->url())); diff --git a/test/Unit/FustyRequestTest.php b/test/Unit/FustyRequestTest.php index 618b254..a91bf6c 100644 --- a/test/Unit/FustyRequestTest.php +++ b/test/Unit/FustyRequestTest.php @@ -71,8 +71,6 @@ public function testFustyRequest_construct() public function testFustyRequest_ValidateUpload() { - //// Setup test - $firstChunk = vfsStream::newFile('temp_file'); $firstChunk->setContent('1234567890'); $this->vfs->addChild($firstChunk); @@ -94,14 +92,15 @@ public function testFustyRequest_ValidateUpload() $config = new Config(); $config->setTempDir($this->vfs->url()); - $file = $this->createMock('Flow\File');//, ['_move_uploaded_file'], [$config, $fustyRequest]); + $file = $this->createPartialMock(File::class, ['_move_uploaded_file']); + $file->__construct($config, $fustyRequest); /** @noinspection PhpUndefinedMethodInspection */ $file->expects($this->once()) ->method('_move_uploaded_file') - ->will($this->returnCallback(static function ($filename, $destination) { + ->willReturnCallback(static function ($filename, $destination) { return rename($filename, $destination); - })); + }); //// Actual test