engelsystem/tests/Unit/Models/BaseModelTest.php

69 lines
2.0 KiB
PHP
Raw Normal View History

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-09-25 17:29:15 +02:00
/**
* @covers \Engelsystem\Models\BaseModel::findOrNew
*/
public function testFindOrNew()
{
/** @var QueryBuilder|MockObject $queryBuilder */
$queryBuilder = $this->createMock(QueryBuilder::class);
BaseModelImplementation::$queryBuilder = $queryBuilder;
$anotherModel = new BaseModelImplementation();
$queryBuilder->expects($this->once())
->method('findOrNew')
->with(31337, ['lorem', 'ipsum'])
->willReturn($anotherModel);
$model = new BaseModelImplementation();
$newModel = $model->findOrNew(31337, ['lorem', 'ipsum']);
$this->assertEquals($anotherModel, $newModel);
}
2018-08-31 01:55:05 +02:00
}