Skip to content

Instantly share code, notes, and snippets.

@odinuv
Created September 27, 2018 15:19
Show Gist options
  • Save odinuv/1a5563fc33921dfbff792f4d69b69de4 to your computer and use it in GitHub Desktop.
Save odinuv/1a5563fc33921dfbff792f4d69b69de4 to your computer and use it in GitHub Desktop.
Testing the untestable: Test network kill during execute
<?php
public function testNetworkKillerExecute()
{
$conn = $this->getConnection();
// sleep 1 second before killing, then kill it for 3 seconds
exec('php killNetwork.php 1 3 > /dev/null &');
ErrorHandler::register(null, true);
// sleep a while to make sure the connection is terminated
sleep(2);
$stmt = $conn->query('SELECT NOW();');
self::expectException(\ErrorException::class);
self::expectExceptionMessage('Warning: PDOStatement::execute(): MySQL server has gone away');
$stmt->execute();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment