Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for PHP 8 #24

Merged
merged 9 commits into from
Aug 16, 2023
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);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this code is problematic for the input stream and it works well.
But for the output stream is not working, as data wrapper is not writable.
And maybe that's helpful for the future, as the STDIN input is similar, not writable and we can generate a proper stream that will issue a warning in case app tries to write to input.

I would suggest to:

  • keep the function as it was but rename it to makeInputStream() and keep use it for $inputStream.
  • create a new function makeOutputStream() that just fopen to php://memory and use it for $outputStream.

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

private function makeOutputStream(array $lines)
drealecs marked this conversation as resolved.
Show resolved Hide resolved
{
$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);
}
}
Loading