Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 0e20b2b

Browse files
melliolmichalbundyra
authored andcommitted
- created test cases for oci8 copy/pasting the ones existing for the other drivers,
- created 3 test cases to test the blob/clob implementation
1 parent 201a6c7 commit 0e20b2b

File tree

9 files changed

+463
-4
lines changed

9 files changed

+463
-4
lines changed

.ci/oracle_fixtures.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
echo "Configure Oracle test database"
4+
5+
"CREATE DATABASE test DATAFILE 'zenddb_test' SIZE 10M"

phpunit.xml.dist

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@
4343
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_SQLSRV_PASSWORD" value="Password123" />
4444
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_SQLSRV_DATABASE" value="zenddb_test" />
4545

46-
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8" value="false" />
47-
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_HOSTNAME" value="" />
46+
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8" value="true"/>
4847
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_USERNAME" value="" />
4948
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_PASSWORD" value="" />
5049
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_DATABASE" value="" />
50+
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_CHARSET" value=""/>
51+
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_CONNECTIONSTRING" value=""/>
5152

5253
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_IBMDB2" value="false" />
5354
<env name="TESTS_ZEND_DB_ADAPTER_DRIVER_IBMDB2_HOSTNAME" value="" />
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace ZendIntegrationTest\Db\Adapter\Driver\Oci8;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Zend\Db\Adapter\Driver\Oci8\Connection;
7+
8+
/**
9+
* @group integration
10+
* @group integration-oci8
11+
*/
12+
class ConnectionTest extends TestCase
13+
{
14+
15+
use TraitSetup;
16+
17+
public function testConnectionOk()
18+
{
19+
$connection = new Connection($this->variables);
20+
$connection->connect();
21+
22+
self::assertTrue($connection->isConnected());
23+
$connection->disconnect();
24+
}
25+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
3+
namespace ZendIntegrationTest\Db\Adapter\Driver\Oci8;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Zend\Db\Adapter\Adapter;
7+
use Zend\Db\Adapter\ParameterContainer;
8+
use Zend\Db\TableGateway\TableGateway;
9+
10+
class TableGatewayTest extends TestCase
11+
{
12+
use TraitSetup;
13+
14+
/**
15+
* @see https://github.com/zendframework/zend-db/issues/330
16+
*/
17+
public function testSelectWithEmptyCurrentWithBufferResult()
18+
{
19+
$adapter = new Adapter([
20+
'driver' => 'OCI8',
21+
'connection_string' => $this->variables['connectionstring'],
22+
'username' => $this->variables['username'],
23+
'password' => $this->variables['password'],
24+
'character_set' => $this->variables['charset'],
25+
'options' => ['buffer_results' => true]
26+
]);
27+
$tableGateway = new TableGateway('TEST', $adapter);
28+
$rowset = $tableGateway->select('ID = 0');
29+
30+
$this->assertNull($rowset->current());
31+
}
32+
33+
/**
34+
* @see https://github.com/zendframework/zend-db/issues/330
35+
*/
36+
public function testSelectWithEmptyCurrentWithoutBufferResult()
37+
{
38+
$adapter = new Adapter([
39+
'driver' => 'OCI8',
40+
'connection_string' => $this->variables['connectionstring'],
41+
'username' => $this->variables['username'],
42+
'password' => $this->variables['password'],
43+
'character_set' => $this->variables['charset'],
44+
'options' => ['buffer_results' => false]
45+
]);
46+
$tableGateway = new TableGateway('TEST', $adapter);
47+
$rowset = $tableGateway->select('ID = 0');
48+
49+
$this->assertNull($rowset->current());
50+
}
51+
52+
/**
53+
* @see https://github.com/zendframework/zend-db/pull/396
54+
*/
55+
public function testBlobWithOci8()
56+
{
57+
$adapter = new Adapter([
58+
'driver' => 'OCI8',
59+
'connection_string' => $this->variables['connectionstring'],
60+
'username' => $this->variables['username'],
61+
'password' => $this->variables['password'],
62+
'character_set' => $this->variables['charset'],
63+
'options' => ['buffer_results' => false]
64+
]);
65+
$tableGateway = new TableGateway('TEST', $adapter);
66+
67+
$blob = 'very long sentence that is in fact not very long that tests blob';
68+
69+
$data = new ParameterContainer();
70+
$data->setFromArray(['CONTENT_BLOB' => $blob]);
71+
$data->offsetSetErrata('CONTENT_BLOB', ParameterContainer::TYPE_BLOB);
72+
73+
$sql = "UPDATE TEST SET CONTENT_BLOB= :CONTENT_BLOB WHERE ID = 1";
74+
$stm = $tableGateway->getAdapter()->getDriver()->createStatement($sql);
75+
$stm->setParameterContainer($data);
76+
$stm->execute();
77+
78+
$rowset = $tableGateway->select('ID = 1')->current();
79+
80+
$this->assertInstanceOf('OCI-Lob', $rowset['CONTENT_BLOB']);
81+
$value = $rowset['CONTENT_BLOB']->read($rowset['CONTENT_BLOB']->size());
82+
$this->assertEquals($blob, $value);
83+
}
84+
85+
/**
86+
* @see https://github.com/zendframework/zend-db/pull/396
87+
*/
88+
public function testClobWithOci8()
89+
{
90+
$adapter = new Adapter([
91+
'driver' => 'OCI8',
92+
'connection_string' => $this->variables['connectionstring'],
93+
'username' => $this->variables['username'],
94+
'password' => $this->variables['password'],
95+
'character_set' => $this->variables['charset'],
96+
'options' => ['buffer_results' => false]
97+
]);
98+
$tableGateway = new TableGateway('TEST', $adapter);
99+
100+
$clob = 'very long sentence that is in fact not very long that tests clob';
101+
102+
$data = new ParameterContainer();
103+
$data->setFromArray(['CONTENT_CLOB' => $clob]);
104+
$data->offsetSetErrata('CONTENT_CLOB', ParameterContainer::TYPE_CLOB);
105+
106+
$sql = "UPDATE TEST SET CONTENT_CLOB= :CONTENT_CLOB WHERE ID = 1";
107+
$stm = $tableGateway->getAdapter()->getDriver()->createStatement($sql);
108+
$stm->setParameterContainer($data);
109+
$stm->execute();
110+
111+
$rowset = $tableGateway->select('ID = 1')->current();
112+
113+
$this->assertInstanceOf('OCI-Lob', $rowset['CONTENT_CLOB']);
114+
$value = $rowset['CONTENT_CLOB']->read($rowset['CONTENT_CLOB']->size());
115+
$this->assertEquals($clob, $value);
116+
}
117+
118+
/**
119+
* @see https://github.com/zendframework/zend-db/pull/396
120+
*/
121+
public function testLobWithOci8()
122+
{
123+
$adapter = new Adapter([
124+
'driver' => 'OCI8',
125+
'connection_string' => $this->variables['connectionstring'],
126+
'username' => $this->variables['username'],
127+
'password' => $this->variables['password'],
128+
'character_set' => $this->variables['charset'],
129+
'options' => ['buffer_results' => false]
130+
]);
131+
$tableGateway = new TableGateway('TEST', $adapter);
132+
133+
$clob = 'very long sentence that is in fact not very long that tests lob';
134+
135+
$data = new ParameterContainer();
136+
$data->setFromArray(['CONTENT_CLOB' => $clob]);
137+
$data->offsetSetErrata('CONTENT_CLOB', ParameterContainer::TYPE_LOB);
138+
139+
$sql = "UPDATE TEST SET CONTENT_CLOB= :CONTENT_CLOB WHERE ID = 2";
140+
$stm = $tableGateway->getAdapter()->getDriver()->createStatement($sql);
141+
$stm->setParameterContainer($data);
142+
$stm->execute();
143+
144+
$rowset = $tableGateway->select('ID = 2')->current();
145+
146+
$this->assertInstanceOf('OCI-Lob', $rowset['CONTENT_CLOB']);
147+
$value = $rowset['CONTENT_CLOB']->read($rowset['CONTENT_CLOB']->size());
148+
$this->assertEquals($clob, $value);
149+
}
150+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-db for the canonical source repository
4+
* @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-db/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
namespace ZendIntegrationTest\Db\Adapter\Driver\Oci8;
9+
10+
trait TraitSetup
11+
{
12+
protected $variables = [
13+
'connectionstring' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_CONNECTIONSTRING',
14+
'username' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_USERNAME',
15+
'password' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_PASSWORD',
16+
'charset' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_CHARSET',
17+
'database' => 'TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_DATABASE',
18+
];
19+
20+
/**
21+
* Sets up the fixture, for example, opens a network connection.
22+
* This method is called before a test is executed.
23+
*/
24+
protected function setUp()
25+
{
26+
if (!getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8')) {
27+
$this->markTestSkipped('Oci8 integration test disabled');
28+
}
29+
30+
if (!extension_loaded('oci8')) {
31+
$this->fail('The phpunit group integration-oci8 was enabled, but the extension is not loaded.');
32+
}
33+
34+
foreach ($this->variables as $name => $value) {
35+
if (!getenv($value)) {
36+
$this->markTestSkipped(sprintf(
37+
'Missing required variable %s from phpunit.xml for this integration test',
38+
$value
39+
));
40+
}
41+
$this->variables[$name] = getenv($value);
42+
}
43+
}
44+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace ZendIntegrationTest\Db\Adapter\Platform;
11+
12+
use PHPUnit\Framework\TestCase;
13+
use Zend\Db\Adapter\Driver\Oci8;
14+
use Zend\Db\Adapter\Driver\Pdo;
15+
use Zend\Db\Adapter\Platform\Oracle;
16+
17+
/**
18+
* @group integration
19+
* @group integration-oci8
20+
*/
21+
class Oci8Test extends TestCase
22+
{
23+
public $adapters = [];
24+
25+
public function setUp()
26+
{
27+
if (!getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8')) {
28+
$this->markTestSkipped(__CLASS__ . ' integration tests are not enabled!');
29+
}
30+
if (extension_loaded('oci8')) {
31+
$this->adapters['oci8'] = oci_connect(
32+
getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_USERNAME'),
33+
getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_PASSWORD'),
34+
getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_CONNECTIONSTRING'),
35+
getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_CHARSET'),
36+
null);
37+
}
38+
if (extension_loaded('pdo_oci')) {
39+
$this->adapters['pdo_oci'] = new \PDO(
40+
'oci:dbname=' . getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_CONNECTIONSTRING'),
41+
getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_USERNAME'),
42+
getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8_PASSWORD')
43+
);
44+
}
45+
}
46+
47+
public function testQuoteValueWithOci8()
48+
{
49+
if (!isset($this->adapters['oci8'])
50+
|| !$this->adapters['oci8'] instanceof \Oracle) {
51+
$this->markTestSkipped('Oracle (oci8) not configured in unit test configuration file');
52+
}
53+
$oracle = new Oracle($this->adapters['oci8']);
54+
$value = $oracle->quoteValue('value');
55+
self::assertEquals('\'value\'', $value);
56+
57+
$oracle = new Oracle(new Oci8\Oci8(new Oci8\Connection($this->adapters['oci8'])));
58+
$value = $oracle->quoteValue('value');
59+
self::assertEquals('\'value\'', $value);
60+
}
61+
62+
public function testQuoteValueWithPdoOci()
63+
{
64+
if (!isset($this->adapters['pdo_oci'])
65+
|| !$this->adapters['pdo_oci'] instanceof \PDO) {
66+
$this->markTestSkipped('Oracle (pdo_oci) not configured in unit test configuration file');
67+
}
68+
$oracle = new Pdo($this->adapters['pdo_oci']);
69+
$value = $oracle->quoteValue('value');
70+
self::assertEquals('\'value\'', $value);
71+
72+
$oracle = new Pdo(new Pdo\Pdo(new Pdo\Connection($this->adapters['pdo_oci'])));
73+
$value = $oracle->quoteValue('value');
74+
self::assertEquals('\'value\'', $value);
75+
}
76+
77+
78+
}

test/integration/IntegrationTestListener.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
namespace ZendIntegrationTest\Db;
1111

12-
use Exception;
1312
use PDO;
14-
use PDOException;
1513
use PHPUnit\Framework\BaseTestListener;
1614
use PHPUnit_Framework_TestSuite as TestSuite;
1715
use ZendIntegrationTest\Db\Platform\FixtureLoader;
@@ -40,6 +38,9 @@ public function startTestSuite(TestSuite $suite)
4038
if (getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_PGSQL')) {
4139
$this->fixtureLoader = new \ZendIntegrationTest\Db\Platform\PgsqlFixtureLoader();
4240
}
41+
if (getenv('TESTS_ZEND_DB_ADAPTER_DRIVER_OCI8')) {
42+
$this->fixtureLoader = new \ZendIntegrationTest\Db\Platform\Oci8FixtureLoader();
43+
}
4344

4445
if (! isset($this->fixtureLoader)) {
4546
return;

0 commit comments

Comments
 (0)