1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Janisbiz\LightOrm\Tests\Unit\Dms\MySQL\Connection; |
4
|
|
|
|
5
|
|
|
use Janisbiz\LightOrm\Dms\MySQL\Connection\Connection; |
6
|
|
|
use Janisbiz\LightOrm\Dms\MySQL\Connection\ConnectionPDOException; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
class ConnectionTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var Connection|\PHPUnit_Framework_MockObject_MockObject |
13
|
|
|
*/ |
14
|
|
|
private $connection; |
15
|
|
|
|
16
|
|
|
public function setUp() |
17
|
|
|
{ |
18
|
|
|
$this->connection = $this->createPartialMock( |
19
|
|
|
Connection::class, |
20
|
|
|
[ |
21
|
|
|
'inTransaction', |
22
|
|
|
'parentBeginTransaction', |
23
|
|
|
'exec', |
24
|
|
|
] |
25
|
|
|
); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testBeginTransaction() |
29
|
|
|
{ |
30
|
|
|
$this->connection->method('inTransaction')->willReturn(false); |
|
|
|
|
31
|
|
|
$this->connection->method('parentBeginTransaction')->willReturn(true); |
32
|
|
|
$this->assertTrue($this->connection->beginTransaction() instanceof Connection); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testBeginTransactionWhenInTransaction() |
36
|
|
|
{ |
37
|
|
|
$this->connection->method('inTransaction')->willReturn(true); |
38
|
|
|
$this->assertTrue($this->connection->beginTransaction() instanceof Connection); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testSetSqlSafeUpdates() |
42
|
|
|
{ |
43
|
|
|
$this |
44
|
|
|
->connection |
45
|
|
|
->expects($this->once()) |
46
|
|
|
->method('exec') |
47
|
|
|
->withConsecutive([ |
48
|
|
|
'SET SESSION SQL_SAFE_UPDATES = 1;', |
49
|
|
|
]) |
50
|
|
|
; |
51
|
|
|
$this->assertTrue($this->connection->setSqlSafeUpdates() instanceof Connection); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testUnsetSqlSafeUpdates() |
55
|
|
|
{ |
56
|
|
|
$this |
57
|
|
|
->connection |
58
|
|
|
->expects($this->once()) |
59
|
|
|
->method('exec') |
60
|
|
|
->withConsecutive([ |
61
|
|
|
'SET SESSION SQL_SAFE_UPDATES = 0;', |
62
|
|
|
]) |
63
|
|
|
; |
64
|
|
|
$this->assertTrue($this->connection->unsetSqlSafeUpdates() instanceof Connection); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testBeginTransactionWhenNotInTransactionAndCantBeginTransaction() |
68
|
|
|
{ |
69
|
|
|
$this->connection->method('inTransaction')->willReturn(false); |
70
|
|
|
$this->connection->method('parentBeginTransaction')->willReturn(false); |
71
|
|
|
|
72
|
|
|
$this->expectException(ConnectionPDOException::class); |
73
|
|
|
$this->expectExceptionMessage('Cannot begin transaction!'); |
74
|
|
|
|
75
|
|
|
$this->connection->beginTransaction(); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.