2018-08-31 01:55:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Models;
|
|
|
|
|
|
|
|
use Engelsystem\Test\Unit\Models\Stub\BaseModelImplementation;
|
2018-09-15 17:24:59 +02:00
|
|
|
use Illuminate\Database\Eloquent\Builder as QueryBuilder;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2018-08-31 01:55:05 +02:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class BaseModelTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Models\BaseModel::create
|
|
|
|
*/
|
|
|
|
public function testCreate()
|
|
|
|
{
|
|
|
|
$model = new BaseModelImplementation();
|
|
|
|
$newModel = $model->create(['foo' => 'bar']);
|
|
|
|
|
|
|
|
$this->assertNotEquals($model, $newModel);
|
|
|
|
$this->assertEquals('bar', $newModel->foo);
|
|
|
|
$this->assertEquals(1, $newModel->saveCount);
|
|
|
|
}
|
2018-09-15 17:24:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Models\BaseModel::find
|
|
|
|
*/
|
|
|
|
public function testFind()
|
|
|
|
{
|
|
|
|
/** @var QueryBuilder|MockObject $queryBuilder */
|
|
|
|
$queryBuilder = $this->createMock(QueryBuilder::class);
|
|
|
|
BaseModelImplementation::$queryBuilder = $queryBuilder;
|
|
|
|
|
|
|
|
$anotherModel = new BaseModelImplementation();
|
|
|
|
|
|
|
|
$queryBuilder->expects($this->once())
|
|
|
|
->method('find')
|
|
|
|
->with(1337, ['foo', 'bar'])
|
|
|
|
->willReturn($anotherModel);
|
|
|
|
|
|
|
|
$model = new BaseModelImplementation();
|
|
|
|
$newModel = $model->find(1337, ['foo', 'bar']);
|
|
|
|
|
|
|
|
$this->assertEquals($anotherModel, $newModel);
|
|
|
|
}
|
2018-08-31 01:55:05 +02:00
|
|
|
}
|