博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php代码质量检测工具_8个必须具备PHP质量保证工具
阅读量:2506 次
发布时间:2019-05-11

本文共 6913 字,大约阅读时间需要 23 分钟。

php代码质量检测工具

This popular post has been updated on June 30th 2017 to include newest technologies and tools.

该热门帖子已于2017年6月30日更新,其中包括最新技术和工具。



For shipping quality code, we must have testing in mind while coding (if not doing TDD). However, with the wide range of PHP testing tools out there, it’s hard to make a choice! Exploring PHP is a fun adventure (premium course on that !) but it’s hard to assemble a toolbelt that’s not too heavy to wear to work!

对于运输质量代码,编码时必须牢记测试(如果不执行TDD)。 但是,有了各种各样PHP测试工具,很难做出选择! 探索PHP是一个有趣的冒险( 是高级课程!),但是要组装一个不太重的工具带很难工作!

This popular article will highlight the most popular testing tools and has been updated to reflect the state of QA tools in 2017.

这篇热门文章将重点介绍最受欢迎的测试工具,并已更新以反映2017年质量检查工具的状态。

Untested code is broken code.

未经测试的代码是损坏的代码。

Lab testing environment illustration

PHPUnit (PHPUnit)

PHPUnit is the go to testing framework for PHP. It was created by in 2004 and current in version 6 that requires PHP 7.

PHPUnit是用于PHP的测试框架。 它由于2004年创建,当前版本为6,需要PHP 7。

We have plenty of tutorials coming up about it.

我们有很多关于它的教程。

Cucumber (Cucumber)

is a framework for creating acceptance tests from specifications. It’s known for it descriptive generated texts that can be read as just plain English. The official PHP implementation for Cucumber is .

是用于根据规范创建验收测试的框架。 它以描述性的生成文本而著称,可以将其理解为纯英语。 Cucumber的官方PHP实现是 。

Behat logo

We have a about it here on SitePoint. The below example taken from the documentation is a good example on how expressive those expectations are.

我们在SitePoint上有关于它的 。 以下文档中的示例是这些期望表达能力的一个很好的例子。

Feature: Listing command  In order to change the structure of the folder I am currently in  As a UNIX user  I need to be able see the currently available files and folders there  Scenario: Listing two files in a directory    Given I am in a directory "test"    And I have a file named "foo"    And I have a file named "bar"    When I run "ls"    Then I should get:      """      bar      foo      """

原子 (Atoum)

Atoum logo

is another unit testing framework for PHP. It’s a standalone package that you can install via GitHub, Composer or via a PHAR executable file.

是另一个用于PHP的单元测试框架。 它是一个独立的软件包,您可以通过GitHub,Composer或PHAR可执行文件进行安装。

Atoum tests are very readable with expressive method names and chaining.

Atoum测试使用表达性方法名称和链接非常可读。

$this->integer($classInstance->myMethod())        ->isEqualTo(10);$this->string($classInstance->myMethod())        ->contains("Something heppened");

You want to learn more about PHP unit testing with Atoum, you can follow this .

您想了解有关使用Atoum进行PHP单元测试的更多信息,可以按照本 。

Selenium (Selenium)

is a tool for automated browser testing (Integration and acceptance testing). It transforms the tests to browser API commands and it asserts the expected results. It supports most of the available browsers out there.

是用于自动浏览器测试(集成和验收测试)的工具。 它将测试转换为浏览器API命令,并声明预期结果。 它支持大多数可用的浏览器。

We can use Selenium with PHPUnit using an extension.

我们可以将Selenium与PHPUnit一起使用扩展。

composer require --dev phpunit/phpunitcomposer require --dev phpunit/phpunit-selenium

Here’s a simple example:

这是一个简单的例子:

class UserSubscriptionTest extends PHPUnit_Extensions_Selenium2TestCase{    public function testFormSubmissionWithUsername()    {        $this->byName('username')->value('name');        $this->byId('subscriptionForm')->submit();    }}

You can follow this series if you want to learn more about .

如果您想了解有关更多信息,可以阅读本系列文章。

黄昏 (Dusk)

Laravel Dusk Logo

from Laravel is another browser automation tool. It can be used standalone (with ) or with Selenium. It has an easy to use API and covers all the testing possibilities like waiting for elements, file upload, mouse control, etc. Here’s a simple example:

Laravel的是另一个浏览器自动化工具。 它可以单独使用(与一起使用)或与Selenium一起使用。 它具有易于使用的API,涵盖了所有测试可能性,例如等待元素,文件上传,鼠标控制等。这是一个简单的示例:

class LanguagesControllerTest extends DuskTestCase{    public function testCreate()    {        $this->browse(function (Browser $browser) {            $user = $this->getAdminUser();            $browser->loginAs($user)                ->visit('/panel/core/languages')                ->click('#add')                ->assertPathIs('/panel/core/languages/create')                ->type('name', 'Arabic')                ->select('direction', 'rtl')                ->press('Submit')                ->assertSee('Language: Arabic')                ->assertSee('ar')                ->assertSee('rtl')                ->assertSee('Language created');        });    }}

You can check to get started on testing with Dusk.

您可以查看以开始使用Dusk进行测试。

卡兰 (Kahlan)

Kahlan logo

is a full-featured Unit & BDD test framework which uses a describe-it syntax.

是功能齐全的Unit&BDD测试框架,它使用describe-it语法。

describe("Positive Expectation", function() {    it("expects that 5 > 4", function() {        expect(5)->toBeGreaterThan(4);    });});

You can see from the syntax above that it’s similar to Behat tests. Kahlan supports stubbing and mocking out of the box with no dependencies, code coverage, reporting, etc.

您可以从上面的语法中看到它类似于Behat测试。 Kahlan支持开箱即用和模拟,无需依赖项,代码覆盖率,报告等。

it("makes a instance double with a parent class", function() {    $double = Double::instance(['extends' => 'Kahlan\Util\Text']);    expect(is_object($double))->toBe(true);    expect(get_parent_class($double))->toBe('Kahlan\Util\Text');});

php_testability (php_testability)

The last package I want mention here is . It’s a static analysis tool that tells you about testability issues in your program and generates a detailed report.

我要在这里提到的最后一个软件包是 。 这是一个静态分析工具,可以告诉您程序中的可测试性问题并生成详细的报告。

The package doesn’t currently have a tagged release that you can rely on, but you can safely use it in development. You can install it via Composer:

该软件包当前没有可依赖的带标记的发行版,但是您可以在开发中安全地使用它。 您可以通过Composer安装它:

composer require edsonmedina/php_testability "dev-master"

Then run it like this:

然后像这样运行它:

vendor/bin/testability . -x vendor

持续集成(CI)服务 (Continuous integration (CI) Services)

An important part in delivering code when working with teams is the ability to automatically check code before it’s merged to the official repo of the project. Most available CI services/tools provide the ability to test code on different platforms and configurations to make sure your code is safe to merge.

与团队合作时交付代码的重要部分是能够在代码合并到项目的正式仓库之前自动检查代码。 大多数可用的CI服务/工具都可以在不同的平台和配置上测试代码,以确保您的代码可以安全合并。

Thumbs up and down in one

There are a lot of services out there which offer good pricing tiers, but you can use open source tools as well:

有很多提供良好定价层的服务,但是您也可以使用开源工具:

  • : (open source) .

    :(开放源代码) 。

  • : (free for open source projects) .

    :(对于开源项目免费) 。

  • : (free for open source projects) .

    :(对于开源项目免费) 。

  • : .

    : 。

结论 (Conclusion)

Adopting the testing culture is hard, but it grows slowly with practice. If you care about your code, you should test it! The above tools and resources will help you get started quickly.

很难采用测试文化,但随着实践的发展,它会慢慢发展。 如果您关心自己的代码,则应该对其进行测试! 以上工具和资源将帮助您快速入门。

What is your experience with the tools mentioned above? Did we miss something? Let us know and we’ll do our best to expand the list with essential tools!

您对上述工具有何经验? 我们错过了什么吗? 让我们知道,我们将尽力使用必要的工具来扩大清单!

翻译自:

php代码质量检测工具

转载地址:http://sxegb.baihongyu.com/

你可能感兴趣的文章
APP版本号记录
查看>>
母函数
查看>>
最长不重复子串
查看>>
POJ 3621
查看>>
PHP ajax实现数组返回
查看>>
java web 自定义filter
查看>>
J.U.C Atomic(二)基本类型原子操作
查看>>
POJ---2945 Find the Clones[字典树-简单题(多例输入注意删除)]
查看>>
[Luogu4550] 收集邮票
查看>>
Python-循环
查看>>
(转)最大子序列和问题 看着貌似不错
查看>>
thinkphp3.2 链接数据库测试
查看>>
项目的上线流程是怎样的?
查看>>
Linux通配符
查看>>
ES6 Iterator
查看>>
Apache2.4开启GZIP功能
查看>>
远程桌面关闭重启电脑的方法
查看>>
第三章 熟悉常用的HDFS操作
查看>>
filter:expression(document.execCommand("BackgroundImageCache",false,true) 转
查看>>
Java - 30 Java 网络编程
查看>>