cspray/database-testing-pdo
Composer 安装命令:
composer require cspray/database-testing-pdo
包简介
PDO ConnectionAdapter for cspray/database-testing
README 文档
README
A connection adapter for cspray/database-testing that allows you to
use a PDO connection for testing database interactions.
Installation
Composer is the only supported means to install this package.
composer require --dev cspray/database-testing-pdo
Quick Start
This library works by providing an implementation of the Cspray\DatabaseTesting\ConnectionAdapter\ConnectionAdapter interface, along with a variety of Cspray\DatabaseTesting\ConnectionAdapter\ConnectionAdapterFactory implementations designed to work with common databases. Check out the example appropriate for your database below or check out the "Database Connection Adapter Reference"!
All examples below will use code from the cspray/database-testing-phpunit extension. If you're using a different testing framework you may need to adjust your code as appropriate.
Postgres
<?php declare(strict_types=1); namespace Cspray\DatabaseTesting\Pdo\Demo; use Cspray\DatabaseTesting\ConnectionAdapter\ConnectionAdapterConfig; use Cspray\DatabaseTesting\DatabaseCleanup\TransactionWithRollback; use Cspray\DatabaseTesting\RequiresTestDatabase; use Cspray\DatabaseTesting\Pdo\Postgres\PostgresConnectionAdapterFactory; use PHPUnit\Framework\TestCase; #[RequiresTestDatabase( new PostgresConnectionAdapterFactory(new ConnectionAdapterConfig( 'my_database', '127.0.0.1', 5432, 'my_user', 'my_password' )), new TransactionWithRollback() )] final class PostgresDemoTest extends TestCase { }
MySql
<?php declare(strict_types=1); namespace Cspray\DatabaseTesting\Pdo\Demo; use Cspray\DatabaseTesting\ConnectionAdapter\ConnectionAdapterConfig; use Cspray\DatabaseTesting\DatabaseCleanup\TransactionWithRollback; use Cspray\DatabaseTesting\RequiresTestDatabase; use Cspray\DatabaseTesting\Pdo\Postgres\PostgresConnectionAdapterFactory; use PHPUnit\Framework\TestCase; #[RequiresTestDatabase( new PostgresConnectionAdapterFactory(new ConnectionAdapterConfig( 'my_database', '127.0.0.1', 5432, 'my_user', 'my_password' )), new TransactionWithRollback() )] final class PostgresDemoTest extends TestCase { }
Sqlite
<?php declare(strict_types=1); namespace Cspray\DatabaseTesting\Pdo\Demo; use Cspray\DatabaseTesting\ConnectionAdapter\ConnectionAdapterConfig; use Cspray\DatabaseTesting\DatabaseCleanup\TransactionWithRollback; use Cspray\DatabaseTesting\RequiresTestDatabase; use Cspray\DatabaseTesting\Pdo\Sqlite\SqliteConnectionAdapterFactory; use PHPUnit\Framework\TestCase; #[RequiresTestDatabase( // The default file path for Sqlite is an in-memory database // Provide the path to the SQL file that should be loaded when // the database is created // if you're using a persisted file, provide it as the first argument // and remove the initial schema path new SqliteConnectionAdapterFactory( initialSchemaPath: __DIR__ . '/schemas/sqlite.sql' ), new TransactionWithRollback() )] final class SqliteDemoTest extends TestCase { }
Database Connection Adapter Reference
| Database | ConnectionAdapterFactory |
|---|---|
| Postgres | Cspray\DatabaseTesting\Pdo\Postgres\PostgresConnectionAdapterFactory |
| MySql | Cspray\DatabaseTesting\Pdo\Mysql\MysqlConnectionAdapterFactory |
| SQLite | Cspray\DatabaseTesting\Pdo\Sqlite\SqliteConnectionAdapterFactory |
Running Tests
By the nature of this library, we need to interact with a database during our tests. This presents some challenges and concessions that otherwise wouldn't be present when writing tests. Most importantly, that means we need to have multiple running database servers. To run tests for this library you must use docker compose run --rm tests. This will ensure the appropriate database servers are up and running so tests have something to connect to.
cspray/database-testing-pdo 适用场景与选型建议
cspray/database-testing-pdo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 cspray/database-testing-pdo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cspray/database-testing-pdo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: Unknown
- 更新时间: 2025-05-08