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
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
### Static analysis

To run static analysis:
- psalm
- phpstan
- [psalm](https://psalm.dev/)
- [phpstan](https://phpstan.org/)

```shell
make check
```

To fix code style:
- [phpcs](https://github.com/squizlabs/PHP_CodeSniffer)
- [rector](https://getrector.com/)

```shell
make fix
```

### Testing

The package is tested with
Expand Down
18 changes: 13 additions & 5 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@

declare(strict_types=1);

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\DeadCode\Rector\Node\RemoveNonExistingVarAnnotationRector;
use Rector\Set\ValueObject\SetList;

return Rector\Config\RectorConfig::configure()
->withPaths(
[
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__ . '/example',
]
)
->withParallel()
->withCache('/tmp/var/rector')
->withPhpSets()
->withRules(
->withPhpSets(php83: true)
->withSets(
[
InlineConstructorDefaultToPropertyRector::class,
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
SetList::PRIVATIZATION,
SetList::TYPE_DECLARATION_DOCBLOCKS,
]
)
->withSkip(
[
RemoveNonExistingVarAnnotationRector::class,
]
);
2 changes: 1 addition & 1 deletion src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private function makeConnection(): ConnectionInterface
* @note если вдруг экземпляр класса Migrator будет использоваться как сервис, то переиспользуем коннект.
* Но с ограничением по времени, долго держать в памяти не будем.
*/
if ($this->connectionInstance === null || $this->connectionTimer < time()) {
if (!$this->connectionInstance instanceof Connection || $this->connectionTimer < time()) {
$this->connectionTimer = time() + $timeout;
try {
return $this->connectionInstance = new Connection(
Expand Down
2 changes: 1 addition & 1 deletion src/internal/ErrorInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public function getMessage(): string
#[\Override]
public function __toString(): string
{
return $this->getMessage();
return $this->message;
}
}
21 changes: 17 additions & 4 deletions tests/workflow/StatementMysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Override;
use Throwable;
use PDO;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use dbschemix\core\connection\TransactionInterface;
use dbschemix\pdo\internal\Connection;
Expand Down Expand Up @@ -55,16 +56,28 @@ public function testExecActiveTransaction(): void
}

/**
* @return iterable<non-empty-string[]>
*/
public static function additionSchemaQuery(): iterable
{
yield ['CREATE TABLE IF NOT EXISTS test (name TEXT PRIMARY KEY, version INTEGER DEFAULT 0, atime TEXT)'];
yield ['ALTER TABLE migration ADD COLUMN test TEXT DEFAULT NULL'];
yield ['CREATE UNIQUE INDEX IF NOT EXISTS `UI_migration_name` ON migration (name)'];
yield ['DROP INDEX IF EXISTS `UI_migration_name`'];
yield ['DROP TABLE IF EXISTS test'];
}

/**
* @param non-empty-string $query
* @throws Throwable
*/
public function testExecNotActiveTransaction(): void
#[DataProvider('additionSchemaQuery')]
public function testExecNotActiveTransaction(string $query): void
{
// default: false
self::assertFalse($this->transaction->isActive());

$this->transaction->exec(
"CREATE TABLE test (name TEXT PRIMARY KEY, version INTEGER DEFAULT 0, atime TEXT)"
);
$this->transaction->exec($query);

// statement CREATE TABLE: false
self::assertFalse($this->transaction->isActive());
Expand Down
Loading