-
Notifications
You must be signed in to change notification settings - Fork 60
/
PhpunitTest.php
215 lines (179 loc) · 5.69 KB
/
PhpunitTest.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
namespace Tests\Functional;
use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver;
use Doctrine\DBAL\Exception\TableNotFoundException;
use PHPUnit\Framework\TestCase;
class PhpunitTest extends TestCase
{
use FunctionalTestTrait;
protected function setUp(): void
{
parent::setUp();
$this->init();
/** @phpstan-ignore-next-line */
if ((method_exists($this, 'name') ? $this->name() : $this->getName()) === 'testSkippedTestDuringSetup') {
$this->markTestSkipped();
}
}
public function testChangeDbState(): void
{
$this->assertRowCount(0);
$this->insertRow();
$this->assertRowCount(1);
}
/**
* @depends testChangeDbState
*/
public function testPreviousChangesAreRolledBack(): void
{
$this->assertRowCount(0);
}
/**
* @dataProvider someDataProvider
*/
public function testWithDataProvider(int $expectedRowCount): void
{
$this->assertRowCount($expectedRowCount);
$this->insertRow();
}
/**
* @return iterable<array{int}>
*/
public static function someDataProvider(): iterable
{
yield [0];
}
public function testChangeDbStateForConnectionWithoutServerVersion(): void
{
$this->connection = $this->kernel->getContainer()->get('doctrine.dbal.no_server_version_connection');
$this->assertRowCount(0);
$this->insertRow();
$this->assertRowCount(1);
}
/**
* @depends testChangeDbStateForConnectionWithoutServerVersion
*/
public function testChangeDbStateForConnectionWithoutServerVersionRolledBack(): void
{
$this->connection = $this->kernel->getContainer()->get('doctrine.dbal.no_server_version_connection');
$this->assertRowCount(0);
$this->assertFalse($this->connection->isTransactionActive());
}
public function testChangeDbStateForReplicaConnection(): void
{
$this->connection = $this->kernel->getContainer()->get('doctrine.dbal.replica_connection');
$this->assertRowCount(0);
$this->insertRow();
$this->assertRowCount(1);
}
/**
* @depends testChangeDbStateForReplicaConnection
*/
public function testChangeDbStateForReplicaConnectionRolledBack(): void
{
$this->connection = $this->kernel->getContainer()->get('doctrine.dbal.replica_connection');
$this->assertRowCount(0);
$this->assertFalse($this->connection->isTransactionActive());
}
public function testChangeDbStateWithMultipleConnections(): void
{
$this->assertRowCount(0);
$this->insertRow();
$this->assertRowCount(1);
$this->connection->close();
$this->assertRowCount(1);
}
public function testChangeDbStateWithinTransaction(): void
{
$this->assertRowCount(0);
$this->beginTransaction();
$this->insertRow();
$this->assertRowCount(1);
$this->rollbackTransaction();
$this->assertRowCount(0);
$this->beginTransaction();
$this->insertRow();
$this->assertRowCount(1);
$this->rollbackTransaction();
$this->assertRowCount(0);
$this->beginTransaction();
$this->insertRow();
$this->commitTransaction();
$this->assertRowCount(1);
$this->beginTransaction();
$this->insertRow();
$this->commitTransaction();
$this->assertRowCount(2);
}
/**
* @depends testChangeDbStateWithinTransaction
*/
public function testPreviousChangesAreRolledBackAfterTransaction(): void
{
$this->assertRowCount(0);
}
public function testChangeDbStateWithSavePoint(): void
{
$this->assertRowCount(0);
$this->createSavepoint('foo');
$this->insertRow();
$this->assertRowCount(1);
$this->rollbackSavepoint('foo');
$this->assertRowCount(0);
$this->insertRow();
}
/**
* @depends testChangeDbStateWithSavePoint
*/
public function testPreviousChangesAreRolledBackAfterUsingSavePoint(): void
{
$this->assertRowCount(0);
}
public function testSkippedTest(): void
{
$this->markTestSkipped();
}
public function testSkippedTestDuringSetup(): void
{
$this->assertTrue(true);
}
public function testMarkIncomplete(): void
{
$this->markTestIncomplete();
}
public function testRollBackChangesWithReOpenedConnection(): void
{
$this->connection->close();
$this->connection->beginTransaction();
$this->connection->commit();
$this->assertRowCount(0);
}
public function testWillThrowSpecificException(): void
{
$this->expectException(TableNotFoundException::class);
$this->connection->insert('does_not_exist', ['foo' => 'bar']);
}
public function testTransactionalBehaviorCanBeDisabledDuringRuntime(): void
{
StaticDriver::setKeepStaticConnections(false);
$this->kernel->shutdown();
$this->init();
$this->insertRow();
$this->assertRowCount(1);
StaticDriver::setKeepStaticConnections(true);
}
/**
* @depends testTransactionalBehaviorCanBeDisabledDuringRuntime
*/
public function testChangesFromPreviousTestAreVisibleWhenDisabledDuringRuntime(): void
{
StaticDriver::setKeepStaticConnections(false);
$this->kernel->shutdown();
$this->setUp();
$this->assertRowCount(1);
// cleanup persisted row to not affect any other tests afterwards
$this->connection->executeQuery('DELETE FROM test');
$this->assertRowCount(0);
StaticDriver::setKeepStaticConnections(true);
}
}