Skip to content

Commit

Permalink
Merge pull request #4 from o0h/release-v2
Browse files Browse the repository at this point in the history
Release v2
  • Loading branch information
o0h authored Feb 24, 2020
2 parents c8daf2f + caa9e74 commit 59d70ad
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ composer.lock
tests/test_app/database/data
tests/test_app/vendor
.php_cs.cache
.phpunit.result.cache
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"require-dev": {
"phpunit/phpunit": "^8.5",
"cakephp/cakephp": "^4.0",
"cakephp/cakephp-codesniffer": "~4.0.0"
"cakephp/cakephp-codesniffer": "^4.0"
},
"license": "MIT",
"authors": [
Expand All @@ -32,6 +32,6 @@
"test": "phpunit",
"cs-check": "phpcs --colors -p ./src ./tests/TestCase",
"stan": "phpstan.phar analyse src/ tests/TestCase",
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^0.12 && mv composer.backup composer.json"
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:@stable && mv composer.backup composer.json"
}
}
7 changes: 0 additions & 7 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,4 @@
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />

<rule ref="CakePHP"/>
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes" >
<properties>
<property name="newlinesCountAfterDeclare" value="2" />
<property name="spacesCountAroundEqualsSign" value="0" />
<property name="newlinesCountBetweenOpenTagAndDeclare" value="2" />
</properties>
</rule> />
</ruleset>
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
parameters:
level: 5
level: 6
checkMissingIterableValueType: false
autoload_files:
- tests/bootstrap.php
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>

Expand Down
4 changes: 1 addition & 3 deletions src/Database/Connection/MasterReplicaConnection.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php

declare(strict_types=1);

namespace Connehito\CakephpMasterReplica\Database\Connection;

use Cake\Database\Connection;
use Cake\Database\Driver;
use Cake\Database\DriverInterface;

/**
Expand Down Expand Up @@ -53,7 +51,7 @@ public function __construct($config)
* @param string $role master or replica
* @return $this
*/
public function switchRole(string $role): self
public function switchRole(string $role)
{
$this->role = $role;
$driver = $this->getDriver();
Expand Down
20 changes: 6 additions & 14 deletions tests/TestCase/Database/Connection/MasterReplicaConnectionTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

declare(strict_types=1);

namespace Connehito\CakephpMasterReplica\Test\TestCase\Database\Connection;
Expand All @@ -13,7 +12,7 @@
use Connehito\CakephpMasterReplica\Database\Connection\MasterReplicaConnection;
use ReflectionProperty;

class MasterReplicaConnectionTest extends TestCase
final class MasterReplicaConnectionTest extends TestCase
{
/**
* @var MasterReplicaConnection
Expand All @@ -36,7 +35,7 @@ class MasterReplicaConnectionTest extends TestCase
];

/**
* {@inheritdoc}
* @inheritDoc
*/
public function setUp(): void
{
Expand All @@ -47,10 +46,8 @@ public function setUp(): void

/**
* @test
*
* @return void
*/
public function constructToSetDrivers()
public function constructToSetDrivers(): void
{
$getDriverConfig = function (DriverInterface $driver) {
$configProperty = new ReflectionProperty($driver, '_config');
Expand Down Expand Up @@ -98,10 +95,8 @@ public function constructToSetDrivers()

/**
* @test
*
* @return void
*/
public function constructToSetDefaultRole()
public function constructToSetDefaultRole(): void
{
$driversProperty = new ReflectionProperty($this->subject, 'drivers');
$driversProperty->setAccessible(true);
Expand All @@ -120,10 +115,8 @@ public function constructToSetDefaultRole()

/**
* @test
*
* @return void
*/
public function switchRole()
public function switchRole(): void
{
$roleProperty = new ReflectionProperty($this->subject, 'role');
$roleProperty->setAccessible(true);
Expand Down Expand Up @@ -159,9 +152,8 @@ public function switchRole()
* @test
*
* @depends switchRole
* @return void
*/
public function getDriver()
public function getDriver(): void
{
$driversProperty = new ReflectionProperty($this->subject, 'drivers');
$driversProperty->setAccessible(true);
Expand Down
15 changes: 5 additions & 10 deletions tests/TestCase/MasterReplicaConnectionIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

declare(strict_types=1);

namespace Connehito\CakephpMasterReplica\Test\TestCase;
Expand All @@ -10,10 +9,10 @@
use Connehito\CakephpMasterReplica\Database\Connection\MasterReplicaConnection;
use PDOException;

class MasterReplicaConnectionIntegrationTest extends TestCase
final class MasterReplicaConnectionIntegrationTest extends TestCase
{
/**
* {@inheritDoc}}
* @inheritDoc
*/
public function tearDown(): void
{
Expand All @@ -26,10 +25,8 @@ public function tearDown(): void

/**
* @test
*
* @return void
*/
public function switchRoleThenChangingSession()
public function switchRoleThenChangingSession(): void
{
$subject = ConnectionManager::get('test');
assert($subject instanceof MasterReplicaConnection);
Expand All @@ -48,10 +45,8 @@ public function switchRoleThenChangingSession()

/**
* @test
*
* @return void
*/
public function switchToReadOnlyUserThenNotWritable()
public function switchToReadOnlyUserThenNotWritable(): void
{
$table = $this->getTableLocator()->get('Users');
$query = $table->query()
Expand All @@ -72,7 +67,7 @@ public function switchToReadOnlyUserThenNotWritable()
// Secondary user is not writable, so PDO throws the exception.
$connection->switchRole('secondary');
$this->expectException(PDOException::class);
$this->expectExceptionMessageRegExp(
$this->expectExceptionMessageMatches(
"/INSERT command denied to user '(.*?)'@'(.*?)' for table 'users'/"
);
$query->cleanCopy()->execute();
Expand Down
8 changes: 4 additions & 4 deletions tests/test_app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
}
],
"require": {
"cakephp/cakephp": "^3.5",
"cakephp/cakephp": "^4.0",
"connehito/cakephp-master-replica": "@dev"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"phpstan/phpstan": "^0.11.9",
"squizlabs/php_codesniffer": "^3.4"
"phpunit/phpunit": "^8.5",
"phpstan/phpstan": "@stable",
"squizlabs/php_codesniffer": "@stable"
},
"license": "MIT",
"authors": [
Expand Down

0 comments on commit 59d70ad

Please sign in to comment.