如何在Drupal8环境中为自定义模块运行PHPUnit测试
我正在尝试为Drupal8创建和运行PHPUnit测试。详情如下: 我的顶级目录,composer.json所在的位置如何在Drupal8环境中为自定义模块运行PHPUnit测试,phpunit,drupal-8,Phpunit,Drupal 8,我正在尝试为Drupal8创建和运行PHPUnit测试。详情如下: 我的顶级目录,composer.json所在的位置 Dockerfile bootstrap.php composer.lock phpunit-examples phpunit.xml.org web Jenkinsfile checkstyle.xml config phpuni
Dockerfile bootstrap.php composer.lock phpunit-examples phpunit.xml.org web
Jenkinsfile checkstyle.xml config phpunit.xml scripts
LICENSE components drush phpunit.xml.dist sonar-project.properties
README.md composer.json patches phpunit.xml.dist.org vendor
/供应商/bin/phpunit——版本
PHPUnit 6.5.14由塞巴斯蒂安·伯格曼和贡献者撰写
phpunit.xml.dist
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
verbose="true"
>
<testsuites>
<testsuite name="unit">
<file>./tests/TestSuites/UnitTestSuite.php</file>
</testsuite>
<testsuite name="kernel">
<file>./tests/TestSuites/KernelTestSuite.php</file>
</testsuite>
<testsuite name="functional">
<file>./tests/TestSuites/FunctionalTestSuite.php</file>
</testsuite>
<testsuite name="functional-javascript">
<file>./tests/TestSuites/FunctionalJavascriptTestSuite.php</file>
</testsuite>
</testsuites>
</phpunit>
我尝试将测试移动到web/modules/custom/benefit/tests/src/Unit/BenefitListBuilderTest.php下,但得到了相同的错误。
如何让测试识别UnitTestCase的路径
更新:
我已在PHPStorm中设置了存储库,因此现在我遇到错误:
Error : Class 'Drupal\Tests\BenefitListBuilder' not found
在我看来,@kamal,问题在于您将测试实例化为:使用PHPUnit\Framework\TestCase;但是您使用的是Drupal,所以应该如下所示:使用Drupal\Tests\UnitTestCase 我希望这有帮助
<?php declare(strict_types = 1);
namespace Drupal\Tests\benefit;
use Mockery;
use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;
use Drupal\benefit\BenefitListBuilder;
/**
* Test basic functionality of My Module.
*
* @group benefit
*/
class BenefitListBuilderTest extends UnitTestCase
{
/** @var BenefitListBuilder */
private $benefitListBuilder;
protected function setUp()
{
$a = "var_a";
$b = "var_b";
$this->benefitListBuilder = new BenefitListBuilder($a,$b);
}
public function testMissing()
{
$this->fail('Test not yet implemented');
}
}
$./vendor/bin/phpunit web/modules/custom/benefit/tests/src/BenefitListBuilderTest.php
PHP Fatal error: Class 'Drupal\Tests\benefit\UnitTestCase' not found in /Users/syedahmed/BG-REPOS/PHPUNITTEST-BenefitsAPI/BenefitsAPI/web/modules/custom/benefit/tests/src/BenefitListBuilderTest.php on line 15
Fatal error: Class 'Drupal\Tests\benefit\UnitTestCase' not found in /Users/syedahmed/BG-REPOS/PHPUNITTEST-BenefitsAPI/BenefitsAPI/web/modules/custom/benefit/tests/src/BenefitListBuilderTest.php on line 15
Error : Class 'Drupal\Tests\BenefitListBuilder' not found