Skip to content
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
23 changes: 22 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,28 @@ name: CI
on: [push, pull_request]

jobs:
phpcs:
name: Code style
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
tools: phpcs

- name: Check production code style
run: composer cs-prod

- name: Check test code style
run: composer cs-tests

tests:
name: Unit tests
runs-on: ubuntu-latest

services:
Expand Down Expand Up @@ -53,7 +74,7 @@ jobs:
run: /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'P@ssw0rd' -Q 'CREATE DATABASE codeception_test'

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
14 changes: 14 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,26 @@
"ext-pdo": "*",
"codeception/codeception": "*@dev"
},
"require-dev": {
"squizlabs/php_codesniffer": "*"
},
"conflict": {
"codeception/codeception": "<5.0"
},
"autoload":{
"classmap": ["src/"]
},
"autoload-dev": {
"classmap": ["tests/"]
},
"scripts": {
"cs-prod": "phpcs src/",
"cs-tests": "phpcs tests/ --standard=tests/phpcs.xml"
},
"scripts-descriptions": {
"cs-prod": "Check production code style",
"cs-tests": "Check test code style"
},
"config": {
"classmap-authoritative": true,
"sort-packages": true
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.amd64.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.9'

services:
php:
platform: linux/amd64
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.9"

services:
php:
container_name: codeception-module-db
Expand Down
8 changes: 8 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ruleset name="Codeception">
<description>Codeception code standard</description>
<rule ref="PSR12">
<exclude name="Generic.Files.LineLength.TooLong"/>
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
</rule>
</ruleset>
2 changes: 1 addition & 1 deletion src/Codeception/Lib/DbPopulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected function buildCommand(string $command, string $dumpFile = null): strin

foreach ($vars as $key => $value) {
if (!is_array($value)) {
$vars['$'.$key] = $value;
$vars['$' . $key] = $value;
}

unset($vars[$key]);
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Lib/Driver/MySql.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getPrimaryKey(string $tableName): array
$columns = $stmt->fetchAll(PDO::FETCH_ASSOC);

foreach ($columns as $column) {
$primaryKey []= $column['Column_name'];
$primaryKey[] = $column['Column_name'];
}
$this->primaryKeys[$tableName] = $primaryKey;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Lib/Driver/Oci.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function getPrimaryKey(string $tableName): array
$columns = $stmt->fetchAll(\PDO::FETCH_ASSOC);

foreach ($columns as $column) {
$primaryKey []= $column['COLUMN_NAME'];
$primaryKey[] = $column['COLUMN_NAME'];
}

$this->primaryKeys[$tableName] = $primaryKey;
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Lib/Driver/PostgreSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function getPrimaryKey(string $tableName): array
$stmt = $this->executeQuery($query, []);
$columns = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($columns as $column) {
$primaryKey []= $column['attname'];
$primaryKey[] = $column['attname'];
}

$this->primaryKeys[$tableName] = $primaryKey;
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Lib/Driver/SqlSrv.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getPrimaryKey(string $tableName): array
$columns = $stmt->fetchAll(PDO::FETCH_ASSOC);

foreach ($columns as $column) {
$primaryKey []= $column['Column_Name'];
$primaryKey[] = $column['Column_Name'];
}

$this->primaryKeys[$tableName] = $primaryKey;
Expand Down
6 changes: 3 additions & 3 deletions src/Codeception/Lib/Driver/Sqlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Sqlite extends Db
{
protected bool $hasSnapshot = false;

protected string $filename = '';

public function __construct(string $dsn, string $user = null, string $password = null, array $options = null)
Expand Down Expand Up @@ -47,7 +47,7 @@ public function load(array $sql): void
if (file_exists($this->filename . '_snapshot')) {
unlink($this->filename . '_snapshot');
}

parent::load($sql);
copy($this->filename, $this->filename . '_snapshot');
$this->hasSnapshot = true;
Expand All @@ -71,7 +71,7 @@ public function getPrimaryKey(string $tableName): array

foreach ($columns as $column) {
if ($column['pk'] !== '0' && $column['pk'] !== 0) {
$primaryKey []= $column['name'];
$primaryKey[] = $column['name'];
}
}

Expand Down
19 changes: 12 additions & 7 deletions src/Codeception/Module/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,38 +565,43 @@ private function connect($databaseKey, $databaseConfig): void

$options = [];

if (array_key_exists('ssl_key', $databaseConfig)
if (
array_key_exists('ssl_key', $databaseConfig)
&& !empty($databaseConfig['ssl_key'])
&& defined(PDO::class . '::MYSQL_ATTR_SSL_KEY')
) {
$options[PDO::MYSQL_ATTR_SSL_KEY] = (string) $databaseConfig['ssl_key'];
}

if (array_key_exists('ssl_cert', $databaseConfig)
if (
array_key_exists('ssl_cert', $databaseConfig)
&& !empty($databaseConfig['ssl_cert'])
&& defined(PDO::class . '::MYSQL_ATTR_SSL_CERT')
) {
$options[PDO::MYSQL_ATTR_SSL_CERT] = (string) $databaseConfig['ssl_cert'];
}

if (array_key_exists('ssl_ca', $databaseConfig)
if (
array_key_exists('ssl_ca', $databaseConfig)
&& !empty($databaseConfig['ssl_ca'])
&& defined(PDO::class . '::MYSQL_ATTR_SSL_CA')
) {
$options[PDO::MYSQL_ATTR_SSL_CA] = (string) $databaseConfig['ssl_ca'];
}

if (array_key_exists('ssl_cipher', $databaseConfig)
if (
array_key_exists('ssl_cipher', $databaseConfig)
&& !empty($databaseConfig['ssl_cipher'])
&& defined(PDO::class . '::MYSQL_ATTR_SSL_CIPHER')
) {
$options[PDO::MYSQL_ATTR_SSL_CIPHER] = (string) $databaseConfig['ssl_cipher'];
}

if (array_key_exists('ssl_verify_server_cert', $databaseConfig)
if (
array_key_exists('ssl_verify_server_cert', $databaseConfig)
&& defined(PDO::class . '::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT')
) {
$options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = (boolean) $databaseConfig[ 'ssl_verify_server_cert' ];
$options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = (bool) $databaseConfig[ 'ssl_verify_server_cert' ];
}

try {
Expand Down Expand Up @@ -672,7 +677,7 @@ protected function removeInserted($databaseKey = null): void
try {
$this->_getDriver()->deleteQueryByCriteria($row['table'], $row['primary']);
} catch (Exception $e) {
$this->debug("Couldn't delete record " . json_encode($row['primary'], JSON_THROW_ON_ERROR) ." from {$row['table']}");
$this->debug("Couldn't delete record " . json_encode($row['primary'], JSON_THROW_ON_ERROR) . " from {$row['table']}");
}
}

Expand Down
9 changes: 9 additions & 0 deletions tests/phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<ruleset name="Codeception">
<description>Codeception code standard</description>
<rule ref="PSR12">
<exclude name="Generic.Files.LineLength.TooLong"/>
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace"/>
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
</rule>
</ruleset>
9 changes: 4 additions & 5 deletions tests/support/UnitTester.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


/**
* Inherited Methods
* @method void wantToTest($text)
Expand All @@ -15,12 +14,12 @@
* @method void pause()
*
* @SuppressWarnings(PHPMD)
*/
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;

/**
* Define custom actions here
*/
/**
* Define custom actions here
*/
}
22 changes: 9 additions & 13 deletions tests/unit/Codeception/Lib/Driver/DbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,29 @@
use Codeception\Test\Unit;
use Codeception\Util\ReflectionHelper;

/**
* @group appveyor
* @group db
*/
final class DbTest extends Unit
{
/**
* @dataProvider getWhereCriteria
*/
public function testGenerateWhereClause(array $criteria, string $expectedResult)
{
$db = new Db('sqlite:tests/data/sqlite.db','root','');
$db = new Db('sqlite:tests/data/sqlite.db', 'root', '');
$result = ReflectionHelper::invokePrivateMethod($db, 'generateWhereClause', [&$criteria]);
$this->assertSame($expectedResult, $result);
}

public function getWhereCriteria(): array
{
return [
'like' => [['email like' => 'mail.ua'], 'WHERE "email" LIKE ? '],
'<=' => [['id <=' => '5'], 'WHERE "id" <= ? '],
'<' => [['id <' => '5'], 'WHERE "id" < ? '],
'>=' => [['id >=' => '5'], 'WHERE "id" >= ? '],
'>' => [['id >' => '5'], 'WHERE "id" > ? '],
'!=' => [['id !=' => '5'], 'WHERE "id" != ? '],
'is null' => [['id' => null], 'WHERE "id" IS NULL '],
'is not null' => [['id !=' => null], 'WHERE "id" IS NOT NULL '],
'like' => [['email like' => 'mail.ua'], 'WHERE "email" LIKE ? '],
'<=' => [['id <=' => '5'], 'WHERE "id" <= ? '],
'<' => [['id <' => '5'], 'WHERE "id" < ? '],
'>=' => [['id >=' => '5'], 'WHERE "id" >= ? '],
'>' => [['id >' => '5'], 'WHERE "id" > ? '],
'!=' => [['id !=' => '5'], 'WHERE "id" != ? '],
'is null' => [['id' => null], 'WHERE "id" IS NULL '],
'is not null' => [['id !=' => null], 'WHERE "id" IS NOT NULL '],
];
}
}
11 changes: 2 additions & 9 deletions tests/unit/Codeception/Lib/Driver/MysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
use Codeception\Lib\Driver\MySql;
use Codeception\Test\Unit;

/**
* @group appveyor
* @group db
*/
final class MysqlTest extends Unit
{
protected static array $config = [
Expand Down Expand Up @@ -69,9 +65,6 @@ public function testCleanupDatabase()
$this->assertEmpty($this->mysql->getDbh()->query("SHOW TABLES")->fetchAll());
}

/**
* @group appveyor
*/
public function testLoadDump()
{
$res = $this->mysql->getDbh()->query("select * from users where name = 'davert'");
Expand Down Expand Up @@ -108,7 +101,7 @@ public function testInsertIntoBitField()
{
$res = $this->mysql->executeQuery(
"insert into `users`(`id`,`name`,`email`,`is_active`,`created_at`) values (?,?,?,?,?)",
[5,'insert.test','insert.test@mail.ua',false,'2012-02-01 21:17:47']
[5, 'insert.test', 'insert.test@mail.ua', false, '2012-02-01 21:17:47']
);
$this->assertSame(1, $res->rowCount());
}
Expand All @@ -123,7 +116,7 @@ public function testLoadThrowsExceptionWhenDumpFileContainsSyntaxError()
'check the manual that corresponds to your MySQL server version for the right syntax to use near ' .
"'VALS('')' at line 1\nSQL query being executed: \n" . $sql;
$this->expectException(ModuleException::class);
$this->expectExceptionMessage( $expectedMessage);
$this->expectExceptionMessage($expectedMessage);
$this->mysql->load([$sql]);
}
}
6 changes: 1 addition & 5 deletions tests/unit/Codeception/Lib/Driver/PostgresTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
use Codeception\Lib\Driver\PostgreSql;
use Codeception\Test\Unit;

/**
* @group appveyor
* @group db
*/
final class PostgresTest extends Unit
{
protected static array $config = [
Expand Down Expand Up @@ -141,7 +137,7 @@ public function testGetEmptyArrayIfTableHasNoPrimaryKey()

public function testLastInsertIdReturnsSequenceValueWhenNonStandardSequenceNameIsUsed()
{
$this->postgres->executeQuery('INSERT INTO seqnames(name) VALUES(?)',['test']);
$this->postgres->executeQuery('INSERT INTO seqnames(name) VALUES(?)', ['test']);
$this->assertSame('1', $this->postgres->lastInsertId('seqnames'));
}

Expand Down
4 changes: 0 additions & 4 deletions tests/unit/Codeception/Lib/Driver/SqliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
use Codeception\Lib\Driver\Sqlite;
use Codeception\Test\Unit;

/**
* @group db
* Class SqliteTest
*/
final class SqliteTest extends Unit
{
/**
Expand Down
7 changes: 0 additions & 7 deletions tests/unit/Codeception/Module/Db/MssqlDblibDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

declare(strict_types=1);

use Codeception\Configuration;

require_once Configuration::testsDir() . 'unit/Codeception/Module/Db/AbstractDbTest.php';

/**
* @group db
*/
final class MssqlDblibDbTest extends AbstractDbTest
{
public function getPopulator(): string
Expand Down
7 changes: 0 additions & 7 deletions tests/unit/Codeception/Module/Db/MssqlSqlSrvDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

declare(strict_types=1);

use Codeception\Configuration;

require_once Configuration::testsDir() . 'unit/Codeception/Module/Db/AbstractDbTest.php';

/**
* @group db
*/
final class MssqlSqlSrvDbTest extends AbstractDbTest
{
public function getPopulator(): string
Expand Down
Loading