/ / TYPO3CMSCoreTestsUnitTestCase nie je možné načítať do testovacích súborov jednotky extbase - php, phpunit, typo3, extbase

TYPO3CMSCoreTestsUnitTestCase nie je možné načítať do testovacích súborov jednotky extbase - php, phpunit, typo3, extbase

Robím samostatné testovanie jednotky s phpunitom na rozšírenie extbase.

tu je môj phpunt.xml umiestnený v 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>

moja štruktúra priečinkov je zobrazená nižšie

tu zadajte popis obrázku

A súbor DummyControllerTest je tu

<?php
namespace RickyTestExtensionTestsUnitController;
/***************************************************************
*  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 RickyTestExtensionControllerDummyController.
*
* @author Ricky Mathew <ricky.mk@pitsolutions.com>
*/
class DummyControllerTest extends TYPO3CMSCoreTestsUnitTestCase
{

/**
* @var RickyTestExtensionControllerDummyController
*/
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 RickyTestExtensionDomainModelDummy();

$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);
}
}

Ale pri spustení phpunitu cez príkazový riadok to vyvolá

Závažná chyba: Trieda "TYPO3CMSCoreTestsUnitTestCase" sa nenašla v /opt/xampp/htdocs/typo3testpro/typo3conf/ext/test_extension/Tests/Unit/Controller/DummyControllerTest.php v riadku 37

Prečo to nie je automatické načítavanie? Snažil som sa vytvoriť inštanciu TYPO3CMSCoreTestsUnitTestCase vnútri mojej kontrolnej triedy len na testovanie a tam sa dokonale automaticky načíta

odpovede:

2 pre odpoveď č. 1

V PHPUnit (nielen pre TYPO3) musíte zaviesť automatické načítanie. Ak to chcete urobiť, pridajte atribút bootstrap pre vás <phpunit> v konfiguračnom súbore. Je to cesta k súboru, ktorý sa spustí pred testami a mal by nastaviť automatické načítanie.

V kontexte TYPO3 môžete tento súbor použiť typo3/sysext/core/Build/UnitTestsBootstrap.php, poskytuje ho jadro TYPO3.

Ak prevádzkujete projekt bez TYPO3, zvyčajne musíte zahrnúť automaticky generovaný súbor, ktorý vytvoril skladateľ, v predvolenom nastavení je to súbor vendor/autoload.php.

Váš konfiguračný súbor by mal potom vyzerať takto:

<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>