klako / mocknet
Scoutnet的复制品。
v0.3
2022-03-28 21:39 UTC
Requires
- php: >=7.3
- ext-mbstring: *
- ext-pdo: *
- doctrine/annotations: ^1.13
- doctrine/orm: ^2.9.2
- fzaninotto/faker: ^1.9
- slim/psr7: ^1.0
- slim/slim: ^4.4
- symfony/cache: ^5.3
- symfony/process: ^5.0
- tuupola/slim-basic-auth: ^3.2
Requires (Dev)
- ext-pdo_sqlite: *
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-22 17:31:46 UTC
README
Mocknet是一个轻量级的Scoutnet API复制品,使用假数据用于测试环境。
安装
使用以下命令使用composer安装包:composer require klako/mocknet
该包需要一些与Doctrine兼容的数据库,例如sqlite或mysql。创建数据库连接的参数可以在Doctrine文档中找到
运行应用程序
有三种运行应用程序的方法。
使用Scouterna\Mocknet\PhpServer
以下代码将在指定的主机地址和端口上启动内部PHP网络服务器。
$server = new Scouterna\Mocknet\PhpServer( "localhost", "8080", $databaseParams, // parameters for the database connection as specified above 444, // The group id to be required in the api calls "abcdefghikjlmn" // The api key to be required in the api calls ); $server->start();
使用Scouterna\Mocknet\ServerApp
以下代码将在您的现有应用程序中程序化运行应用程序。
Scouterna\Mocknet\ServerApp::run( $connection, // A Doctrine\DBAL\Connection or parameters for the database connection 444, // The group id to be required in the api calls "abcdefghikjlmn" // The api key to be required in the api calls );
使用server.php
server.php文件可以用作网络服务器的入口点。
必须指定以下环境变量。
MOCKNET_VENDOR_FOLDER
composer vendor文件夹的路径MOCKNET_DBPARAMS
包含数据库参数的base64编码json对象MOCKNET_GROUP_ID
API调用中所需的组IDMOCKNET_API_KEY
API调用中所需的API密钥
生成和读取数据库
为了简单生成一个组,使用以下环境变量运行generator.php文件。
MOCKNET_VENDOR_FOLDER
composer vendor文件夹的路径MOCKNET_DBPARAMS
包含数据库参数的base64编码json对象MOCKNET_GROUP_ID
生成组的组ID
为了创建一个既可以读取也可以写入数据库的管理器,使用Scouterna\Mocknet\Database\ManagerFactory
类。命名空间Scouterna\Mocknet\Database\Model
包含管理器和API使用的所有实体。