Skip to content
This repository was archived by the owner on Nov 21, 2023. It is now read-only.

Support laravel/framework#47973 (v10.20.0) #3

Merged
merged 4 commits into from
Aug 23, 2023
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
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ jobs:
strategy:
matrix:
php: [8.1, '8.0']
laravel: [^10.0, ^9.0]
laravel: [^10.20, 10.19.*, ^9.0]
db: [mysql, pgsql, sqlite, sqlsrv, 'odbc:sqlsrv']
exclude:
- { php: 8.0, laravel: ^10.0 }
- { php: 8.0, laravel: ^10.20 }
- { php: 8.0, laravel: 10.19.* }
- { php: 8.0, laravel: ^11.0 }
- { php: 8.1, laravel: ^11.0 }

Expand Down Expand Up @@ -86,7 +87,9 @@ jobs:
run: mkdir -p build/logs

- name: Test
run: composer test -- --coverage-clover build/logs/clover.xml
run: |
composer test -- --migrate-configuration || :
composer test -- --coverage-clover build/logs/clover.xml
env:
DB: ${{ matrix.db }}

Expand Down
5 changes: 5 additions & 0 deletions src/UniqueViolationDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Mpyw\LaravelUniqueViolationDetector;

use Illuminate\Database\ConnectionInterface;
use Illuminate\Database\UniqueConstraintViolationException;
use Mpyw\UniqueViolationDetector\UniqueViolationDetector as DetectorInterface;
use PDOException;

Expand All @@ -27,6 +28,10 @@ public function __construct(ConnectionInterface $connection)

public function violated(PDOException $e): bool
{
if ($e instanceof UniqueConstraintViolationException) {
return true;
}

return (
$this->detector
?: ($this->detector = (new DetectorDiscoverer())->discover($this->connection))
Expand Down
15 changes: 15 additions & 0 deletions tests/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Mpyw\LaravelUniqueViolationDetector\Tests;

use Illuminate\Database\Connection;
use Illuminate\Database\Connectors\SqlServerConnector;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\SQLiteConnection;
Expand Down Expand Up @@ -40,6 +42,19 @@ protected function setUp(): void
{
parent::setUp();

// https://github.com/laravel/framework/issues/47937#issuecomment-1678200201
$this->app->instance(
'db.connector.sqlsrv',
new class() extends SqlServerConnector {
protected $options = [
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE => true,
];
},
);

config(['database.connections' => require __DIR__ . '/config/database.php']);
config(['database.default' => getenv('DB') ?: 'sqlite']);

Expand Down