summaryrefslogtreecommitdiff
path: root/tests/Unit/Models
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-09-15 17:24:59 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-09-16 14:56:07 +0200
commit104e4f4c437376eb739dd3ef2de603855947a557 (patch)
treeb28f33e6d2fbb2aad5af074d2eb1d2e02148c6cd /tests/Unit/Models
parentedeab5e75ffa02b075c151ca03ea1038f61e4396 (diff)
Session: Added Symfony PDO backend
Diffstat (limited to 'tests/Unit/Models')
-rw-r--r--tests/Unit/Models/BaseModelTest.php24
-rw-r--r--tests/Unit/Models/Stub/BaseModelImplementation.php12
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/Unit/Models/BaseModelTest.php b/tests/Unit/Models/BaseModelTest.php
index 52cb8c7b..9af55fa1 100644
--- a/tests/Unit/Models/BaseModelTest.php
+++ b/tests/Unit/Models/BaseModelTest.php
@@ -3,6 +3,8 @@
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
@@ -19,4 +21,26 @@ class BaseModelTest extends TestCase
$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);
+ }
}
diff --git a/tests/Unit/Models/Stub/BaseModelImplementation.php b/tests/Unit/Models/Stub/BaseModelImplementation.php
index 4aa1ef0b..70643b03 100644
--- a/tests/Unit/Models/Stub/BaseModelImplementation.php
+++ b/tests/Unit/Models/Stub/BaseModelImplementation.php
@@ -3,6 +3,7 @@
namespace Engelsystem\Test\Unit\Models\Stub;
use Engelsystem\Models\BaseModel;
+use Illuminate\Database\Eloquent\Builder as QueryBuilder;
/**
* @property string foo
@@ -15,6 +16,9 @@ class BaseModelImplementation extends BaseModel
/** @var int */
public $saveCount = 0;
+ /** @var QueryBuilder */
+ public static $queryBuilder = null;
+
/**
* @param array $options
* @return bool
@@ -24,4 +28,12 @@ class BaseModelImplementation extends BaseModel
$this->saveCount++;
return true;
}
+
+ /**
+ * @return QueryBuilder
+ */
+ public static function query()
+ {
+ return self::$queryBuilder;
+ }
}