forked from Runalyze/Runalyze
/
DeleterTest.php
60 lines (49 loc) · 1.65 KB
/
DeleterTest.php
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
<?php
namespace Runalyze\Model;
use PDO;
class Deleter_MockTester extends DeleterWithAccountID {
public function table() {
return 'table';
}
protected function where() {
return '`foo`="DELETE"';
}
protected function before() {
$this->PDO->exec('INSERT INTO `'.PREFIX.'log` (`msg`) VALUES ("before")');
}
protected function after() {
$this->PDO->exec('INSERT INTO `'.PREFIX.'log` (`msg`) VALUES ("after")');
}
}
class DeleterObject_MockTester extends Object {
public function properties() {
return array ('foo');
}
}
/**
* Generated by hand
*/
class DeleterTest extends \PHPUnit_Framework_TestCase {
/**
* @var \PDO
*/
protected $PDO;
protected function setUp() {
$this->PDO = new PDO('sqlite::memory:');
$this->PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->PDO->exec('CREATE TEMP TABLE `'.PREFIX.'table` ( `foo` VARCHAR(10) )');
$this->PDO->exec('CREATE TEMP TABLE `'.PREFIX.'log` ( `msg` VARCHAR(10) )');
}
protected function tearDown() {
$this->PDO->exec('DROP TABLE `'.PREFIX.'table`');
$this->PDO->exec('DROP TABLE `'.PREFIX.'log`');
}
public function testDeleteOnlyCorrectOne() {
$this->PDO->exec('INSERT INTO `'.PREFIX.'table` (`foo`) VALUES ("bar")');
$this->PDO->exec('INSERT INTO `'.PREFIX.'table` (`foo`) VALUES ("DELETE")');
$Deleter = new Deleter_MockTester($this->PDO, new DeleterObject_MockTester());
$Deleter->delete();
$this->assertEquals(array('bar'), $this->PDO->query('SELECT `foo` FROM `'.PREFIX.'table`')->fetchAll(PDO::FETCH_COLUMN));
$this->assertEquals(array('before', 'after'), $this->PDO->query('SELECT `msg` FROM `'.PREFIX.'log`')->fetchAll(PDO::FETCH_COLUMN));
}
}