blob: 9af55fa1fad767ab4a5ca173c64b45ab52d3c646 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
<?php
namespace Engelsystem\Test\Unit\Models;
use Engelsystem\Test\Unit\Models\Stub\BaseModelImplementation;
use Illuminate\Database\Eloquent\Builder as QueryBuilder;
use PHPUnit\Framework\MockObject\MockObject;
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);
}
/**
* @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);
}
}
|