Skip to content

Commit d9f5cc5

Browse files
Changed the approach for PDO returned values on tests and changed stream wrapper
1 parent a88903e commit d9f5cc5

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

tests-integration/AfterScriptRunTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ public static function setUpBeforeClass(): void
5151
self::$destination = new PDO($dsnDestination, $dbUser, $dbPass);
5252

5353
self::$source->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
54+
self::$source->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
5455
self::$destination->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
56+
self::$destination->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
5557
}
5658

5759
public function testNullIsAnonymizedWithNull(): void
@@ -216,8 +218,8 @@ public function testTruncatedTable(): void
216218
$stmt = self::$destination->query($query);
217219
$destRow = $stmt->fetch(PDO::FETCH_ASSOC);
218220

219-
$this->assertGreaterThan(0, (int)$sourceRow['nr']);
220-
$this->assertSame(0, (int)$destRow['nr']);
221+
$this->assertGreaterThan('0', $sourceRow['nr']);
222+
$this->assertSame('0', $destRow['nr']);
221223
}
222224

223225
/**

tests/AnonymizerTest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ final class AnonymizerTest extends TestCase
3434
/** @var ObserverInterface|MockObject */
3535
private $observerMock;
3636

37-
public const TMP_FILE_PATH = "/tmp/testData";
38-
3937
public function setUp(): void
4038
{
4139
parent::setUp();
@@ -54,8 +52,8 @@ public function setUp(): void
5452

5553
public function testRun(): void
5654
{
57-
$inputStream = $this->makeLineStream(['line1', 'line2']);
58-
$outputStream = $this->makeLineStream([]);
55+
$inputStream = $this->makeInputStream(['line1', 'line2']);
56+
$outputStream = $this->makeOutputStream([]);
5957

6058
$data = [
6159
'table1' => [
@@ -285,12 +283,18 @@ public function testRun(): void
285283
$this->assertSame(['INSERT table1' . "\n", 'INSERT table2'], $actual);
286284
}
287285

288-
private function makeLineStream(array $lines)
286+
private function makeInputStream(array $lines)
289287
{
288+
$fp = fopen('data://text/plain;base64,' . base64_encode(implode("\n", $lines)), 'ab+');
289+
rewind($fp);
290290

291-
$fp = fopen(self::TMP_FILE_PATH . (string)rand(0, 999), 'w+');
292-
fwrite($fp, implode("\n", $lines));
291+
return $fp;
292+
}
293293

294+
private function makeOutputStream(array $lines)
295+
{
296+
$fp = fopen('php://memory', 'ab+');
297+
fwrite($fp, implode("\n", $lines));
294298
rewind($fp);
295299

296300
return $fp;

tests/Application/Observer/ProgressTest.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ class ProgressTest extends TestCase
1010
{
1111
private Progress $sut;
1212

13-
public const TMP_FILE_PATH = "/tmp/testData";
14-
1513
public function setUp(): void
1614
{
1715
$this->sut = new Progress();
@@ -157,7 +155,7 @@ private function getProperty($name)
157155

158156
private function setOutputStream()
159157
{
160-
$fp = fopen(self::TMP_FILE_PATH, 'w+');
158+
$fp = fopen('php://memory', 'ab+');
161159
rewind($fp);
162160

163161
$refObject = new ReflectionObject($this->sut);
@@ -173,9 +171,4 @@ private function getOutputStream()
173171
$refProperty->setAccessible(true);
174172
return $refProperty->getValue($this->sut);
175173
}
176-
177-
public static function tearDownAfterClass(): void
178-
{
179-
unlink(self::TMP_FILE_PATH);
180-
}
181174
}

0 commit comments

Comments
 (0)