diff --git a/tests/FileTest.php b/tests/FileTest.php index 1c32aab1..21a3445f 100644 --- a/tests/FileTest.php +++ b/tests/FileTest.php @@ -4,7 +4,6 @@ use TusPhp\File; use Mockery as m; -use phpmock\MockBuilder; use TusPhp\Cache\FileStore; use TusPhp\Cache\CacheFactory; use PHPUnit\Framework\TestCase; @@ -18,9 +17,6 @@ class FileTest extends TestCase /** @var File */ protected $file; - /** @var MockBuilder */ - protected $mockBuilder; - /** * Prepare vars. * @@ -28,8 +24,7 @@ class FileTest extends TestCase */ public function setUp() { - $this->file = new File('tus.txt', CacheFactory::make()); - $this->mockBuilder = (new MockBuilder)->setNamespace('\TusPhp'); + $this->file = new File('tus.txt', CacheFactory::make()); $this->file->setMeta(100, 1024, '/path/to/file.txt', 'http://tus.local/uploads/file.txt'); @@ -272,25 +267,11 @@ public function it_throws_file_exception_if_file_doesnt_exists_for_read_mode() */ public function it_throws_exception_if_it_cannot_seek() { - $this->mockBuilder - ->setName('fseek') - ->setFunction( - function () { - return -1; - } - ); - - $mock = $this->mockBuilder->build(); - - $mock->enable(); - $file = __DIR__ . '/Fixtures/empty.txt'; $handle = $this->file->open($file, 'r'); - $this->file->seek($handle, 5); + $this->file->seek($handle, -1); $this->file->close($handle); - - $mock->disable(); } /** @@ -312,39 +293,6 @@ public function it_moves_to_proper_location_in_a_file() $this->file->close($handle); } - /** - * @test - * - * @covers ::read - * - * @runInSeparateProcess - * - * @expectedException \TusPhp\Exception\FileException - * @expectedExceptionMessage Cannot read file. - */ - public function it_throws_exception_if_it_cannot_read() - { - $this->mockBuilder - ->setName('fread') - ->setFunction( - function () { - return false; - } - ); - - $mock = $this->mockBuilder->build(); - - $mock->enable(); - - $file = __DIR__ . '/Fixtures/empty.txt'; - $handle = $this->file->open($file, 'r'); - - $this->file->read($handle, 5); - $this->file->close($handle); - - $mock->disable(); - } - /** * @test * @@ -354,8 +302,7 @@ function () { */ public function it_reads_from_a_file() { - $file = __DIR__ . '/Fixtures/data.txt'; - + $file = __DIR__ . '/Fixtures/data.txt'; $handle = $this->file->open($file, 'r'); $this->file->seek($handle, 49); @@ -365,39 +312,6 @@ public function it_reads_from_a_file() $this->file->close($handle); } - /** - * @test - * - * @covers ::write - * - * @runInSeparateProcess - * - * @expectedException \TusPhp\Exception\FileException - * @expectedExceptionMessage Cannot write to a file. - */ - public function it_throws_exception_if_it_cannot_write() - { - $this->mockBuilder - ->setName('fwrite') - ->setFunction( - function () { - return false; - } - ); - - $mock = $this->mockBuilder->build(); - - $mock->enable(); - - $file = __DIR__ . '/Fixtures/empty.txt'; - $handle = $this->file->open($file, 'r'); - - $this->file->write($handle, ''); - $this->file->close($handle); - - $mock->disable(); - } - /** * @test * @@ -607,52 +521,6 @@ public function it_throws_404_if_source_file_not_found() $this->file->setOffset(10)->upload(100); } - /** - * @test - * - * @covers ::upload - * @covers ::open - * - * @runInSeparateProcess - * - * @expectedException \TusPhp\Exception\ConnectionException - * @expectedExceptionMessage Connection aborted by user. - */ - public function it_throws_connection_exception_if_connection_is_aborted_by_user() - { - $file = __DIR__ . '/.tmp/upload.txt'; - $key = uniqid(); - - $cacheMock = m::mock(FileStore::class); - $fileMock = m::mock(File::class, [null, $cacheMock])->makePartial(); - - $fileMock - ->shouldReceive('getKey') - ->once() - ->andReturn($key); - - $this->mockBuilder - ->setName('connection_status') - ->setFunction( - function () use ($key) { - return 1; - } - ); - - $mock = $this->mockBuilder->build(); - - $mock->enable(); - - $fileMock - ->setFilePath($file) - ->setOffset(0) - ->upload(100); - - $mock->disable(); - - @unlink($file); - } - /** * @test * @@ -742,18 +610,6 @@ public function it_uploads_a_chunk() ->with($key, ['offset' => $totalBytes]) ->andReturn(null); - $this->mockBuilder - ->setName('hash_file') - ->setFunction( - function () use ($checksum) { - return $checksum; - } - ); - - $mock = $this->mockBuilder->build(); - - $mock->enable(); - $bytesWritten = $fileMock ->setFilePath($file) ->setOffset(0) @@ -761,8 +617,6 @@ function () use ($checksum) { $this->assertEquals($totalBytes, $bytesWritten); - $mock->disable(); - @unlink($file); } @@ -778,7 +632,6 @@ public function it_uploads_complete_file() $file = __DIR__ . '/.tmp/upload.txt'; $data = file_get_contents(__DIR__ . '/Fixtures/data.txt'); $key = uniqid(); - $checksum = '74f02d6da32082463e382f2274e85fd8eae3e81f739f8959abc91865656e3b3a'; $totalBytes = \strlen($data); $cacheMock = m::mock(FileStore::class); @@ -800,18 +653,6 @@ public function it_uploads_complete_file() ->with($key, ['offset' => $totalBytes]) ->andReturn(null); - $this->mockBuilder - ->setName('hash_file') - ->setFunction( - function () use ($checksum) { - return $checksum; - } - ); - - $mock = $this->mockBuilder->build(); - - $mock->enable(); - $bytesWritten = $fileMock ->setFilePath($file) ->setOffset(0) @@ -819,8 +660,6 @@ function () use ($checksum) { $this->assertEquals($totalBytes, $bytesWritten); - $mock->disable(); - @unlink($file); }