diff --git a/.github/workflows/coding-styles.yml b/.github/workflows/coding-styles.yml new file mode 100644 index 0000000..450c052 --- /dev/null +++ b/.github/workflows/coding-styles.yml @@ -0,0 +1,35 @@ +name: "Coding Styles" + +on: [push, pull_request] + +jobs: + tests: + name: Coding Styles + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + php: + - 8.2 + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: xdebug + ini-values: memory_limit=1G + tools: cs2pr + + - name: Validate Composer files + run: composer validate --no-check-all --strict + + - name: Install Composer dependencies + run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader + + - name: Coding styles + run: php vendor/bin/php-cs-fixer fix --verbose --dry-run --format=checkstyle | cs2pr diff --git a/src/ARC2/Store/Adapter/AbstractAdapter.php b/src/ARC2/Store/Adapter/AbstractAdapter.php index cdbc7fd..33e682f 100644 --- a/src/ARC2/Store/Adapter/AbstractAdapter.php +++ b/src/ARC2/Store/Adapter/AbstractAdapter.php @@ -28,7 +28,7 @@ abstract class AbstractAdapter protected $queries = []; /** - * @param array $configuration Default is array(). + * @param array $configuration default is array() */ public function __construct(array $configuration = []) { diff --git a/src/ARC2/Store/Adapter/PDOAdapter.php b/src/ARC2/Store/Adapter/PDOAdapter.php index 26b7923..02623d1 100644 --- a/src/ARC2/Store/Adapter/PDOAdapter.php +++ b/src/ARC2/Store/Adapter/PDOAdapter.php @@ -12,8 +12,6 @@ namespace ARC2\Store\Adapter; -use Exception; - /** * PDO Adapter - Handles database operations using PDO. */ @@ -242,7 +240,7 @@ public function getServerVersion(): string return $this->db->query('select version()')->fetchColumn(); } - throw new Exception('You need to connect to DB server first. Use connect() before this function.'); + throw new \Exception('You need to connect to DB server first. Use connect() before this function.'); } public function getErrorCode() diff --git a/tests/db_adapter_depended/store/ARC2_StoreTest.php b/tests/db_adapter_depended/store/ARC2_StoreTest.php index 877eb1e..ba60525 100644 --- a/tests/db_adapter_depended/store/ARC2_StoreTest.php +++ b/tests/db_adapter_depended/store/ARC2_StoreTest.php @@ -320,10 +320,10 @@ public function testEnableFulltextSearch() // just check pattern public function testGetDBVersion() { - $pattern = '/[0-9]{1,}\.[0-9]{1,}\.[0-9]{2}/'; - - $result = preg_match($pattern, $this->fixture->getDBVersion(), $match); - $this->assertEquals(1, $result, $this->fixture->getDBVersion()); + $this->assertEquals( + $this->fixture->getDBObject()->getConnection()->query('select version()')->fetchColumn(), + $this->fixture->getDBVersion() + ); } /* diff --git a/tests/integration/src/ARC2/Store/Adapter/AbstractAdapterTest.php b/tests/integration/src/ARC2/Store/Adapter/AbstractAdapterTest.php index e42b4b1..eee0a33 100644 --- a/tests/integration/src/ARC2/Store/Adapter/AbstractAdapterTest.php +++ b/tests/integration/src/ARC2/Store/Adapter/AbstractAdapterTest.php @@ -227,10 +227,10 @@ public function testQuery() public function testGetServerVersion() { - $pattern = '/[0-9]{1,}\.[0-9]{1,}\.[0-9]{2}/'; - - // check that server version looks like 5.5.21 - $this->assertEquals(1, preg_match($pattern, $this->fixture->getServerVersion())); + $this->assertEquals( + $this->fixture->getConnection()->query('select version()')->fetchColumn(), + $this->fixture->getServerVersion() + ); } /*