Skip to content

Commit

Permalink
Merge branch '8.x'
Browse files Browse the repository at this point in the history
* 8.x:
  Bump v8.1.2 🚀
  Remove dummy test.
  Apply fixes from StyleCI
  Add connection methods to toggle case senstive sessions.
  Fix unique and exists case insensitive validation.
  Revert NLS_COMP and NLS_SORT.
  Setup orchestra/testbench testcase.
  Apply fixes from StyleCI
  Refactor tests and move to namespace.
  Update github action script.
  Use oci8-2.2.0.
  • Loading branch information
yajra committed Dec 6, 2020
2 parents 462f536 + 9c711da commit df65df7
Show file tree
Hide file tree
Showing 23 changed files with 601 additions and 282 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ jobs:
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, gd
tools: composer:v2, pecl
coverage: none
tools: pecl

- name: Setup OCI8
run: ./oci8.sh
Expand All @@ -49,7 +49,11 @@ jobs:
run: sudo echo "extension=oci8.so" >> /etc/php/${{ matrix.php }}/cli/php.ini

- name: Install dependencies
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-suggest
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit --verbose
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## [Unreleased]

## [v8.1.2] - 2020-12-06

- Fix database presence verifier. [#607]
- Revert [#598]
- Fixes [#601], [#602]
- Use orchestra testbench for tests

## [v8.1.1] - 2020-11-21

- Implement case insensitive function-based unique index. [#599]
Expand Down Expand Up @@ -108,7 +115,8 @@
- Fix [#406], [#404].
- Added more options to Sequence Create Method [#355], credits to [@nikklass].

[Unreleased]: https://github.com/yajra/laravel-oci8/compare/v8.1.1...7.x
[Unreleased]: https://github.com/yajra/laravel-oci8/compare/v8.1.2...8.x
[v8.1.2]: https://github.com/yajra/laravel-oci8/compare/v8.1.1...v8.1.2
[v8.1.1]: https://github.com/yajra/laravel-oci8/compare/v8.1.0...v8.1.1
[v8.1.0]: https://github.com/yajra/laravel-oci8/compare/v8.0.0...v8.1.0
[v8.0.1]: https://github.com/yajra/laravel-oci8/compare/v8.0.0...v8.0.1
Expand Down Expand Up @@ -160,7 +168,10 @@
[#591]: https://github.com/yajra/laravel-oci8/pull/591
[#598]: https://github.com/yajra/laravel-oci8/pull/598
[#599]: https://github.com/yajra/laravel-oci8/pull/599
[#607]: https://github.com/yajra/laravel-oci8/pull/607

[#602]: https://github.com/yajra/laravel-oci8/issue/602
[#601]: https://github.com/yajra/laravel-oci8/issue/601
[#590]: https://github.com/yajra/laravel-oci8/issue/590
[#564]: https://github.com/yajra/laravel-oci8/issue/564
[#523]: https://github.com/yajra/laravel-oci8/issue/523
Expand Down
12 changes: 10 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
"php": "^7.3",
"ext-oci8": ">=2.0.0",
"ext-pdo": "*",
"illuminate/support": "^8",
"illuminate/database": "^8",
"illuminate/support": "^8",
"illuminate/validation": "^8",
"yajra/laravel-pdo-via-oci8": "^2"
},
"require-dev": {
"orchestra/testbench": "^6.5",
"mockery/mockery": "^1.3.1",
"phpunit/phpunit": "^8.4|^9.0"
},
Expand All @@ -29,13 +31,19 @@
"Yajra\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Yajra\\Oci8\\Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "8.x-dev"
},
"laravel": {
"providers": [
"Yajra\\Oci8\\Oci8ServiceProvider"
"Yajra\\Oci8\\Oci8ServiceProvider",
"Yajra\\Oci8\\Oci8ValidationServiceProvider"
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion oci8.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sudo ln -s /opt/oracle/instantclient_12_1 /opt/oracle/instantclient
sudo ln -s /opt/oracle/instantclient/libclntsh.so.12.1 /opt/oracle/instantclient/libclntsh.so
sudo ln -s /opt/oracle/instantclient/libocci.so.12.1 /opt/oracle/instantclient/libocci.so

sudo sh -c "echo 'instantclient,/opt/oracle/instantclient' | pecl install oci8"
sudo sh -c "echo 'instantclient,/opt/oracle/instantclient' | pecl install oci8-2.2.0"

# setup ld library path
sudo sh -c "echo '/opt/oracle/instantclient' >> /etc/ld.so.conf"
Expand Down
40 changes: 23 additions & 17 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
<phpunit backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="tests/bootstrap.php"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
stopOnError="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="Laravel OCI8 Test Suite">
<directory>tests</directory>
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".blade.php">./src/</directory>
</exclude>
</coverage>
<php>
<ini name="memory_limit" value="2048M" />
<!--
<env name="REDIS_HOST" value="127.0.0.1" />
<env name="REDIS_PORT" value="6379" />
-->
</php>
</phpunit>
20 changes: 20 additions & 0 deletions src/Oci8/Oci8Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,24 @@ protected function causedByLostConnection(Throwable $e)

return Str::contains($e->getMessage(), $lostConnectionErrors);
}

/**
* Set oracle NLS session to case insensitive search & sort.
*
* @return $this
*/
public function useCaseInsensitiveSession()
{
return $this->setSessionVars(['NLS_COMP' => 'LINGUISTIC', 'NLS_SORT' => 'BINARY_CI']);
}

/**
* Set oracle NLS session to case sensitive search & sort.
*
* @return $this
*/
public function useCaseSensitiveSession()
{
return $this->setSessionVars(['NLS_COMP' => 'BINARY', 'NLS_SORT' => 'BINARY']);
}
}
2 changes: 0 additions & 2 deletions src/Oci8/Oci8ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ public function register()
'NLS_TIMESTAMP_FORMAT' => 'YYYY-MM-DD HH24:MI:SS',
'NLS_TIMESTAMP_TZ_FORMAT' => 'YYYY-MM-DD HH24:MI:SS TZH:TZM',
'NLS_NUMERIC_CHARACTERS' => '.,',
'NLS_COMP' => 'LINGUISTIC',
'NLS_SORT' => 'BINARY_CI',
];

// Like Postgres, Oracle allows the concept of "schema"
Expand Down
16 changes: 16 additions & 0 deletions src/Oci8/Oci8ValidationServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Yajra\Oci8;

use Illuminate\Validation\ValidationServiceProvider;
use Yajra\Oci8\Validation\Oci8DatabasePresenceVerifier;

class Oci8ValidationServiceProvider extends ValidationServiceProvider
{
protected function registerPresenceVerifier()
{
$this->app->singleton('validation.presence', function ($app) {
return new Oci8DatabasePresenceVerifier($app['db']);
});
}
}
59 changes: 59 additions & 0 deletions src/Oci8/Validation/Oci8DatabasePresenceVerifier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Yajra\Oci8\Validation;

use Illuminate\Validation\DatabasePresenceVerifier;
use Yajra\Oci8\Oci8Connection;

class Oci8DatabasePresenceVerifier extends DatabasePresenceVerifier
{
/**
* Count the number of objects in a collection having the given value.
*
* @param string $collection
* @param string $column
* @param string $value
* @param int|null $excludeId
* @param string|null $idColumn
* @param array $extra
* @return int
*/
public function getCount($collection, $column, $value, $excludeId = null, $idColumn = null, array $extra = [])
{
$connection = $this->table($collection)->getConnection();

if (! $connection instanceof Oci8Connection) {
return parent::getCount($collection, $column, $value, $excludeId, $idColumn, $extra);
}

$connection->useCaseInsensitiveSession();
$count = parent::getCount($collection, $column, $value, $excludeId, $idColumn, $extra);
$connection->useCaseSensitiveSession();

return $count;
}

/**
* Count the number of objects in a collection with the given values.
*
* @param string $collection
* @param string $column
* @param array $values
* @param array $extra
* @return int
*/
public function getMultiCount($collection, $column, array $values, array $extra = [])
{
$connection = $this->table($collection)->getConnection();

if (! $connection instanceof Oci8Connection) {
return parent::getMultiCount($collection, $column, $values, $extra);
}

$connection->useCaseInsensitiveSession();
$count = parent::getMultiCount($collection, $column, $values, $extra);
$connection->useCaseSensitiveSession();

return $count;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php

namespace Yajra\Oci8\Tests\Database;

use Mockery as m;
use PDO;
use PHPUnit\Framework\TestCase;
use Yajra\Oci8\Oci8Connection;

class DatabaseConnectionTest extends TestCase
class Oci8ConnectionTest extends TestCase
{
public function tearDown(): void
{
Expand All @@ -12,21 +16,21 @@ public function tearDown(): void

public function testCreateSequence()
{
$connection = m::mock(Yajra\Oci8\Oci8Connection::class);
$connection = m::mock(Oci8Connection::class);
$connection->shouldReceive('createSequence')->with('posts_id_seq')->once()->andReturn(true);
$this->assertEquals(true, $connection->createSequence('posts_id_seq'));
}

public function testCreateSequenceInvalidName()
{
$connection = m::mock(Yajra\Oci8\Oci8Connection::class);
$connection = m::mock(Oci8Connection::class);
$connection->shouldReceive('createSequence')->with(null)->once()->andReturn(false);
$this->assertEquals(false, $connection->createSequence(null));
}

public function testDropSequence()
{
$connection = m::mock(Yajra\Oci8\Oci8Connection::class);
$connection = m::mock(Oci8Connection::class);
$connection->shouldReceive('dropSequence')->with('posts_id_seq')->once()->andReturn(true);
$connection->shouldReceive('checkSequence')->with('posts_id_seq')->once()->andReturn(true);
$connection->checkSequence('posts_id_seq');
Expand All @@ -35,7 +39,7 @@ public function testDropSequence()

public function testDropSequenceInvalidName()
{
$connection = m::mock(Yajra\Oci8\Oci8Connection::class);
$connection = m::mock(Oci8Connection::class);
$connection->shouldReceive('dropSequence')->with(null)->once()->andReturn(false);
$connection->shouldReceive('checkSequence')->with(null)->once()->andReturn(true);
$connection->checkSequence(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<?php

namespace Yajra\Oci8\Tests\Database;

use Illuminate\Database\Connectors\Connector;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Yajra\Oci8\Connectors\OracleConnector;
use Yajra\Pdo\Oci8;

class DatabaseConnectorTest extends TestCase
class Oci8ConnectorTest extends TestCase
{
public function tearDown(): void
{
Expand All @@ -24,13 +29,13 @@ public function testCreateConnection()
'charset' => 'charset',
'options' => [],
];
$oci8 = $connector->createConnection($tns, $config, []);
$this->assertInstanceOf(Yajra\Pdo\Oci8::class, $oci8);
$oci8 = $connector->createConnection($tns, $config, []);
$this->assertInstanceOf(Oci8::class, $oci8);
}

public function testOptionResolution()
{
$connector = new Illuminate\Database\Connectors\Connector;
$connector = new Connector;
$connector->setDefaultOptions([0 => 'foo', 1 => 'bar']);
$this->assertEquals([0 => 'baz', 1 => 'bar', 2 => 'boom'],
$connector->getOptions(['options' => [0 => 'baz', 2 => 'boom']]));
Expand All @@ -43,7 +48,7 @@ public function testOptionResolution()
*/
public function testOracleConnectCallsCreateConnectionWithProperArguments($dsn, $config)
{
$connector = $this->getMockBuilder(Yajra\Oci8\Connectors\OracleConnector::class)
$connector = $this->getMockBuilder(OracleConnector::class)
->setMethods(['createConnection', 'getOptions'])
->getMock();
$connection = m::mock('PDO');
Expand Down Expand Up @@ -183,15 +188,15 @@ public function OracleConnectProvider()
}
}

class OracleConnectorStub extends \Yajra\Oci8\Connectors\OracleConnector
class OracleConnectorStub extends OracleConnector
{
public function createConnection($tns, array $config, array $options)
{
return new Oci8Stub($tns, $config['username'], $config['password'], $config['options']);
}
}

class Oci8Stub extends \Yajra\Pdo\Oci8
class Oci8Stub extends Oci8
{
public function __construct($dsn, $username, $password, array $options = [])
{
Expand Down
Loading

0 comments on commit df65df7

Please sign in to comment.