Skip to content

Commit be9f665

Browse files
committed
Added $tries to Database::transaction
1 parent 8ac9ad1 commit be9f665

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/Databases/MySQLTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
namespace Kir\MySQL\Databases;
3+
4+
use PDO;
5+
6+
class MySQLTest extends \PHPUnit_Framework_TestCase {
7+
public function testTransactionTries1() {
8+
$pdo = new PDO('sqlite::memory:');
9+
$mysql = new MySQL($pdo);
10+
11+
$this->setExpectedException('Exception', '5');
12+
13+
$mysql->transaction(5, function () {
14+
static $i;
15+
$i++;
16+
throw new \Exception($i);
17+
});
18+
}
19+
20+
public function testTransactionTries2() {
21+
$pdo = new PDO('sqlite::memory:');
22+
$mysql = new MySQL($pdo);
23+
24+
$result = $mysql->transaction(5, function () {
25+
static $i;
26+
$i++;
27+
if($i < 5) {
28+
throw new \Exception($i);
29+
}
30+
return $i;
31+
});
32+
33+
$this->assertEquals(5, $result);
34+
}
35+
}

0 commit comments

Comments
 (0)