Skip to content

Commit

Permalink
test: Remove php-mock dep leftover
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitpokhrel committed Oct 31, 2020
1 parent ff420fd commit a255ea8
Showing 1 changed file with 3 additions and 164 deletions.
167 changes: 3 additions & 164 deletions tests/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,18 +17,14 @@ class FileTest extends TestCase
/** @var File */
protected $file;

/** @var MockBuilder */
protected $mockBuilder;

/**
* Prepare vars.
*
* @return void
*/
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');

Expand Down Expand Up @@ -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();
}

/**
Expand All @@ -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
*
Expand All @@ -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);
Expand All @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -742,27 +610,13 @@ 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)
->upload($totalBytes);

$this->assertEquals($totalBytes, $bytesWritten);

$mock->disable();

@unlink($file);
}

Expand All @@ -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);
Expand All @@ -800,27 +653,13 @@ 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)
->upload($totalBytes);

$this->assertEquals($totalBytes, $bytesWritten);

$mock->disable();

@unlink($file);
}

Expand Down

0 comments on commit a255ea8

Please sign in to comment.