Skip to content

Commit

Permalink
tests: update tests accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jun 21, 2023
1 parent 11126a9 commit b38a198
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 33 deletions.
23 changes: 17 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<coverage/>
<testsuites>
<testsuite name="OCI8">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
12 changes: 5 additions & 7 deletions tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
use PHPUnit\Framework\TestCase;
use ReflectionObject;

use function getenv;

/**
* @internal
*/
Expand All @@ -42,11 +40,11 @@ protected function getConnection(): DBAL\Connection
}

$params = [
'user' => getenv('DB_USER'),
'password' => getenv('DB_PASSWORD'),
'host' => getenv('DB_HOST'),
'port' => getenv('DB_PORT'),
'dbname' => getenv('DB_SCHEMA'),
'user' => $_ENV['DB_USER'],
'password' => $_ENV['DB_PASSWORD'],
'host' => $_ENV['DB_HOST'],
'port' => $_ENV['DB_PORT'],
'dbname' => $_ENV['DB_SCHEMA'],
'driverClass' => Driver::class,
];

Expand Down
3 changes: 2 additions & 1 deletion tests/Doctrine/DBAL/Driver/OCI8/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
namespace tests\EcPhp\DoctrineOci8\Doctrine\DBAL\Test\Driver\OCI8;

use Doctrine\DBAL\Types\Type;
use EcPhp\DoctrineOci8\Doctrine\DBAL\Driver\OCI8\OCI8Connection;
use EcPhp\DoctrineOci8\Doctrine\DBAL\Driver\OCI8\Connection as OCI8Connection;
use tests\EcPhp\DoctrineOci8\AbstractTestCase;

/**
* @internal
*
* @coversNothing
*/
final class DriverTest extends AbstractTestCase
Expand Down
3 changes: 2 additions & 1 deletion tests/Doctrine/DBAL/Driver/OCI8/OCI8ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

namespace tests\EcPhp\DoctrineOci8\Doctrine\DBAL\Test\Driver\OCI8;

use EcPhp\DoctrineOci8\Doctrine\DBAL\Driver\OCI8\OCI8Statement;
use EcPhp\DoctrineOci8\Doctrine\DBAL\Driver\OCI8\Statement as OCI8Statement;
use tests\EcPhp\DoctrineOci8\AbstractTestCase;

/**
* @internal
*
* @coversNothing
*/
final class OCI8ConnectionTest extends AbstractTestCase
Expand Down
21 changes: 12 additions & 9 deletions tests/Doctrine/DBAL/Driver/OCI8/OCI8StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

namespace tests\EcPhp\DoctrineOci8\Doctrine\DBAL\Test\Driver\OCI8;

use EcPhp\DoctrineOci8\Doctrine\DBAL\Driver\OCI8\Cursor;
use EcPhp\DoctrineOci8\Doctrine\DBAL\Driver\OCI8\OCI8;
use EcPhp\DoctrineOci8\Doctrine\DBAL\Driver\OCI8\OCI8Cursor;
use EcPhp\DoctrineOci8\Doctrine\DBAL\Driver\OCI8\Statement;
use LogicException;
use PDO;
use tests\EcPhp\DoctrineOci8\AbstractTestCase;
Expand All @@ -22,6 +23,7 @@

/**
* @internal
*
* @coversNothing
*/
final class OCI8StatementTest extends AbstractTestCase
Expand Down Expand Up @@ -68,9 +70,9 @@ public function testBindParamSetsOci8Cursor(): void
$stmt->bindParam('cursor2', $cursor2, OCI8::PARAM_CURSOR);
$stmt->bindParam('cursor3', $cursor3, PDO::PARAM_STMT);

self::assertInstanceOf(OCI8Cursor::class, $cursor1);
self::assertInstanceOf(OCI8Cursor::class, $cursor2);
self::assertInstanceOf(OCI8Cursor::class, $cursor3);
self::assertInstanceOf(Cursor::class, $cursor1);
self::assertInstanceOf(Cursor::class, $cursor2);
self::assertInstanceOf(Cursor::class, $cursor3);
}

public function testBindValueThrowsExceptionWhenTypeIsCursor(): void
Expand Down Expand Up @@ -109,14 +111,15 @@ public function testBindValueThrowsExceptionWhenTypeIsPdoStmt(): void
public function testCursorFetchAll(): void
{
$conn = $this->getConnection();
/** @var Statement */
$stmt = $conn->prepare('BEGIN FIRST_NAMES(:cursor); END;');

/** @var OCI8Cursor $cursor */
$stmt->bindParam('cursor', $cursor, 'cursor');
$stmt->execute();
$cursor->execute();
$result = $cursor->execute();

$results = $cursor->fetchAll(PDO::FETCH_ASSOC);
$results = $result->fetchAllAssociative();

self::assertSame(self::$employees, $results);
}
Expand All @@ -126,14 +129,14 @@ public function testCursorFetchColumn(): void
$conn = $this->getConnection();
$stmt = $conn->prepare('BEGIN FIRST_NAMES(:cursor); END;');

/** @var OCI8Cursor $cursor */
/** @var Cursor $cursor */
$stmt->bindParam('cursor', $cursor, 'cursor');
$stmt->execute();
$cursor->execute();
$result = $cursor->execute();

$results = [];

while (false !== ($columnValue = $cursor->fetchColumn())) {
while (false !== ($columnValue = $result->fetchOne())) {
$results[] = $columnValue;
}

Expand Down
1 change: 1 addition & 0 deletions tests/Doctrine/DBAL/Driver/OCI8/OCI8Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

/**
* @internal
*
* @coversNothing
*/
final class OCI8Test extends AbstractTestCase
Expand Down
16 changes: 9 additions & 7 deletions tests/OciWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace tests\EcPhp\DoctrineOci8;

use RuntimeException;

use const OCI_DEFAULT;

final class OciWrapper
Expand All @@ -25,9 +27,9 @@ public function __construct()
// We must change the password in order to take this in account.
oci_password_change(
$this->connect(),
getenv('DB_USER'),
getenv('DB_PASSWORD'),
getenv('DB_PASSWORD')
$_ENV['DB_USER'],
$_ENV['DB_PASSWORD'],
$_ENV['DB_PASSWORD']
);
}

Expand All @@ -43,10 +45,10 @@ public function connect()
{
if (!$this->dbh) {
$this->dbh = oci_connect(
getenv('DB_USER'),
getenv('DB_PASSWORD'),
'//' . getenv('DB_HOST') . ':' . getenv('DB_PORT') . '/' . getenv('DB_SCHEMA'),
getenv('DB_CHARSET'),
$_ENV['DB_USER'],
$_ENV['DB_PASSWORD'],
'//' . $_ENV['DB_HOST'] . ':' . $_ENV['DB_PORT'] . '/' . $_ENV['DB_SCHEMA'],
$_ENV['DB_CHARSET'],
OCI_DEFAULT
);

Expand Down
3 changes: 1 addition & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@

$autoloader = require __DIR__ . '/../vendor/autoload.php';

$dotenv = new Dotenv(true);
$dotenv->loadEnv(__DIR__ . '/../.env');
(new Dotenv())->loadEnv(__DIR__ . '/../.env');

0 comments on commit b38a198

Please sign in to comment.