Skip to content

Commit

Permalink
Changed the approach for PDO returned values on tests and changed str…
Browse files Browse the repository at this point in the history
…eam wrapper
  • Loading branch information
beniamin-gheorghita-payu-gpo committed Aug 16, 2023
1 parent a88903e commit d9f5cc5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
6 changes: 4 additions & 2 deletions tests-integration/AfterScriptRunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public static function setUpBeforeClass(): void
self::$destination = new PDO($dsnDestination, $dbUser, $dbPass);

self::$source->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
self::$source->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
self::$destination->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
self::$destination->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
}

public function testNullIsAnonymizedWithNull(): void
Expand Down Expand Up @@ -216,8 +218,8 @@ public function testTruncatedTable(): void
$stmt = self::$destination->query($query);
$destRow = $stmt->fetch(PDO::FETCH_ASSOC);

$this->assertGreaterThan(0, (int)$sourceRow['nr']);
$this->assertSame(0, (int)$destRow['nr']);
$this->assertGreaterThan('0', $sourceRow['nr']);
$this->assertSame('0', $destRow['nr']);
}

/**
Expand Down
18 changes: 11 additions & 7 deletions tests/AnonymizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ final class AnonymizerTest extends TestCase
/** @var ObserverInterface|MockObject */
private $observerMock;

public const TMP_FILE_PATH = "/tmp/testData";

public function setUp(): void
{
parent::setUp();
Expand All @@ -54,8 +52,8 @@ public function setUp(): void

public function testRun(): void
{
$inputStream = $this->makeLineStream(['line1', 'line2']);
$outputStream = $this->makeLineStream([]);
$inputStream = $this->makeInputStream(['line1', 'line2']);
$outputStream = $this->makeOutputStream([]);

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

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

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

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

return $fp;
Expand Down
9 changes: 1 addition & 8 deletions tests/Application/Observer/ProgressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class ProgressTest extends TestCase
{
private Progress $sut;

public const TMP_FILE_PATH = "/tmp/testData";

public function setUp(): void
{
$this->sut = new Progress();
Expand Down Expand Up @@ -157,7 +155,7 @@ private function getProperty($name)

private function setOutputStream()
{
$fp = fopen(self::TMP_FILE_PATH, 'w+');
$fp = fopen('php://memory', 'ab+');
rewind($fp);

$refObject = new ReflectionObject($this->sut);
Expand All @@ -173,9 +171,4 @@ private function getOutputStream()
$refProperty->setAccessible(true);
return $refProperty->getValue($this->sut);
}

public static function tearDownAfterClass(): void
{
unlink(self::TMP_FILE_PATH);
}
}

0 comments on commit d9f5cc5

Please sign in to comment.