Skip to content

Commit

Permalink
Update Dsn, update dev dependencies and pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw authored and devanych committed Dec 19, 2020
1 parent 343e2c3 commit bdc1585
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 114 deletions.
30 changes: 11 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
name: PHP ${{ matrix.php }}-mssql-${{ matrix.mssql }}

env:
extensions: dom, json, pdo, pdo_sqlsrv
extensions: pdo, pdo_sqlsrv, pdo_sqlsrv-5.9.0preview1
key: cache

runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v2.3.4

- name: Create MS SQL Database
run: docker exec -i mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'CREATE DATABASE yiitest'
Expand All @@ -58,7 +58,7 @@ jobs:
key: ${{ env.key }}

- name: Cache extensions
uses: actions/cache@v2.1.1
uses: actions/cache@v2
with:
path: ${{ steps.cache.outputs.dir }}
key: ${{ steps.cache.outputs.key }}
Expand All @@ -73,25 +73,21 @@ jobs:
coverage: pcov
tools: composer:v2, pecl

- name: install pecl pdo_sqlsrv support PHP 8.0
if: matrix.php == '8.0'
run: sudo pecl install pdo_sqlsrv-5.9.0preview1

- name: Determine composer cache directory on Linux
if: matrix.os == 'ubuntu-latest'
run: echo "::set-env name=COMPOSER_CACHE_DIR::$(composer config cache-dir)"
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Determine composer cache directory on Windows
if: matrix.os == 'windows-latest'
run: ECHO "::set-env name=COMPOSER_CACHE_DIR::~\AppData\Local\Composer"
run: echo "COMPOSER_CACHE_DIR=~\AppData\Local\Composer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: Cache dependencies installed with composer
uses: actions/cache@v2.1.1
uses: actions/cache@v2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-${{ matrix.dependencies }}-
php${{ matrix.php }}-composer-
- name: Install dependencies with composer php 7.4
if: matrix.php == '7.4'
Expand All @@ -102,15 +98,11 @@ jobs:
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run tests with phpunit and coverage on Linux php 7.4
if: matrix.php == '7.4' && matrix.mssql == 'server:2019-latest'
if: matrix.os == 'ubuntu-latest' && matrix.php == '7.4'
run: vendor/bin/phpunit --coverage-clover=coverage.clover --colors=always

- name: Run tests with phpunit on Linux php 7.4
if: matrix.php == '7.4' && matrix.mssql == 'server:2017-latest'
run: vendor/bin/phpunit --colors=always

- name: Run tests with phpunit Linux php 8.0
if: matrix.php == '8.0'
- name: Run tests with phpunit without coverage
if: matrix.os != 'ubuntu-latest' || matrix.php != '7.4'
run: vendor/bin/phpunit --colors=always

- name: Code coverage
Expand Down
23 changes: 11 additions & 12 deletions .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

env:
extensions: dom, json, libxml, pdo, pdo_sqlsrv
extensions: pdo, pdo_sqlsrv

runs-on: ${{ matrix.os }}

Expand All @@ -35,26 +35,26 @@ jobs:
options: --name=mssql --health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'SELECT 1'" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: Checkout
uses: actions/checkout@v2.3.4

- name: Create MS SQL Database
run: docker exec -i mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'CREATE DATABASE yiitest'

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
extensions: ${{ env.extensions }}
ini-values: memory_limit=-1
coverage: "pcov"
coverage: pcov
tools: composer:v2, pecl

- name: Determine composer cache directory
run: echo "::set-env name=COMPOSER_CACHE_DIR::$(composer config cache-dir)"
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v2.1.1
uses: actions/cache@v2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
Expand All @@ -64,10 +64,9 @@ jobs:
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run test mutation infection with coverage
- name: Run infection
run: |
mkdir -p build/logs
vendor/bin/phpunit --coverage-xml=build/logs/coverage-xml --log-junit=build/logs/junit.xml --colors=always
vendor/bin/infection --threads=2 --coverage=build/logs --show-mutations --no-progress
git fetch --depth=1 origin $GITHUB_BASE_REF
vendor/bin/roave-infection-static-analysis-plugin -j2 --git-diff-filter=A --git-diff-base=origin/$GITHUB_BASE_REF --logger-github --ignore-msi-with-no-mutations --only-covered
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
12 changes: 6 additions & 6 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ jobs:
- "7.4"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: Checkout
uses: actions/checkout@v2.3.4

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
extensions: ${{ env.extensions }}
Expand All @@ -35,7 +35,7 @@ jobs:
tools: composer:v2, cs2pr, pecl,

- name: Determine composer cache directory
run: echo "::set-env name=COMPOSER_CACHE_DIR::$(composer config cache-dir)"
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v1
Expand All @@ -48,5 +48,5 @@ jobs:
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Static analysis with phan
- name: Static analysis
run: vendor/bin/psalm --shepherd --stats --output-format=checkstyle | cs2pr --graceful-warnings --colorize
34 changes: 24 additions & 10 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
build:
environment:
php: "7.4"
nodes:
analysis:
tests:
override:
- php-scrutinizer-run
checks:
php: true

filter:
paths:
- "src/*"
checks:
php: true

tools:
php_code_coverage:
enabled: true
external_code_coverage:
timeout: 600

build:
environment:
php: 7.4.12
nodes:
analysis:
tests:
override:
- php-scrutinizer-run
dependencies:
override:
- composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
tests:
override:
-
command: "./vendor/bin/phpunit --coverage-clover ./coverage.xml"
on_node: 1
coverage:
file: coverage.xml
format: php-clover
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,14 @@ Using yiisoft/composer-config-plugin automatically get the settings of `CacheInt
Di-Container:

```php
use Psr\Log\LoggerInterface;
use Yiisoft\Cache\CacheInterface;
use Yiisoft\Db\Mssql\Connection as MssqlConnection;
use Yiisoft\Factory\Definitions\Reference;
use Yiisoft\Profiler\Profiler;

return [
MssqlConnection::class => [
'__class' => MssqlConnection::class,
'__construct()' => [
Reference::to(CacheInterface::class),
Reference::to(LoggerInterface::class),
Reference::to(Profiler::class),
$params['yiisoft/db-mssql']['dsn']
'dsn' => $params['yiisoft/db-mssql']['dsn']
],
'setUsername()' => [$params['yiisoft/db-mssql']['username']],
'setPassword()' => [$params['yiisoft/db-mssql']['password']]
Expand All @@ -60,11 +54,11 @@ return [
Params.php

```php
use Yiisoft\Db\Mssql\Dsn as MssqlDsn;
use Yiisoft\Db\Mssql\Dsn;

return [
'yiisoft/db-mssql' => [
'dsn' => (new MssqlDsn('sqlsrv', '127.0.0.1', 'yiitest', '1433'))->getDsn(),
'dsn' => (new Dsn('sqlsrv', '127.0.0.1', 'yiitest', '1433'))->asString(),
'username' => 'SA',
'password' => 'YourStrong!Passw0rd'
]
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"yiisoft/db": "^3.0@dev"
},
"require-dev": {
"infection/infection": "^0.16.6",
"phpunit/phpunit": "^9.3",
"vimeo/psalm": "^3.15",
"phpunit/phpunit": "^9.4",
"roave/infection-static-analysis-plugin": "^1.3",
"vimeo/psalm": "^4.1",
"yiisoft/aliases": "^1.0",
"yiisoft/cache": "^3.0@dev",
"yiisoft/di": "^3.0@dev",
Expand Down
16 changes: 10 additions & 6 deletions src/Dsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

final class Dsn
{
private string $database;
private string $databaseName;
private string $driver;
private string $server;
private string $port;

public function __construct(string $driver, string $server, string $database, string $port = '1433')
public function __construct(string $driver, string $server, string $databaseName, string $port = '1433')
{
$this->driver = $driver;
$this->server = $server;
$this->database = $database;
$this->databaseName = $databaseName;
$this->port = $port;
}

Expand All @@ -28,15 +28,19 @@ public function __construct(string $driver, string $server, string $database, st
*
* ```php
* $dsn = new MssqlDsn('sqlsrv', 'localhost', 'yiitest', '1433');
* $connection = new MssqlConnection($this->cache, $this->logger, $this->profiler, $dsn->getDsn());
* $connection = new MssqlConnection($this->cache, $this->logger, $this->profiler, $dsn->asString());
* ```
*
* Will result in the DSN string `sqlsrv:Server=localhost,1433;Database=yiitest`.
*/
public function asString(): string
{
return "$this->driver:" . "Server=$this->server," . "$this->port" . ";Database=$this->databaseName";
}

public function getDsn(): string
public function __toString(): string
{
return "$this->driver:" . "Server=$this->server," . "$this->port;" . "Database=$this->database";
return $this->asString();
}

public function getDriver(): string
Expand Down
10 changes: 5 additions & 5 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public function testConstruct(): void
$this->assertEquals($this->cache, $db->getSchemaCache());
$this->assertEquals($this->logger, $db->getLogger());
$this->assertEquals($this->profiler, $db->getProfiler());
$this->assertEquals($this->dsn->getDsn(), $db->getDsn());
$this->assertEquals($this->params()['yiisoft/db-mssql']['dsn'], $db->getDsn());
}

public function testGetDriverName(): void
{
$db = $this->getConnection();

$this->assertEquals($this->dsn->getDriver(), $db->getDriverName());
$this->assertEquals('sqlsrv', $db->getDriverName());
}

public function testOpenClose(): void
Expand Down Expand Up @@ -141,7 +141,7 @@ public function testGetPdoAfterClose(): void
$this->cache,
$this->logger,
$this->profiler,
$this->dsn->getDsn()
$this->params()['yiisoft/db-mssql']['dsn']
],
'setUsername()' => [$db->getUsername()],
'setPassword()' => [$db->getPassword()]
Expand Down Expand Up @@ -176,7 +176,7 @@ public function testServerStatusCacheWorks(): void
$this->cache,
$this->logger,
$this->profiler,
$this->dsn->getDsn()
$this->params()['yiisoft/db-mssql']['dsn']
],
'setUsername()' => [$db->getUsername()],
'setPassword()' => [$db->getPassword()]
Expand Down Expand Up @@ -250,7 +250,7 @@ public function testServerStatusCacheCanBeDisabled(): void
$this->cache,
$this->logger,
$this->profiler,
$this->dsn->getDsn()
$this->params()['yiisoft/db-mssql']['dsn']
],
'setUsername()' => [$db->getUsername()],
'setPassword()' => [$db->getPassword()]
Expand Down
Loading

0 comments on commit bdc1585

Please sign in to comment.