noiselabs/zf-test-case-behat-extension

通过暴露Zend\Test类(最初为PHPUnit构建)进行ZF MVC应用的集成测试

0.2.0 2017-09-19 12:15 UTC

This package is auto-updated.

Last update: 2024-09-11 14:58:43 UTC


README

Build Status Scrutinizer Code Quality

通过暴露Zend\Test类(最初为PHPUnit构建)在Behat中对ZF MVC应用进行集成测试。

安装

此扩展需要

  • Behat 3.0+

推荐的安装方法是使用Composer

$ composer require --dev noiselabs/zf-test-case-behat-extension

然后您可以在您的behat.yml中激活此扩展

default:
    # ...
    extensions:
        Noiselabs\Behat\ZfTestCaseExtension\ServiceContainer\ZfTestCaseExtension:
            configuration: </path/to/application.config.php>

用法

实现ZfTestCaseAwareContext或扩展ZfTestCaseContext

<?php

use Album\Controller\AlbumController;
use Noiselabs\Behat\ZfTestCaseExtension\Context\ZfTestCaseAwareContext;
use Noiselabs\Behat\ZfTestCaseExtension\TestCase\HttpControllerTestCase;

class MyContext implements ZfTestCaseAwareContext
{
    /**
     * @var HttpControllerTestCase
     */
    private $testCase;

    public function setTestCase(HttpControllerTestCase $testCase)
    {
        $this->testCase = $testCase;
    }
    
    /**
     * @When /^the album endpoint is called$/
     */
    public function testIndexActionCanBeAccessed()
    {
        // See https://docs.zendframework.com/tutorials/unit-testing/
        $this->testCase->dispatch('/album');
        $this->testCase->assertResponseStatusCode(200);
        $this->testCase->assertModuleName('Album');
        $this->testCase->assertControllerName(AlbumController::class);
        $this->testCase->assertControllerClass('AlbumController');
        $this->testCase->assertMatchedRouteName('album');
    }
}

版权

版权(c)2017 Vítor Brandão。许可协议MIT License