blob: 18ca2d9a630972a56912be6dcbf2f454e0a2499f (
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
<?php
declare(strict_types=1);
namespace Engelsystem\Test\Unit\Models;
use Engelsystem\Models\News;
use Engelsystem\Models\User\User;
use Engelsystem\Test\Unit\HasDatabase;
use Engelsystem\Test\Unit\TestCase;
/**
* This class provides tests for the News model.
*/
class NewsTest extends TestCase
{
use HasDatabase;
/** @var array */
private $newsData;
/** @var User */
private $user;
/**
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$this->initDatabase();
$this->user = (new User())->create([
'name' => 'lorem',
'password' => '',
'email' => 'foo@bar.batz',
'api_key' => '',
]);
$this->newsData = [
'title' => 'test title',
'text' => 'test text',
'user_id' => $this->user->id
];
}
/**
* Tests that creating a News item with default values works.
*
* @return void
*/
public function testCreateDefault(): void
{
$news = (new News())->create($this->newsData);
$news = $news->find($news->id);
$this->assertSame(1, $news->id);
$this->assertSame($this->newsData['title'], $news->title);
$this->assertSame($this->newsData['text'], $news->text);
$this->assertFalse($news->is_meeting);
}
/**
* Tests that creating a News item with all fill values works.
*
* @return void
*/
public function testCreate(): void
{
$news = (new News())->create(
$this->newsData + ['is_meeting' => true]
);
$news = $news->find($news->id);
$this->assertSame(1, $news->id);
$this->assertSame($this->newsData['title'], $news->title);
$this->assertSame($this->newsData['text'], $news->text);
$this->assertTrue($news->is_meeting);
}
}
|