Skip to content

Commit

Permalink
Test on PHP 8
Browse files Browse the repository at this point in the history
Co-authored-by: Taylor Otwell <taylor@laravel.com>
Co-authored-by: Graham Campbell <graham@alt-three.com>
  • Loading branch information
3 people committed Oct 19, 2020
1 parent 28bb76e commit 1b7ee16
Show file tree
Hide file tree
Showing 42 changed files with 390 additions and 49 deletions.
63 changes: 56 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.2, 7.3, 7.4]
php: [7.2, 7.3, 7.4, 8.0]
stability: [prefer-lowest, prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
Expand All @@ -47,8 +47,32 @@ jobs:
- name: Setup Memcached
uses: niden/actions-memcached@v7

- name: Install dependencies
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress
- name: Setup problem matchers
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install PHP 7 dependencies
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-dist --no-interaction --no-progress
if: "matrix.php < 8"

- name: Setup PHP 8 Dependencies
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer require "phpunit/phpunit:^9.3.3" "doctrine/dbal:^3.0" --no-update --no-interaction
if: "matrix.php >= 8"

- name: Install PHP 8 Dependencies
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress --ignore-platform-req=php
if: "matrix.php >= 8"

- name: Execute tests
run: vendor/bin/phpunit --verbose
Expand All @@ -62,14 +86,16 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.2, 7.3, 7.4]
php: [7.2, 7.3, 7.4, 8.0]
include:
- php: 7.2
stability: prefer-lowest
- php: 7.3
stability: prefer-stable
- php: 7.4
stability: prefer-stable
- php: 8.0
stability: prefer-stable

name: PHP ${{ matrix.php }} - ${{ matrix.stability }} - Windows

Expand All @@ -89,10 +115,33 @@ jobs:
extensions: dom, curl, libxml, mbstring, zip, pdo, sqlite, pdo_sqlite, gd, pdo_mysql, fileinfo, ftp
tools: composer:v2
coverage: none
ini-values: memory_limit=512M

- name: Install dependencies
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress
- name: Setup problem matchers
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install PHP 7 Dependencies
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-dist --no-interaction --no-progress
if: "matrix.php < 8"

- name: Setup PHP 8 Dependencies
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer require "phpunit/phpunit:^9.3.3" "doctrine/dbal:^3.0" --no-update --no-interaction
if: "matrix.php >= 8"

- name: Install PHP 8 Dependencies
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress --ignore-platform-req=php
if: "matrix.php >= 8"

- name: Execute tests
run: vendor/bin/phpunit --verbose
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2|^8.0",
"ext-json": "*",
"ext-mbstring": "*",
"ext-openssl": "*",
Expand Down Expand Up @@ -78,7 +78,7 @@
},
"require-dev": {
"aws/aws-sdk-php": "^3.0",
"doctrine/dbal": "^2.6",
"doctrine/dbal": "^2.6|^3.0",
"filp/whoops": "^2.8",
"guzzlehttp/guzzle": "^6.3.1|^7.0.1",
"league/flysystem-cached-adapter": "^1.0",
Expand Down Expand Up @@ -120,7 +120,7 @@
"ext-posix": "Required to use all features of the queue worker.",
"ext-redis": "Required to use the Redis cache and queue drivers (^4.0|^5.0).",
"aws/aws-sdk-php": "Required to use the SQS queue driver, DynamoDb failed job storage and SES mail driver (^3.0).",
"doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6).",
"doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6|^3.0).",
"filp/whoops": "Required for friendly error pages in development (^2.8).",
"fzaninotto/faker": "Required to use the eloquent factory builder (^1.9.1).",
"guzzlehttp/guzzle": "Required to use the Mailgun mail driver and the ping methods on schedules (^6.3.1|^7.0.1).",
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Auth/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2|^8.0",
"illuminate/contracts": "^6.0",
"illuminate/http": "^6.0",
"illuminate/queue": "^6.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Broadcasting/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2|^8.0",
"ext-json": "*",
"psr/log": "^1.0",
"illuminate/bus": "^6.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Bus/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2|^8.0",
"illuminate/contracts": "^6.0",
"illuminate/pipeline": "^6.0",
"illuminate/support": "^6.0"
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Cache/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2|^8.0",
"illuminate/contracts": "^6.0",
"illuminate/support": "^6.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Config/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2|^8.0",
"illuminate/contracts": "^6.0",
"illuminate/support": "^6.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Console/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2|^8.0",
"illuminate/contracts": "^6.0",
"illuminate/support": "^6.0",
"symfony/console": "^4.3.4",
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Container/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2|^8.0",
"illuminate/contracts": "^6.0",
"psr/container": "^1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Contracts/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2|^8.0",
"psr/container": "^1.0",
"psr/simple-cache": "^1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Cookie/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": "^7.2",
"php": "^7.2|^8.0",
"illuminate/contracts": "^6.0",
"illuminate/support": "^6.0",
"symfony/http-foundation": "^4.3.4",
Expand Down
11 changes: 9 additions & 2 deletions src/Illuminate/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,14 @@ public function getDoctrineColumn($table, $column)
*/
public function getDoctrineSchemaManager()
{
return $this->getDoctrineDriver()->getSchemaManager($this->getDoctrineConnection());
$connection = $this->getDoctrineConnection();

// v2 expects only one param, and v3 two. We don't need to care about
// this, and can always pass them both. In v2, the 2nd is ignored.
return $this->getDoctrineDriver()->getSchemaManager(
$connection,
$connection->getDatabasePlatform()
);
}

/**
Expand All @@ -905,7 +912,7 @@ public function getDoctrineConnection()
$this->doctrineConnection = new DoctrineConnection(array_filter([
'pdo' => $this->getPdo(),
'dbname' => $this->getDatabaseName(),
'driver' => $driver->getName(),
'driver' => method_exists($driver, 'getName') ? $driver->getName() : null,
'serverVersion' => $this->getConfig('server_version'),
]), $driver);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Illuminate/Database/MySqlConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Illuminate\Database;

use Doctrine\DBAL\Driver\PDOMySql\Driver as DoctrineDriver;
use Doctrine\DBAL\Version;
use Illuminate\Database\PDO\MySqlDriver;
use Illuminate\Database\Query\Grammars\MySqlGrammar as QueryGrammar;
use Illuminate\Database\Query\Processors\MySqlProcessor;
use Illuminate\Database\Schema\Grammars\MySqlGrammar as SchemaGrammar;
Expand Down Expand Up @@ -57,10 +59,10 @@ protected function getDefaultPostProcessor()
/**
* Get the Doctrine DBAL driver.
*
* @return \Doctrine\DBAL\Driver\PDOMySql\Driver
* @return \Doctrine\DBAL\Driver\PDOMySql\Driver|\Illuminate\Database\PDO\MySqlDriver
*/
protected function getDoctrineDriver()
{
return new DoctrineDriver;
return class_exists(Version::class) ? new DoctrineDriver : new MySqlDriver;
}
}
18 changes: 18 additions & 0 deletions src/Illuminate/Database/PDO/Concerns/ConnectsToDatabase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Illuminate\Database\PDO\Concerns;

use Illuminate\Database\PDO\Connection;
use PDO;

trait ConnectsToDatabase
{
public function connect(array $params)
{
if (! isset($params['pdo']) || ! $params['pdo'] instanceof PDO) {
throw new \InvalidArgumentException('Laravel requires the pdo property to be set and be a PDO instance.');
}

return new Connection($params['pdo']);
}
}
117 changes: 117 additions & 0 deletions src/Illuminate/Database/PDO/Connection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

namespace Illuminate\Database\PDO;

use Doctrine\DBAL\Driver\PDO\Exception;
use Doctrine\DBAL\Driver\PDO\Result;
use Doctrine\DBAL\Driver\PDO\Statement;
use Doctrine\DBAL\Driver\Result as ResultInterface;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Driver\Statement as StatementInterface;
use Doctrine\DBAL\ParameterType;
use PDO;
use PDOException;
use PDOStatement;

class Connection implements ServerInfoAwareConnection
{
/**
* @var \PDO
*/
private $connection;

/**
* Create a new DPO connection instance.
*
* @param \PDO $connection
* @return void
*/
public function __construct(PDO $connection)
{
$this->connection = $connection;
}

public function exec(string $statement): int
{
try {
$result = $this->connection->exec($statement);

\assert($result !== false);

return $result;
} catch (PDOException $exception) {
throw Exception::new($exception);
}
}

public function getServerVersion()
{
return $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION);
}

public function prepare(string $sql): StatementInterface
{
try {
return $this->createStatement(
$this->connection->prepare($sql)
);
} catch (PDOException $exception) {
throw Exception::new($exception);
}
}

public function query(string $sql): ResultInterface
{
try {
$stmt = $this->connection->query($sql);
\assert($stmt instanceof PDOStatement);

return new Result($stmt);
} catch (PDOException $exception) {
throw Exception::new($exception);
}
}

public function quote($input, $type = ParameterType::STRING)
{
return $this->connection->quote($input, $type);
}

public function lastInsertId($name = null)
{
try {
if ($name === null) {
return $this->connection->lastInsertId();
}

return $this->connection->lastInsertId($name);
} catch (PDOException $exception) {
throw Exception::new($exception);
}
}

protected function createStatement(PDOStatement $stmt): Statement
{
return new Statement($stmt);
}

public function beginTransaction()
{
return $this->connection->beginTransaction();
}

public function commit()
{
return $this->connection->commit();
}

public function rollBack()
{
return $this->connection->rollBack();
}

public function getWrappedConnection(): PDO
{
return $this->connection;
}
}

0 comments on commit 1b7ee16

Please sign in to comment.