Repository navigation
Expand file tree
/
Copy pathTests.php
More file actions
83 lines (67 loc) · 1.98 KB
/
Copy pathTests.php
File metadata and controls
83 lines (67 loc) · 1.98 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
80
81
82
83
<?php
namespace SOB\Nextras;
class Tests extends \SOB\Test
{
private \Nextras\Dbal\Connection $orm;
public function closeConnection() : void
{
$this->orm->disconnect();
}
public function dbSupported(\SOB\Configuration $config) : bool
{
return ! str_contains($config->getDriver(), 'sqlite');
}
/**
* class must delete one record with id=$id
*/
public function delete(int $id) : bool
{
$employee = new \SOB\Nextras\Model\Employee\Employee();
$employee->employee_id = $id;
return $employee->delete();
}
public function init(\SOB\Configuration $config, array $lines, \SOB\BaseLine $runTimer) : static
{
// Create and register the connection
$connection['driver'] = $config->getDriver();
$connection['host'] = $config->getHost();
$connection['username'] = $config->getUser();
$connection['password'] = $config->getPassword();
$connection['database'] = $config->getDatabase();
$connection['port'] = $config->getPort();
$connection['connectionTz'] = 'auto-offset';
$this->orm = new \Nextras\Dbal\Connection($connection);
$this->loadSchema($lines, [$this->orm, 'query'], $runTimer);
return $this;
}
/**
* class must insert one record with id=$id
*
* @return int $id inserted
*/
public function insert(int $id) : int
{
$employee = new \SOB\Nextras\Model\Employee\Employee();
$employee->employee_id = $id;
$employee->company = "Company {$id}";
$employee->last_name = "Last {$id}";
$employee->first_name = "First {$id}";
return $this->orm->persistAndFlush($employee);
}
/**
* class must read and return one record with id=$id or null on no matching record
*/
public function read(int $id) : ?object
{
return new \SOB\Nextras\Model\Employee\Employee($id);
}
/**
* class must update one record with id=$id to have $to in the data
*/
public function update(int $id, int $to) : bool
{
$employee = new \SOB\Nextras\Model\Employee\Employee($id);
$employee->last_name = "Updated {$to}";
return $employee->update();
}
}