Php TYPO3\CMS\Core\Tests\UnitTestCase可以';不能加载到extbase单元测试文件中

Php TYPO3\CMS\Core\Tests\UnitTestCase可以';不能加载到extbase单元测试文件中,php,phpunit,typo3,extbase,Php,Phpunit,Typo3,Extbase,我正在用phpunit对extbase扩展进行独立的单元测试 这是我的phpunt.xml,位于typo3conf中/ <?xml version="1.0" encoding="UTF-8"?> <phpunit colors="true"> <testsuites> <testsuite name="Application Test Suite"> <directory>./ext/t

我正在用phpunit对extbase扩展进行独立的单元测试

这是我的phpunt.xml,位于typo3conf中/

<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
    <testsuites>
        <testsuite name="Application Test Suite">
            <directory>./ext/test_extension/Tests/</directory>
        </testsuite>
    </testsuites>
</phpunit>

/分机/测试\扩展/测试/
我的文件夹结构如下所示

DummyControllerTest文件在这里

<?php
namespace Ricky\TestExtension\Tests\Unit\Controller;
/***************************************************************
 *  Copyright notice
 *
 *  (c) 2016 Ricky Mathew <ricky.mk@pitsolutions.com>, Pits
 *              
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

/**
 * Test case for class Ricky\TestExtension\Controller\DummyController.
 *
 * @author Ricky Mathew <ricky.mk@pitsolutions.com>
 */
class DummyControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
{

    /**
     * @var \Ricky\TestExtension\Controller\DummyController
     */
    protected $subject = NULL;

    public function setUp()
    {
        $this->subject = $this->getMock('Ricky\\TestExtension\\Controller\\DummyController', array('redirect', 'forward', 'addFlashMessage'), array(), '', FALSE);
    }

    public function tearDown()
    {
        unset($this->subject);
    }

    /**
     * @test
     */
    public function listActionFetchesAllDummiesFromRepositoryAndAssignsThemToView()
    {

        $allDummies = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage', array(), array(), '', FALSE);

        $dummyRepository = $this->getMock('Ricky\\TestExtension\\Domain\\Repository\\DummyRepository', array('findAll'), array(), '', FALSE);
        $dummyRepository->expects($this->once())->method('findAll')->will($this->returnValue($allDummies));
        $this->inject($this->subject, 'dummyRepository', $dummyRepository);

        $view = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\View\\ViewInterface');
        $view->expects($this->once())->method('assign')->with('dummies', $allDummies);
        $this->inject($this->subject, 'view', $view);

        $this->subject->listAction();
    }

    /**
     * @test
     */
    public function showActionAssignsTheGivenDummyToView()
    {
        $dummy = new \Ricky\TestExtension\Domain\Model\Dummy();

        $view = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\View\\ViewInterface');
        $this->inject($this->subject, 'view', $view);
        $view->expects($this->once())->method('assign')->with('dummy', $dummy);

        $this->subject->showAction($dummy);
    }
}

您需要在PHPUnit中引导自动加载(而不仅仅针对TYPO3)。为此,将属性
bootstrap
添加到配置文件中的
元素中。它是在测试之前执行的文件的路径,应该设置自动加载

在TYPO3上下文中,您可以使用文件
TYPO3/sysext/core/Build/UnitTestsBootstrap.php
,它由TYPO3核心提供

如果您正在运行一个没有键入3的项目,通常需要包含composer生成的自动加载文件,默认情况下,它是文件
vendor/autoload.php

之后,您的配置文件应如下所示:

<phpunit
    colors="true"
    bootstrap="../typo3/sysext/core/Build/UnitTestsBootstrap.php"
>
    <testsuites>
        <testsuite name="Application Test Suite">
            <directory>./ext/test_extension/Tests/</directory>
        </testsuite>
    </testsuites>
</phpunit>

/分机/测试\扩展/测试/

我听了你的话。。然后,我在命令行中收到以下消息:“无法确定进入脚本的路径。请检查您的路径或设置环境变量‘TYPO3_path_WEB’”@JostNo idea为什么会发生这种情况,安装程序在我的TYPO3实例中工作-您在测试中做什么?它们是单元测试,还是做更多的事情?@RickyMathew我也遇到过同样的问题,在启用composer的TYPO3中运行功能测试,定义了
web dir
并加载了
TYPO3控制台
扩展。通过简单地重载
TYPO3\u PATH\u WEB
以指向安装的根目录,而不是在测试执行过程中指向真实的WEB路径(由
WEB dir
定义):
TYPO3\u PATH\u WEB=/home/my\u project./bin/phpunit-c FunctionalTests.xml