forked from mtierltd/timetracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkIntervalMapperTest.php
More file actions
44 lines (34 loc) · 1.25 KB
/
WorkIntervalMapperTest.php
File metadata and controls
44 lines (34 loc) · 1.25 KB
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
<?php
namespace OCA\TimeTracker\Tests\Unit\Db;
use PHPUnit\Framework\TestCase;
use OCA\TimeTracker\Db\WorkIntervalMapper;
use OCP\IDBConnection;
use OCP\DB\IPreparedStatement;
use OCA\TimeTracker\Db\WorkInterval;
class WorkIntervalMapperTest extends TestCase {
private $db;
private $mapper;
protected function setUp(): void {
$this->db = $this->createMock(IDBConnection::class);
$this->mapper = new WorkIntervalMapper($this->db);
}
public function testFindByName() {
$name = 'test-name';
$stmt = $this->createMock(IPreparedStatement::class);
$this->db->expects($this->once())
->method('prepare')
->with($this->stringContains('WHERE `name` = ?'))
->willReturn($stmt);
$stmt->expects($this->once())
->method('execute');
$stmt->expects($this->exactly(2))
->method('fetch')
->willReturnOnConsecutiveCalls(
['id' => 1, 'name' => $name, 'user_uid' => 'user'],
false
);
$result = $this->mapper->findByName($name);
$this->assertInstanceOf(WorkInterval::class, $result);
$this->assertEquals($name, $result->name);
}
}