Repository navigation
Expand file tree
/
Copy pathTests.php
More file actions
85 lines (70 loc) · 2.03 KB
/
Copy pathTests.php
File metadata and controls
85 lines (70 loc) · 2.03 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
84
85
<?php
namespace SOB\PDO;
class Tests extends \SOB\Test
{
private ?\PHPFUI\ORM\PDOInstance $pdo;
public function closeConnection() : void
{
$this->pdo = null;
}
/**
* class must delete one record with id=$id
*/
public function delete(int $id) : bool
{
return $this->pdo->execute('delete from employee where employee_id=?', [$id]);
}
/**
* Initialize the orm
*
* @param array<string> $lines sql to import into schema
*/
public function init(\SOB\Configuration $config, array $lines, \SOB\BaseLine $runTimer) : static
{
$connection = $config->getPDOConnectionString();
$this->pdo = new \PHPFUI\ORM\PDOInstance($connection, $config->getUser(), $config->getPassword());
\PHPFUI\ORM::addConnection($this->pdo);
\PHPFUI\ORM::$namespaceRoot = __DIR__ . '/../..';
\PHPFUI\ORM::$recordNamespace = 'SOB\PHPFUI\Record';
\PHPFUI\ORM::$tableNamespace = 'SOB\PHPFUI\Table';
\PHPFUI\ORM::$migrationNamespace = 'SOB\PHPFUI\Migration';
\PHPFUI\ORM::$idSuffix = '_id';
$callback = [$this->pdo, 'exec'];
$this->loadSchema($lines, $callback, $runTimer);
return $this;
}
/**
* class must insert one record with id=$id
*
* @return int $id inserted
*/
public function insert(int $id) : int
{
$this->pdo->execute('insert into employee (company, last_name, first_name) values (?,?,?)', ["Company {$id}", "Last {$id}", "First {$id}"]);
$name = 'employee';
if ($this->pdo->postGre)
{
$name .= '_employee_id_seq';
}
return $this->pdo->lastInsertId($name);
}
/**
* class must read and return one record with id=$id or null on no matching record
*/
public function read(int $id) : ?object
{
$result = $this->pdo->getRow('select * from employee where employee_id=?', [$id]);
if (count($result))
{
return (object)$result;
}
return null;
}
/**
* class must update one record with id=$id to have $to in the data
*/
public function update(int $id, int $to) : bool
{
return $this->pdo->execute('update employee set last_name=? where employee_id=?', [ "Updated {$to}", $id]);
}
}