资讯专栏INFORMATION COLUMN

何成为 QueryPHP 开发者

bigdevil_s / 626人阅读

摘要:文档开发基于单元测试实现的自动化文档当前文档开发计划功能开发当前计划功能技术债务清偿当前技术债务单元测试尽可能减少当前单元测试成为开发者需要加入我们的组织,如有相关意愿请发送邮件至小牛哥,我们会联系你的。

QueryPHP 非常欢迎各位给我们共同的伟大的作品添砖加瓦,实现为 PHP 社区提供一个好框架的美好愿景。

文档开发.基于单元测试实现的自动化文档 当前文档开发

计划功能.开发 当前计划功能

技术债务.清偿 当前技术债务

单元测试.尽可能减少 Bug 当前单元测试

成为开发者需要加入我们的组织,如有相关意愿请发送邮件至 小牛哥 <635750556@qq.com>,我们会联系你的。

成为开发者并没有什么任务负担,一切主要以你的意愿,兴趣才是最重要的。

本篇指南将带你搭建的 QueryPHP 开发框架的开发环境,使得你可以参与 QueryPHP 底层代码、单元测试和文档等开发工作。

这里以笔者的 Mac 为例子说明,其实 Windows 下面还更简单些。

克隆 queryphp 仓库

QueryPHP 框架的开发来自于从克隆主仓库开始,由于国内访问 Github 网速的问题,只需要等待一小段时间。

下载代码

$cd /data/codes/test
$git clone git@github.com:hunzhiwange/queryphp.git

Composer 安装

composer install
如果你电脑没有安装 composer,那么已经为你下载一个版本。
sudo chmod 777 ./build/composer
./build/composer install

安装过程

Cloning into "queryphp"...
remote: Enumerating objects: 54, done.
remote: Counting objects: 100% (54/54), done.
remote: Compressing objects: 100% (39/39), done.
remote: Total 17821 (delta 19), reused 36 (delta 14), pack-reused 17767
Receiving objects: 100% (17821/17821), 45.12 MiB | 693.00 KiB/s, done.
Resolving deltas: 100% (8700/8700), done.

测试是否安装成功

如果可以访问,那么恭喜你第一阶段即安装完毕。

标准后台 API 端

首先我们需要创建一个数据库来运行我们的后台,让我们对 QueryPHP 有一个直观的感受,同时方便后期开发调试等。

首先创建一个数据库

可以用 Navicat For Mysql 创建一个数据库 queryphp_development_db.

CREATE DATABASE IF NOT EXISTS queryphp_development_db DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

修改 .env

...
// Database
DATABASE_DRIVER = mysql
DATABASE_HOST = 127.0.0.1
DATABASE_PORT = 3306
DATABASE_NAME = queryphp_development_db
DATABASE_USER = root
DATABASE_PASSWORD =
...


修改为


...
// Database
DATABASE_DRIVER = mysql
DATABASE_HOST = 127.0.0.1
DATABASE_PORT = 3306
DATABASE_NAME = queryphp_development_db
DATABASE_USER = root
DATABASE_PASSWORD = 123456
...

执行数据库迁移命令

php leevel migrate:migrate

安装过程

using config file ./phinx.php
using config parser php
using migration paths
- /data/codes/test/queryphp/database/migrations
using seed paths
- /data/codes/test/queryphp/database/seeds
warning no environment specified, defaulting to: development
using adapter mysql
using database queryphp_development_db


== 20181109060739 App: migrating
== 20181109060739 App: migrated 0.0155s


== 20181112023649 Role: migrating
== 20181112023649 Role: migrated 0.0160s


== 20181112024140 User: migrating
== 20181112024140 User: migrated 0.0166s


== 20181112024211 Permission: migrating
== 20181112024211 Permission: migrated 0.0225s


== 20181112024241 UserRole: migrating
== 20181112024241 UserRole: migrated 0.0155s


== 20181112024302 RolePermission: migrating
== 20181112024302 RolePermission: migrated 0.0206s


== 20181112024416 Resource: migrating
== 20181112024416 Resource: migrated 0.0328s


== 20181112024450 PermissionResource: migrating
== 20181112024450 PermissionResource: migrated 0.0305s


== 20181203130724 Option: migrating
== 20181203130724 Option: migrated 0.0170s


== 20181203144731 Test: migrating
== 20181203144731 Test: migrated 0.0133s


All Done. Took 0.2273s

测试数据库是否正常

php leevel server 

结果

{
    count: 4,
    :trace: {
        ...
    }
}
标准后台前端端

后台 API 搭建好了,我们开始搭建前端了,前端基于 Vue-cli 3IView,首先需要安装 node 才能够跑起来。

对于开发 QueryPHP 来说,你不需要会 Vue 或者 JavaScript,所以请放心不要有心里负担。

安装前端

第一步安装前端,细节信息可以在 frontend/README.md 查看.

cd frontend
npm install -g cnpm --registry=https://registry.npm.taobao.org // Just once
cnpm install

安装过程

✔ All packages installed (1264 packages installed from npm registry, used 14s(network 13s), speed 221.08kB/s, json 1086(2.23MB), tarball 501.92kB)

运行前端

接着访问这个登陆地址.

npm run serve # npm run dev 

输入登陆用户名和密码,这个时候 QueryPHP 不再是一个冰冷的代码,而是有一个干净的带有基础权限系统的后台。

user: admin
password: 123456
运行测试用例

QueryPHP 推崇通过编写测试用例来让代码变得可维护,所以这里需要本地开发跑通测试用例。

首先创建一个数据库

可以用 Navicat For Mysql 创建一个数据库 queryphp_development_test.

CREATE DATABASE IF NOT EXISTS queryphp_development_test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

修改 .env

...
// Database
DATABASE_DRIVER = mysql
DATABASE_HOST = 127.0.0.1
DATABASE_PORT = 3306
DATABASE_NAME = test
DATABASE_USER = root
DATABASE_PASSWORD =
...


修改为


...
// Database
DATABASE_DRIVER = mysql
DATABASE_HOST = 127.0.0.1
DATABASE_PORT = 3306
DATABASE_NAME = queryphp_development_test
DATABASE_USER = root
DATABASE_PASSWORD = 123456
...

执行数据库迁移命令

php leevel migrate:migrate -e testing

安装过程

using config file ./phinx.php
using config parser php
using migration paths
- /data/codes/test/queryphp/database/migrations
using seed paths
- /data/codes/test/queryphp/database/seeds
using environment testing
using adapter mysql
using database queryphp_development_test


== 20181109060739 App: migrating
== 20181109060739 App: migrated 0.0155s


== 20181112023649 Role: migrating
== 20181112023649 Role: migrated 0.0160s


== 20181112024140 User: migrating
== 20181112024140 User: migrated 0.0166s


== 20181112024211 Permission: migrating
== 20181112024211 Permission: migrated 0.0225s


== 20181112024241 UserRole: migrating
== 20181112024241 UserRole: migrated 0.0155s


== 20181112024302 RolePermission: migrating
== 20181112024302 RolePermission: migrated 0.0206s


== 20181112024416 Resource: migrating
== 20181112024416 Resource: migrated 0.0328s


== 20181112024450 PermissionResource: migrating
== 20181112024450 PermissionResource: migrated 0.0305s


== 20181203130724 Option: migrating
== 20181203130724 Option: migrated 0.0170s


== 20181203144731 Test: migrating
== 20181203144731 Test: migrated 0.0133s


All Done. Took 0.2273s

运行测试用例

php ./build/phpunit

结果

注意随着系统演进,测试用例会增加,输出结果就有所不同。
PHPUnit Pretty Result Printer 0.26.2 by Codedungeon and contributors.
PHPUnit 8.1.3 by Sebastian Bergmann and contributors.


==> TestsAdminServiceResourceIndexTest       ✓  ✓
==> TestsExampleExampleTest                    ✓
==> TestsExamplePHPUnitTest                    ✓
==> CommonDomainServiceSearchIndexTest       ✓  ✓  ✓  ✓  ✓  ✓
==> CommonInfraHelperArrayToFormTest          ✓  ✓  ✓  ✓  ✓  ✓
==> CommonInfraSupportWorkflowServiceTest     ✓  ✓  ✓  ✓  ✓
==> CommonInfraSupportWorkflowTest            ✓  ✓  ✓  ✓  ✓

Time: 391 ms, Memory: 18.00 MB

OK (26 tests, 43 assertions)
统一团队代码风格

风格统一对保证我们系统一致性非常重要,我们做到开箱即用,支持 PHPJavaScript

使用 Git 钩子

cp ./build/pre-commit.sh ./.git/hooks/pre-commit
chmod 777 ./.git/hooks/pre-commit

测试自动化格式

common/Test.php


frontend/src/hello.js

function hello(a,b) {
    var c
        if(a>b) {
            c=a
        } else {
            c=b
        }
    console.log(c)
}

Git 提交测试格式化

git add .
git commit -m "测试格式化"

运行过程

Checking PHP Lint...
No syntax errors detected in common/Test.php
Running Code Sniffer...
Loaded config default from ".php_cs.dist".
Paths from configuration file have been overridden by paths provided as command arguments.
1) common/Test.php Fixed all files in 0.009 seconds, 12.000 MB memory used
The file has been automatically formatted.
[13:04:00] Working directory changed to /data/codes/test/queryphp/frontend
[13:04:00] Using gulpfile /data/codes/test/queryphp/frontend/gulpfile.js
[13:04:00] Starting "iview"...
[13:04:00] Finished "iview" after 413 μs
frontend/src/hello.js 53ms
[master 681d7e29] 测试格式化
3 files changed, 32 insertions(+)
mode change 100644 => 100755 build/composer
create mode 100644 common/Test.php
create mode 100644 frontend/src/hello.js
格式化后的 PHP

代码干净漂亮了不少,不是吗。


格式化后的 JavaScript

代码干净漂亮了不少,不是吗。

function hello(a, b) {
    var c
    if (a > b) {
        c = a
    } else {
        c = b
    }
    console.log(c)
}
回滚测试提交

这些测试代码不需要提交到 Git 库,你可以回滚掉刚才测试的这些代码。

git log
git reset --hard 931f283b0b8847e4a3f2ad86efb3c07cd7974c3b // 或者 git revert xxx
HEAD is now at 931f283b Merge branch "dev"
克隆 framework 仓库将框架替换为开发版本

应用层框架全部搭建完毕,接下来我们将框架层代码替换为开发阶段的代码来进行日常框架迭代。

删除框架层

rm -rf ./vendor/hunzhiwange/framework

克隆框架层开发库

$cd /data/codes/test
$git clone git@github.com:hunzhiwange/framework.git ./vendor/hunzhiwange/framework
cd ./vendor/hunzhiwange/framework

Composer 安装

composer install
如果你电脑没有安装 composer,那么已经为你下载一个版本。
sudo chmod 777 ./build/composer
./build/composer install

安装过程

Cloning into "./vendor/hunzhiwange/framework"...
remote: Enumerating objects: 382, done.
remote: Counting objects: 100% (382/382), done.
remote: Compressing objects: 100% (218/218), done.
remote: Total 39304 (delta 196), reused 262 (delta 125), pack-reused 38922
Receiving objects: 100% (39304/39304), 14.49 MiB | 12.00 KiB/s, done.
Resolving deltas: 100% (27594/27594), done.

测试是否安装成功

从新访问首页,如果可以访问,那么恭喜你第一阶段即安装完毕。

php leevel server 
运行框架核心测试用例

QueryPHP 底层框架拥有 3000 多例测试用例,这些测试用例需要被维护,所以这里需要本地开发跑通测试用例。首先创建一个数据库

可以用 Navicat For Mysql 创建一个数据库 test.

CREATE DATABASE IF NOT EXISTS test DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

复制一份配置文件并修改

cp ./tests/config.php ./tests/config.local.php

修改为

 "127.0.0.1",
    "PORT"     => 3306,
    "NAME"     => "test",
    "USER"     => "root",
    "PASSWORD" => "123456",
];


$GLOBALS["LEEVEL_ENV"]["CACHE"]["REDIS"] = [
    "HOST"     => "127.0.0.1",
    "PORT"     => 6380,
    "PASSWORD" => "123456",
];


$GLOBALS["LEEVEL_ENV"]["SESSION"]["REDIS"] = [
    "HOST"     => "127.0.0.1",
    "PORT"     => 6380,
    "PASSWORD" => "123456",
];

执行数据库迁移命令

php vendor/bin/phinx migrate

安装过程

Phinx by CakePHP - https://phinx.org. 0.9.2


using config file ./phinx.php
using config parser php
using migration paths
 - /data/codes/test/queryphp/vendor/hunzhiwange/framework/tests/assert/database/migrations
using seed paths
 - /data/codes/test/queryphp/vendor/hunzhiwange/framework/tests/assert/database/seeds
warning no environment specified, defaulting to: development
using adapter mysql
using database test


 == 20181010111946 User: migrating
 == 20181010111946 User: migrated 0.0076s


 == 20181011111926 Post: migrating
 == 20181011111926 Post: migrated 0.0101s


 == 20181011111937 Comment: migrating
 == 20181011111937 Comment: migrated 0.0106s


 == 20181011151247 PostContent: migrating
 == 20181011151247 PostContent: migrated 0.0087s


 == 20181011160957 Role: migrating
 == 20181011160957 Role: migrated 0.0078s


 == 20181011161035 UserRole: migrating
 == 20181011161035 UserRole: migrated 0.0100s


 == 20181031094608 CompositeId: migrating
 == 20181031094608 CompositeId: migrated 0.0094s


 == 20181107044153 GuestBook: migrating
 == 20181107044153 GuestBook: migrated 0.0086s


 == 20190424055915 TestUnique: migrating
 == 20190424055915 TestUnique: migrated 0.0133s


All Done. Took 0.1179s

运行测试用例

php ./build/phpunit

结果

注意随着系统演进,测试用例会增加,输出结果就有所不同。
PHPUnit 8.1.3 by Sebastian Bergmann and contributors.


==> TestsAuthHashTest                          ✓  ✓
==> TestsAuthManagerTest                       ✓  ✓  ✓
==> TestsAuthMiddlewareAuthTest               ✓  ✓
==> TestsAuthProviderRegisterTest             ✓
==> TestsAuthSessionTest                       ✓  ✓

...

==> TestsViewCompilerCompilerWhileTest        ✓  ✓
==> TestsViewHtmlTest                          ✓  ✓  ✓  ✓  ✓  ✓  ✓  ✓  ✓
==> TestsViewManagerTest                       ✓
==> TestsViewPhpuiTest                         ✓  ✓  ✓  ✓  ✓  ✓  ✓  ✓
==> TestsViewProviderRegisterTest             ✓

Time: 19.51 seconds, Memory: 93.19 MB

Tests: 2978, Assertions: 10031, Failures: 0, Skipped: 6.
统一框架核心团队代码风格

风格统一对保证我们系统一致性非常重要,我们做到开箱即用,核心库只包含 PHP 文件。

使用 Git 钩子

cp ./build/pre-commit.sh ./.git/hooks/pre-commit
chmod 777 ./.git/hooks/pre-commit

测试自动化格式

tests/Name.php


Git 提交测试格式化

git add .
git commit -m "测试格式化"

运行过程

Checking PHP Lint...
No syntax errors detected in tests/Name.php
Running Code Sniffer...
Loaded config default from ".php_cs.dist".
Paths from configuration file have been overridden by paths provided as command arguments.
1) tests/Name.php Fixed all files in 0.009 seconds, 12.000 MB memory used
The file has been automatically formatted.
[master 20f2f845] 测试格式化
2 files changed, 29 insertions(+)
mode change 100644 => 100755 build/composer
create mode 100644 tests/Name.php
格式化后的 PHP

代码干净漂亮了不少,不是吗。

测试代码回滚请见上面的方法,谢谢。


* (c) 2010-2019 http://queryphp.com All rights reserved.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Test;

class Name
{
    public function demo($a = 1, $b = 4)
    {
        echo 1;
    }
}
克隆 queryphp.com 仓库实现自动化文档搭建

QueryPHP 底层的文档基于单元测试加备注的方式来实现的,通过命名工具全部采用自动化生成 Markdown,这大幅度简化了文档的编写工作,同时保证了文档实时性。

官方文档采用 VuePress 读取 Markdown 来实现的

$cd /data/codes/test
$git clone git@github.com:hunzhiwange/queryphp.com.git

修改文档工具生成 Markdown 的路径

$cd /data/codes/test/queryphp
$vim .env


# 修改路径
FRAMEWORK_DOC_OUTPUTDIR = "/data/codes/test/queryphp.com/docs/docs/"

生成文档

$cd /data/codes/test/queryphp
$php leevel make:docwithin tests

运行过程

Class TestsEncryptionEncryptionTest was generate succeed.
Class TestsEncryptionSafeTest was generate succeed.
Class TestsDatabaseManagerTest was generate succeed.
Class TestsDatabaseDddUnitOfWorkTest was generate succeed.
Class TestsDatabaseDddCreateCreateTest was generate succeed.
Class TestsDatabaseQueryAggregateTest was generate succeed.
Class TestsValidateAssertTest was generate succeed.
Class TestsDiContainerTest was generate succeed.
Class TestsDocsBecomeAQueryphpDeveloperDoc was generate succeed.
Class TestsSupportFnTest was generate succeed.
Class TestsSupportStrTest was generate succeed.
Class TestsSupportArrTest was generate succeed.
Class TestsViewSummaryDoc was generate succeed.
Class TestsViewCompilerCompilerAssignTest was generate succeed.
Class TestsViewCompilerCompilerPhpTest was generate succeed.
Class TestsViewCompilerCompilerBreakTest was generate succeed.
Class TestsViewCompilerCompilerIncludeTest was generate succeed.
Class TestsViewCompilerCompilerTagselfTest was generate succeed.
Class TestsViewCompilerCompilerWhileTest was generate succeed.
Class TestsViewCompilerCompilerCssTest was generate succeed.
Class TestsViewCompilerCompilerForTest was generate succeed.
Class TestsViewCompilerCompilerVarTest was generate succeed.
Class TestsViewCompilerCompilerListTest was generate succeed.
Class TestsDebugDebugTest was generate succeed.
A total of 24 files generate succeed.

修改文档菜单

$vim docs/.vuepress/config.js

运行本地文档网站

访问地址 localhost:8088 即可。

$npm install -g yarn
$yarn add -D vuepress # or npm install -D vuepress
$yarn run dev # or npx vuepress dev docs
结尾

到这里为止,我们本地开发环境已经全部搭建完毕,可以愉快地开发了。

::: tip
值得注意的是,我们通常在 dev 分支开发,开发完毕后 mergemaster 分支完成开发。
:::

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/31630.html

相关文章

  • QueryPHP V1-beta.3 完成 1.0.0 计划功能冻结

    摘要:版本完成正式版前的除之外计划功能,启动冻结。百分之百单元测试覆盖直面一剑封喉,基于实现框架常驻,依托生态实现业务常驻,此刻未来逐步渐进。 QueryPHP v1.0.0-beta. 版本完成 1.0 正式版前的除 Swoole 之外计划功能,启动冻结。下一版本专注 Swoole 协程改进。 关于 QueryPHP QueryPHP 是一款现代化的渐进式高性能 PHP 7 不仅仅是常驻框...

    ghnor 评论0 收藏0
  • QueryPHP V1-beta.1 部分文档代码解耦,版本PHP 7.3.2

    摘要:百分之百单元测试覆盖直面一剑封喉,基于实现框架常驻,依托生态实现业务常驻,此刻未来逐步渐进。国际化例子函数随机数字优化最开始采用的的继承一个基础的,方便单元测试有一定性能损失。 经过 1 个月的开发,QueryPHP v1.0.0-beta.1 版本可以发布了,这也是 beta 3 个版本的开始部分。这个版本的主要是代码解耦和性能提升,文档开发。 关于 QueryPHP QueryPH...

    lentrue 评论0 收藏0
  • 未来十年的云计算发展有什么期望?

    摘要:但有一件事将保持在所有名单的首位云计算。过去几年,云计算提供商一直在努力扩大其地理覆盖范围。这最终会代表人们承诺的无缝混合世界吗可以推测,今年云计算将发生很多变化,但关键原则和功能不会。这是新十年的开始,有新的预算和新的商业战略。但有一件事将保持在所有CIO名单的首位:云计算。 去年,Gartner衡量了企业架构的成功,并规划了其2020年的统治地位。它预测,今年市场将再增长17%,达...

    tuantuan 评论0 收藏0
  • 卷积神经网络架构详解:它与神经网络有不同?

    摘要:较大池化一个卷积神经网络的典型架构卷积神经网络的典型架构我们已经讨论过卷积层用表示和池化层用表示只是一个被应用的非线性特征,类似于神经网络。 这是作者在 Medium 上介绍神经网络系列文章中的一篇,他在这里详细介绍了卷积神经网络。卷积神经网络在图像识别、视频识别、推荐系统以及自然语言处理中都有很广的应用。如果想浏览该系列文章,可点击阅读原文查看原文网址。跟神经网络一样,卷积神经网络由神经元...

    HackerShell 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<