sven/laravel-view-assertions

在您的PHPUnit测试中对Laravel视图进行断言

v1.2.0 2023-07-25 14:34 UTC

This package is auto-updated.

Last update: 2024-08-26 16:43:46 UTC


README

Laravel View Assertions

Laravel视图断言

Latest Version on Packagist Total Downloads Software License Build Status StyleCI

为您的Laravel应用程序中的视图缺失的断言。

安装

您需要遵循几个简单的步骤来安装此包。

下载

通过composer

$ composer require sven/laravel-view-assertions --dev

或者将包添加到您的composer.json中的依赖项,并在命令行中运行composer update以下载包

{
    "require-dev": {
        "sven/laravel-view-assertions": "^1.1"
    }
}

使用方法

此包公开了一个特质:`\Sven\LaravelViewAssertions\InteractsWithViews`。当您在测试中使用此特质如下所示时,您将获得几个断言的访问权限

<?php

use Sven\LaravelViewAssertions\InteractsWithViews;
use Illuminate\Foundation\Testing\TestCase;

class ExampleTest extends TestCase
{
    use InteractsWithViews;

    public function test_it_creates_a_view()
    {
        // ...
        
        $this->assertViewExists('some.view-file');
        $this->assertViewsExist(['posts.index', 'posts.show']);
    }

    public function test_it_does_not_create_a_view()
    {
        // ...
        
        $this->assertViewDoesNotExist('some.view-file');
        $this->assertViewsDoNotExist(['posts.edit', 'posts.create']);
    }

    public function test_the_view_equals()
    {
        // ...
        
        $this->assertViewEquals('The Expected Contents', 'index');
    }

    public function test_the_view_does_not_equal()
    {
        // ...
        
        $this->assertViewDoesNotEqual('This Is Not The Content You\'re Looking For', 'index');
    }
}

贡献

所有贡献(拉取请求、问题和功能请求)都欢迎。不过,请首先阅读CONTRIBUTING.md。有关所有贡献者的信息,请参阅贡献者页面

许可

sven/laravel-view-assertions使用MIT许可(MIT)。有关更多信息,请参阅许可文件