在故意抛出异常时,我总是只使用PHP的基本异常类,只是带有不同的消息,例如:
<?php
if($a < $b){
throw new Exception('a is smaller than b');
}elseif($a > $b){
throw new Exception('a is larger than b');
}
然而,最近我注意到,有些人抛出了不同类别的异常,例如:
<?php
if($a < $b){
throw new aIsSmallerThanBException();
}elseif($a &g
我试着用PHPUnit v8。然而,我并没有成功地使用PhpStorm。当我在PhpStorm中运行简单的测试(类方法)时,我得到以下消息: PHP Fatal error: Uncaught PHPUnit\Runner\Exception: Class 'Mrself\\TreeType\\Tests\\Functional\\BuildingTest' could not be found in '/vagrant/symfony-tree-type/tests/Functional/BuildingTest.php'. in /vagrant/sym
我正在对Symfony 3.2应用程序中的phpunit和guzzle进行一些功能测试。
在运行测试之前,我有多个测试需要加载数据库并登录到应用程序。它的设置如下:
<?php
namespace Tests\Legacy\Functional;
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class UsersTest extends KernelTestCase
{
protected fun
我已经在一些测试中尝试过这种方法,其中一个通过,一个不完整,一个失败,但getStatus()对所有这些测试都返回null。
我使用的是PHPUnit版本3.7.10
下面是我的测试监听器代码:
class MyTestListener implements PHPUnit_Framework_TestListener
{
protected $tests = array();
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {}
public function a
我正在尝试让phpunit在phpstorm内工作,我得到了以下错误
Fatal error: Class 'PHPUnit_Framework_TestCase' not found
我使用的是php 7.1.12版和phpunit 7.1.5版。
我一直在寻找解决方案,但找不到任何对我有帮助的东西。
有什么办法解决这个问题吗?
测试配置。
我需要测试我们的错误记录器在各种情况下是如何工作的。其中一个场景是解析错误。下面是一个例子:
public function testParseErrorLogsAnError()
{
$this->assertCount(0, $this->log_handler->getRecords());
try {
eval('<?php not good');
$this->fail('Code above should throw a parse error');
} catc
我正在尝试用PHPUnit建立我的项目。我尝试用我的项目在PHPUnit上配置PhpStorm,下面是本文中解释的步骤。
但是,当我尝试运行测试时,我会不断地得到以下错误。
Warning: require_once(PHPUnit/Runner/Version.php): failed to open stream: No such file or directory in C:\Users\win 8\AppData\Local\Temp\ide-phpunit.php on line 49
Fatal error: require_once(): Failed opening req
安装似乎工作正常(经过大量的工作!)。但是,当在phpStorm中设置断点并执行“运行”时,我收到错误消息
PHP Fatal error: Uncaught Error: Class 'PHPUnit_Framework_TestCase' not found in /home/hs/hellm/vendor/albertofem/rsync-lib/tests/AFM/Rsync/Tests/CommandTest.php:16
Stack trace:
#0 /home/hs/hellm/vendor/phpunit/phpunit/src/Util/FileLoade
我有过
错误:找不到类'app\Main‘
我不知道怎么解决它?
我使用PHPSTORM和phpunit的最新版本。
Main.php
<?php
namespace app;
class Main
{
public function Calc()
{
return 1;
}
}
MainTest.php
<?php
namespace app;
use PHPUnit\Framework\TestCase;
class MainTest extends TestCase
{
public function
我通过谷歌搜索,但找不到答案。PhpStorm有许多内置的代码完成注释,但也有许多缺少注释。我确信有一种方法可以创建新的注释,但是在设置中找不到它。或者可能是某个地方的XML文件。NetBeans对此特性有支持。
换句话说,我如何创建新的phpDoc注释,以便在phpStorm 8中完成,比如@usesDefaultClass for phpUnit。
我正在尝试使用try/catch块为一个自定义WordPress插件添加一些错误处理,该插件通过Twitter API获取Tweet。
出于测试目的,我在类构造方法中抛出了一个异常。
class Twitter_Settings() {
public function __construct() {
throw new \Exception('test');
}
}
然后在我的插件文件中,我这样做:
function twitter_init_settings() {
try {
return new Twitter_S
我在使用Roslyn脚本引擎时遇到了麻烦。当我在委托中运行脚本时,我也不会得到异常处理。
如预期那样工作的测试:
string script = @"var a=0; var b=2/a;";
var runner = CSharpScript.Create<object>(script);
var errors = runner.Compile();
Assert.IsTrue(errors.IsEmpty);
try
{
runner.RunAsync();
Assert.Fail("Where is the exception"
我不明白如何用PHPUnit对异常进行单元测试。
请参见我的方法,但有一个异常:
public function getPhone($html, $tag = 'OFF', $indicative, $number_lenght) {
// .. code
if ($tag <> 'OFF') {
$html = $doc[$tag]->text(); // Apanho apenas o texto dentro da TAG
if (emp