Repository navigation
Expand file tree
/
Copy pathTests.php
More file actions
79 lines (64 loc) · 1.65 KB
/
Copy pathTests.php
File metadata and controls
79 lines (64 loc) · 1.65 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
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
<?php
namespace SOB\RedBean;
class Tests extends \SOB\Test
{
public function closeConnection() : void
{
\RedBeanPHP\R::close();
\RedBeanPHP\R::removeToolBoxByKey('default');
}
/**
* class must delete one record with id=$id
*/
public function delete(int $id) : bool
{
$employee = $this->read($id);
return 1 == \RedBeanPHP\R::trash($employee);
}
/**
* Initialize the orm
*
* @param array<string> $lines sql to import into schema
*/
public function init(\SOB\Configuration $config, array $lines, \SOB\BaseLine $runTimer) : static
{
\RedBeanPHP\R::setup($config->getPDOConnectionString(), $config->getUser(), $config->getPassword());
$this->loadSchema($lines, [\RedBeanPHP\Facade::class, 'exec'], $runTimer);
return $this;
}
/**
* class must insert one record with id=$id
*
* @return int $id inserted
*/
public function insert(int $id) : int
{
$employee = \RedBeanPHP\R::dispense('employee');
$employee->employee_id = $id;
$employee->company = "Company {$id}";
$employee->last_name = "Last {$id}";
$employee->first_name = "First {$id}";
return \RedBeanPHP\R::store($employee);
}
/**
* class must read and return one record with id=$id or null on no matching record
*/
public function read(int $id) : ?object
{
$employee = \RedBeanPHP\R::load('employee', $id);
if (! $employee->employee_id)
{
return null;
}
return $employee;
}
/**
* class must update one record with id=$id to have $to in the data
*/
public function update(int $id, int $to) : bool
{
$employee = $this->read($id);
$employee->last_name = "Updated {$to}";
return \RedBeanPHP\R::store($employee);
}
}