Skip to content

Commit

Permalink
Adds unit tests for idType
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Gattuso committed Jun 14, 2016
1 parent c9a4fc4 commit 81a8482
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/Database/DatabaseEloquentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,28 @@ public function testIssetBehavesCorrectlyWithAttributesAndRelationships()
$this->assertTrue(isset($model->some_relation));
}

public function testIntIdTypePreserved()
{
$model = $this->getMock('EloquentModelStub', ['newQueryWithoutScopes', 'updateTimestamps', 'refresh']);
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('insertGetId')->once()->with([], 'id')->andReturn(1);
$model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));

$this->assertTrue($model->save());
$this->assertEquals(1, $model->id);
}

public function testStringIdTypePreserved()
{
$model = $this->getMock('EloquentIdTypeModelStub', ['newQueryWithoutScopes', 'updateTimestamps', 'refresh']);
$query = m::mock('Illuminate\Database\Eloquent\Builder');
$query->shouldReceive('insertGetId')->once()->with([], 'id')->andReturn("string id");
$model->expects($this->once())->method('newQueryWithoutScopes')->will($this->returnValue($query));

$this->assertTrue($model->save());
$this->assertEquals("string id", $model->id);
}

protected function addMockConnection($model)
{
$model->setConnectionResolver($resolver = m::mock('Illuminate\Database\ConnectionResolverInterface'));
Expand Down Expand Up @@ -1431,6 +1453,11 @@ public function setIncrementing($value)
}
}

class EloquentIdTypeModelStub extends EloquentModelStub
{
public $idType = "string";
}

class EloquentModelFindWithWritePdoStub extends Model
{
public function newQuery()
Expand Down

0 comments on commit 81a8482

Please sign in to comment.