Laravel Browser Kit Testing 项目教程

Laravel Browser Kit Testing 项目教程

browser-kit-testingProvides backwards compatibility for BrowserKit testing in the latest Laravel release.项目地址:https://gitcode.com/gh_mirrors/br/browser-kit-testing

1. 项目的目录结构及介绍

Laravel Browser Kit Testing 项目的目录结构如下:

/laravel/browser-kit-testing
    ├── src
    │   ├── Concerns
    │   │   └── InteractsWithContainer.php
    │   ├── Contracts
    │   │   └── Factory.php
    │   ├── Testing
    │   │   ├── CreatesApplication.php
    │   │   ├── TestCase.php
    │   │   └── TestResponse.php
    │   ├── BrowserKitTestingServiceProvider.php
    │   └── helpers.php
    ├── tests
    │   ├── Feature
    │   │   └── ExampleTest.php
    │   └── Unit
    │       └── ExampleTest.php
    ├── composer.json
    ├── phpunit.xml
    └── README.md

目录结构介绍

  • src: 包含项目的核心代码。

    • Concerns: 包含一些通用的 trait。
    • Contracts: 包含接口定义。
    • Testing: 包含测试相关的类和方法。
    • BrowserKitTestingServiceProvider.php: 服务提供者,用于注册和引导服务。
    • helpers.php: 包含一些辅助函数。
  • tests: 包含项目的测试代码。

    • Feature: 包含功能测试。
    • Unit: 包含单元测试。
  • composer.json: 项目的依赖管理文件。

  • phpunit.xml: PHPUnit 配置文件。

  • README.md: 项目说明文档。

2. 项目的启动文件介绍

项目的启动文件主要是 src/Testing/CreatesApplication.phpsrc/Testing/TestCase.php

CreatesApplication.php

namespace Laravel\BrowserKitTesting\Testing;

use Illuminate\Contracts\Console\Kernel;

trait CreatesApplication
{
    public function createApplication()
    {
        $app = require __DIR__.'/../../bootstrap/app.php';

        $app->make(Kernel::class)->bootstrap();

        return $app;
    }
}

该文件定义了 createApplication 方法,用于创建和引导 Laravel 应用实例。

TestCase.php

namespace Laravel\BrowserKitTesting\Testing;

use Laravel\BrowserKitTesting\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;
}

该文件定义了 TestCase 类,继承自 BaseTestCase,并使用了 CreatesApplication trait。

3. 项目的配置文件介绍

项目的配置文件主要是 phpunit.xml

phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
         colors="true">
    <testsuites>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./src</directory>
        </whitelist>
    </filter>
</phpunit>

该文件配置了 PHPUnit 的测试套件和过滤器,指定了测试文件的目录和后缀。


以上是 Laravel Browser Kit Testing 项目的教程,包含了项目的目录结构、启动文件和配置文件的介绍。

browser-kit-testingProvides backwards compatibility for BrowserKit testing in the latest Laravel release.项目地址:https://gitcode.com/gh_mirrors/br/browser-kit-testing

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

倪俪珍Phineas

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值