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

Streamlined two very similar large column name tests #807

Merged
merged 2 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 48 additions & 47 deletions test/functional/pdo_sqlsrv/PDO101_LargeColumnName.phpt
Original file line number Diff line number Diff line change
@@ -1,76 +1,77 @@
--TEST--
PDO - Large Column Name Test
--DESCRIPTION--
Verifies that long column names are supported (up to 128 chars).
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
--TEST--
PDO - Large Column Name Test
--DESCRIPTION--
Verifies that long column names are supported (up to 128 chars).
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?php require('skipif.inc'); ?>
--FILE--
<?php

include 'MsCommon.inc';
require_once('MsCommon.inc');

function LargeColumnNameTest($columnName, $expectfail)
function largeColumnNameTest($columnName)
{
include 'MsSetup.inc';

Setup();

$conn = Connect();
$conn = connect();

$tableName = "LargeColumnNameTest";
$tableName = "largeColumnNameTest";

DropTable($conn, $tableName);
dropTable($conn, $tableName);

$conn->query("CREATE TABLE [$tableName] ([$columnName] int)");


$conn->query("INSERT INTO [$tableName] ([$columnName]) VALUES (5)");

$stmt = $conn->query("SELECT * from [$tableName]");

if ( null == $stmt )
{
if (!$expectfail)
FatalError("Possible regression: Unable to retrieve inserted value.");
}

DropTable($conn, $tableName);

dropTable($conn, $tableName);
}


//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{

$testName = "PDO - Large Column Name Test";

StartTest($testName);

$columnName = "a";

try
{
for ($a = 1; $a <= 128; $a++)
{
LargeColumnNameTest($columnName, $a > 128);
$columnName .= "A";
}
}
catch (Exception $e)
{
echo $e->getMessage();
startTest($testName);

// The maximum size of a column name is 128 characters
$maxlen = 128;
$columnName = str_repeat('A', $maxlen);

try {
largeColumnNameTest($columnName);
} catch (Exception $e) {
echo "Possible regression: Unable to retrieve inserted value\n";
print_r($e->getMessage());
echo "\n";
}

EndTest($testName);

// Now add another character to the name
$columnName .= 'A';
try {
largeColumnNameTest($columnName);
} catch (Exception $e) {
// Expects to fail
$expected = 'is too long. Maximum length is 128.';
if (strpos($e->getMessage(), $expected) === false) {
print_r($e->getMessage());
echo "\n";
}
}

endTest($testName);
}

Repro();
?>
--EXPECT--
Test "PDO - Large Column Name Test" completed successfully.
repro();
?>
--EXPECT--
Test "PDO - Large Column Name Test" completed successfully.
Original file line number Diff line number Diff line change
Expand Up @@ -8,69 +8,70 @@ PHPT_EXEC=true
<?php require('skipif.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');

include 'MsCommon.inc';

function LargeColumnNameTest($columnName, $expectfail)
function largeColumnNameTest($columnName)
{
include 'MsSetup.inc';

Setup();

$conn = Connect();
$conn = connect();

$tableName = "LargeColumnNameTest";
$tableName = "largeColumnNameTest";

DropTable($conn, $tableName);
dropTable($conn, $tableName);

$conn->query("CREATE TABLE [$tableName] ([$columnName] int)");


$conn->query("INSERT INTO [$tableName] ([$columnName]) VALUES (5)");

$stmt = $conn->query("SELECT * from [$tableName]");

if ( null == $stmt )
{
if (!$expectfail)
FatalError("Possible regression: Unable to retrieve inserted value.");
}

DropTable($conn, $tableName);

dropTable($conn, $tableName);
}


//--------------------------------------------------------------------
// Repro
// repro
//
//--------------------------------------------------------------------
function Repro()
function repro()
{

$testName = "PDO - Large Column Name Test";

StartTest($testName);
startTest($testName);

$columnName = "是";
// The maximum size of a column name is 128 characters
$maxlen = 128;
$columnName = str_repeat('是', $maxlen);

try
{
for ($a = 1; $a <= 128; $a++)
{
LargeColumnNameTest($columnName, $a > 128);
$columnName .= "是";
}
try {
largeColumnNameTest($columnName);
} catch (Exception $e) {
echo "Possible regression: Unable to retrieve inserted value\n";
print_r($e->getMessage());
echo "\n";
}
catch (Exception $e)
{
echo $e->getMessage();

// Now add another character to the name
$columnName .= '是';
try {
largeColumnNameTest($columnName);
} catch (Exception $e) {
// Expects to fail
$expected = 'is too long. Maximum length is 128.';
if (strpos($e->getMessage(), $expected) === false) {
print_r($e->getMessage());
echo "\n";
}
}

EndTest($testName);
endTest($testName);
}

Repro();
repro();

?>
--EXPECT--
Test "PDO - Large Column Name Test" completed successfully.