calinpristavu / future-proofing
Requires
- rector/rector: 0.15.*
Suggests
- phpunit/phpunit: The Future project requires a test suite in order to validate your app's functionality
README
!!!本仓库已迁移至 github.com/evozon/future
Future 是一个库,它简化了 PHP 项目的升级过程。
LOGO 这里
设置
先决条件
- Github 或 Gitlab CI
- composer
Gitlab
该项目旨在集成到 Gitlab CI 管道中。
步骤
composer require --dev calinpristavu/future-proofing
cp vendor/calinpristavu/future-proofing/future-proofing.yaml .
- 打开
.future-proofing.yml
并将future-config:
部分修改为您的需求 - 将 CI 文件和阶段插入到您的项目 CI 文件中。示例
# .gitlab-ci.yml include: '/future-proofing.yaml' stages: ... - future-proofing
- 运行管道并检查
future-proofing
作业的输出
Github
即将推出(tm)
它做什么
管道作业将
- 升级 Docker 容器中项目的 PHP 版本。请参阅 #升级 PHP(链接在这里)
- 升级 composer 依赖项到最新版本
- 对代码库运行 rectors。请参阅 #Rector(链接在这里)
- 运行测试
它不做什么
- 如果应用程序没有测试,则没有任何用途
- 为您编写测试:(微笑)
- 将更改提交到代码库
输出示例
一切准备就绪,可以进行升级
(管道输出在这里)
在升级之前应解决的问题
(管道输出在这里)
升级 PHP
Future 在管道中运行,这意味着它需要一个容器来运行。该容器在 .future-proofing.yml
文件中定义。默认镜像为 php:fpm-alpine
。您可以将其更改为任何其他具有您想要升级到的 PHP 版本的容器。容器用于运行测试,因此请确保它具有运行测试所需的所有依赖项。
我们建议使用与生产环境中相同的容器,但将 PHP 版本更改为您想要升级到的版本。这样,您可以确保测试将在与生产环境相同的环境中运行。
使用 php 7.4 但尝试升级到 8.2 的容器示例
# .gitlab-ci.yml ... include: '/future-proofing.yaml' stages: ... - test ... - future-proofing phpunit: stage: test image: php:7.4-cli script: - composer install - vendor/bin/phpunit
# .future-proofing.yml .future-config: #replace this with the base setup of your project #if your project has a Dockerfile, use it and change the "FROM" section to php:fpm-alpine image: php:8.2-cli
这样,future-proofing 作业将使用 PHP8.2 而不是 PHP7.4 运行所有升级和验证步骤。
Rector
感谢 Rector 提供执行繁重工作的工具。Future 使用 Rector 将代码库升级到最新的编码标准。
Rector 规则定义在 .future-proofing.yml
文件中,在 future-proofing 作业中。请根据您的应用程序上下文自由添加/更改/删除 rectors。
Rectors 通过此库提供的二进制文件 future
进行操作。您可以在本地运行它以查看它将对您的代码库做出哪些更改。示例
$ vendor/bin/future add-rule \\Rector\\CodeQuality\\Rector\\Identical\\GetClassToInstanceOfRector
此命令将 GetClassToInstanceOfRector
添加到将在代码库上运行的 rector.php
中 rectors 列表。然而,我们建议您在 .future-proofing.yml
文件中配置 rectors,因为这将专门针对 CI 管道中的 future-proofing 步骤进行配置。
建议
Future 可用于验证您是否可以一次性升级 所有内容
- PHP 版本到最新版本
- composer 依赖项到最新版本
- 代码库到最新标准。
不建议这样做,因为一次性升级所有内容可能导致大量难以审查和测试的变更。
我们建议将升级过程分为阶段。首先进行PHP版本升级,每次升级一个小版本。例如,如果我们使用的是PHP7.4,首先使用Future升级到PHP8.0,然后是8.1,依此类推...
然后开始处理依赖项和编码风格(参见 #Rector(链接在此))。这样,你可以拥有更小、更容易审查和测试的PR。