Skip to content

Commit

Permalink
fix: table definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Jure Bernava Prah committed May 19, 2021
1 parent 397aa59 commit e7a32e5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function up()

$table->integer('n');
$table->string('fs_file_id');
$table->binary('data');
$table->text('data');

$table->foreign('fs_file_id')
->references('id')
Expand Down
24 changes: 0 additions & 24 deletions src/Casts/Utf8Cast.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Models/FsFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function read(int $offset = 0, int $length = null): string
return file_get_contents($this->getPathFile(), false, $this->context(), ...func_get_args());
}

public function write($data, $append = true)
public function write($data, $append = false)
{
return file_put_contents($this->getPathFile(), $data, $append ? FILE_APPEND : 0, $this->context());
}
Expand Down
2 changes: 0 additions & 2 deletions src/Models/FsFileChunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use JBernavaPrah\EloquentFS\Casts\Utf8Cast;
use JBernavaPrah\EloquentFS\Traits\HasDynamicConnection;

/**
Expand Down Expand Up @@ -34,7 +33,6 @@ class FsFileChunk extends Model

protected $casts = [
'n' => 'integer',
'data' => Utf8Cast::class
];


Expand Down
31 changes: 28 additions & 3 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@


use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\UploadedFile;
use JBernavaPrah\EloquentFS\EloquentFS;
use JBernavaPrah\EloquentFS\Models\FsFile;


class ModelTest extends TestCase
{

protected function tearDown(): void
{
parent::tearDown(); // TODO: Change the autogenerated stub

EloquentFS::$connection = null;
}

function testFileModel()
{
Expand All @@ -26,13 +33,15 @@ function testFileModel()

$this->assertIsResource($file->stream('w'));

$this->assertEquals(6, $file->write($content, false));
$this->assertEquals('foobar', $file->read());

$this->assertEquals(6, $file->write($content));
$this->assertEquals(6, $file->write($content, true));
$this->assertEquals('foobarfoobar', $file->read());


$this->assertEquals(6, $file->write($content));
$this->assertEquals('foobar', $file->read());


}

function testFileModelChangeConnection()
Expand All @@ -44,6 +53,22 @@ function testFileModelChangeConnection()
$file = new FsFile();
$file->getConnection();

EloquentFS::$connection = null;


}

function testFileFromFake(){

$file = UploadedFile::fake()
->image('avatar.jpg', 300, 400)
->size(261100);

$fsFile = new FsFile();
$fsFile->write($file->get());

$this->assertEquals($file->get(), $fsFile->read());
$this->assertNotEmpty($fsFile->id);

}

Expand Down

0 comments on commit e7a32e5

Please sign in to comment.