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

Redirect subclass tests #23

Open
wants to merge 5 commits into
base: pdo_subclassing
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions ext/pdo/tests/bug_43663.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ $dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();

if (getenv('PDOTEST_USECONNECT')) {
die('skip Test not customized for PDO::connect()');
}

echo 'nocache';
?>
--FILE--
<?php
Expand Down
6 changes: 6 additions & 0 deletions ext/pdo/tests/bug_72788.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ $dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();

if (getenv('PDOTEST_USECONNECT')) {
die('skip Test not customized for PDO::connect()');
}

echo 'nocache';
?>
--FILE--
<?php
Expand Down
6 changes: 6 additions & 0 deletions ext/pdo/tests/bug_77849.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ $dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();

if (getenv('PDOTEST_USECONNECT')) {
die('skip Test not customized for PDO::connect()');
}

echo 'nocache';
?>
--FILE--
<?php
Expand Down
6 changes: 6 additions & 0 deletions ext/pdo/tests/pdo_023.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ $dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();

if (getenv('PDOTEST_USECONNECT')) {
die('skip Test not customized for PDO::connect()');
}

echo 'nocache';
?>
--FILE--
<?php
Expand Down
6 changes: 6 additions & 0 deletions ext/pdo/tests/pdo_026.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ $dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();

if (getenv('PDOTEST_USECONNECT')) {
die('skip Test not customized for PDO::connect()');
}

echo 'nocache';
?>
--FILE--
<?php
Expand Down
6 changes: 6 additions & 0 deletions ext/pdo/tests/pdo_029.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ $dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();

if (getenv('PDOTEST_USECONNECT')) {
die('skip Test not customized for PDO::connect()');
}

echo 'nocache';
?>
--FILE--
<?php
Expand Down
6 changes: 6 additions & 0 deletions ext/pdo/tests/pdo_030.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ $dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();

if (getenv('PDOTEST_USECONNECT')) {
die('skip Test not customized for PDO::connect()');
}

echo 'nocache';
?>
--FILE--
<?php
Expand Down
8 changes: 7 additions & 1 deletion ext/pdo/tests/pdo_test.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class PDOTest {
$user = getenv('PDOTEST_USER');
$pass = getenv('PDOTEST_PASS');
$attr = getenv('PDOTEST_ATTR');
$useConnect = getenv('PDOTEST_USECONNECT');

if (is_string($attr) && strlen($attr)) {
$attr = unserialize($attr);
} else {
Expand All @@ -32,7 +34,11 @@ class PDOTest {
if ($user === false) $user = NULL;
if ($pass === false) $pass = NULL;

$db = new $classname($dsn, $user, $pass, $attr);
if ($useConnect) {
$db = $classname::connect($dsn, $user, $pass, $attr);
} else {
$db = new $classname($dsn, $user, $pass, $attr);
}

if (!$db) {
die("Could not create PDO object (DSN=$dsn, user=$user)\n");
Expand Down
6 changes: 6 additions & 0 deletions ext/pdo/tests/pecl_bug_5217.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ $dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();

if (getenv('PDOTEST_USECONNECT')) {
die('skip Test not customized for PDO::connect()');
}

echo 'nocache';
?>
--FILE--
<?php
Expand Down
27 changes: 27 additions & 0 deletions ext/pdo_pgsql/tests/subclass_through_pdo_suite.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
Postgres subclass
--EXTENSIONS--
pdo_pgsql
--REDIRECTTEST--
# Executes the pdo testsuite using PDO::connect()

$config = [
'TESTS' => __DIR__ . '/ext/pdo/tests',
'ENV' => [
'PDOTEST_USECONNECT' => true,
],
];

if (false !== getenv('PDO_PGSQL_TEST_DSN')) {
# user set them from their shell
$config['ENV']['PDOTEST_DSN'] = getenv('PDO_PGSQL_TEST_DSN');
if (false !== getenv('PDO_PGSQL_TEST_ATTR')) {
$config['ENV']['PDOTEST_ATTR'] = getenv('PDO_PGSQL_TEST_ATTR');
}
} else {
$config['ENV']['PDOTEST_DSN'] = 'pgsql:host=localhost port=5432 dbname=test user=postgres password=postgres';
$config['ENV']['PDOTEST_USER'] = 'postgres';
$config['ENV']['PDOTEST_PASS'] = 'postgres';
}

return $config;
27 changes: 27 additions & 0 deletions ext/pdo_pgsql/tests/subclass_through_pgsql_suite.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
Postgres subclass
--EXTENSIONS--
pdo_pgsql
--REDIRECTTEST--
# Executes the pdo_pgsql testsuite using PDO::connect()

$config = [
'TESTS' => __DIR__ . '/ext/pdo_pgsql/tests',
'ENV' => [
'PDOTEST_USECONNECT' => true,
],
];

if (false !== getenv('PDO_PGSQL_TEST_DSN')) {
# user set them from their shell
$config['ENV']['PDOTEST_DSN'] = getenv('PDO_PGSQL_TEST_DSN');
if (false !== getenv('PDO_PGSQL_TEST_ATTR')) {
$config['ENV']['PDOTEST_ATTR'] = getenv('PDO_PGSQL_TEST_ATTR');
}
} else {
$config['ENV']['PDOTEST_DSN'] = 'pgsql:host=localhost port=5432 dbname=test user=postgres password=postgres';
$config['ENV']['PDOTEST_USER'] = 'postgres';
$config['ENV']['PDOTEST_PASS'] = 'postgres';
}

return $config;
8 changes: 8 additions & 0 deletions ext/pdo_pgsql/tests/subclasses/pdopgsql_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
PdoPgsql subclass basic
--EXTENSIONS--
pdo_mysql
--SKIPIF--
<?php
# This does not need to be executed by the redirect as we directly test
# the ::connect() method here already.
if (getenv('REDIR_TEST_DIR')) {
die('skip Excluding from a redirected set');
}
?>
--FILE--
<?php

Expand Down
8 changes: 8 additions & 0 deletions ext/pdo_pgsql/tests/subclasses/pdopgsql_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
PdoPgsql connect through PDO::connect
--EXTENSIONS--
pdo_mysql
--SKIPIF--
<?php
# This does not need to be executed by the redirect as we directly test
# the ::connect() method here already.
if (getenv('REDIR_TEST_DIR')) {
die('skip Excluding from a redirected set');
}
?>
--FILE--
<?php

Expand Down
8 changes: 8 additions & 0 deletions ext/pdo_pgsql/tests/subclasses/pdopgsql_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
PdoPgsql getWarningCount
--EXTENSIONS--
pdo_mysql
--SKIPIF--
<?php
# This does not need to be executed by the redirect as we directly test
# the ::connect() method here already.
if (getenv('REDIR_TEST_DIR')) {
die('skip Excluding from a redirected set');
}
?>
--FILE--
<?php

Expand Down
16 changes: 13 additions & 3 deletions run-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,12 @@ function run_test(string $php, $file, array $env): string

$junit->markTestAs('BORK', $shortname, $tested_file, 0, $ex->getMessage());
return 'BORKED';
} catch (RedirectException $ex) {
show_result("SKIP", $ex->getMessage(), $tested_file);

$junit->markTestAs('SKIP', $shortname, $tested_file, 0, $ex->getMessage());

return 'SKIPPED';
}

$tested = $test->getName();
Expand Down Expand Up @@ -3296,6 +3302,10 @@ class BorkageException extends Exception
{
}

class RedirectException extends Exception
{
}

class JUnit
{
private bool $enabled = true;
Expand Down Expand Up @@ -3735,7 +3745,7 @@ class TestFile
];

/**
* @throws BorkageException
* @throws BorkageException|RedirectException
*/
public function __construct(string $fileName, bool $inRedirect)
{
Expand Down Expand Up @@ -3880,15 +3890,15 @@ private function readFile(): void
}

/**
* @throws BorkageException
* @throws BorkageException|RedirectException
*/
private function validateAndProcess(bool $inRedirect): void
{
// the redirect section allows a set of tests to be reused outside of
// a given test dir
if ($this->hasSection('REDIRECTTEST')) {
if ($inRedirect) {
throw new BorkageException("Can't redirect a test from within a redirected test");
throw new RedirectException("Can't redirect a test from within a redirected test");
}
return;
}
Expand Down