草庐IT

unit-testing

全部标签

php - 在 Laravel PHPUnit 中测试未经授权的用户限制

Laravel版本5.2在我的项目中,role_id=4的用户具有admin角色,可以管理用户。我在AuthServiceProvider中定义了以下能力:publicfunctionboot(GateContract$gate){$this->registerPolicies($gate);$gate->define('can-manage-users',function($user){return$user->role_id==4;});}我已经在UserController__construct方法中使用了这种能力,如下所示:publicfunction__construct()

php - 交响乐 : Testing email sending in command

早上好。我想在我的Symfony命令中测试发送电子邮件。我的电子邮件是通过\Swift_Mailer发送的$this->mailer->send($message);我尝试使用这个:http://symfony.com/doc/current/cookbook/email/testing.html但是$this->client->getProfile()和SymfonyResponse在Symfony命令中不可用。Argument1passedtoSymfony\Component\HttpKernel\Profiler\Profiler::loadProfileFromRespons

php - 如何在 laravel 测试中获取 header 值

这就是我在测试用例中得到响应的方式$response=$this->call('POST','/api/auth/login',['username'=>'xx','password'=>'xxx'],[/*cookies*/],[/*files*/],['HTTP_ClientSecret'=>'xxxx']);然后我们可以这样获取响应内容$response->getContents()我想知道如何获取响应头数据? 最佳答案 做类似的事情:$response->headers->get('content-type');或者任何你需

php - 为什么 laravel 5.4 没有 see() 方法

laravel5.4是否移除了see()方法?它在phpunit测试中用于View。它之前可以在laravel5.2中使用,但现在命令提示符显示。calltoundefinedmethod 最佳答案 Laravel5.4使用LaravelDusk执行浏览器测试。您正在寻找的新方法是assertSee(). 关于php-为什么laravel5.4没有see()方法,我们在StackOverflow上找到一个类似的问题: https://stackoverflow

php - 为什么 $$var ['namedIndex' ] = 'test' 不起作用?

在PHP中你可以$var='title';$$var='mynewtitle';而且效果很好。但是当您尝试将它与数组一起使用时,它不起作用并且没有报告任何错误。$var='title';$$var['en']='myenglishtitle';$var='description';$$var['en']='myenglishdescription';感谢帮助[编辑]如果我这样做$$var=array();array_push($$var,'test');它工作并输出title[0]='test';但我真的需要命名索引:/ 最佳答案

php - in_array 组合值 ('test' ,'value' )

我正在尝试将in_array或类似的东西用于关联数组或更复杂的数组。这是普通的in_arrayin_array('test',array('test','exists'));//truein_array('test',array('not','exists'));//false我要搜索的是对,例如“test”和“value”的组合。我可以根据需要将要搜索的组合设置为array('test','value')或'test'=>'value'。但是,如果要搜索的数组是,我该如何进行搜索?array('test'=>'value','exists'=>'here');orarray(arra

php - 网比 : phpUNit or SimpleTest?

哪个更适合Netbeans:PHPUnit还是SimpleTest? 最佳答案 对于我对PHPUnit与SimpleTest的一般看法,请参阅以下问题:Whatunittestinginphptostart.总结一下这篇文章:PHPUnit是PHP单元测试的事实标准Simpletest已经过时并且(恕我直言)已经失去了它的用处。对于Netbeans:NetbeansasgreatPHPUnitSupport而且我从未见过或听说过类似SimpleTest的东西。我什至不确定它是否可以运行用SimpleTest编写的测试。(至少我找不到

php - 使用抽象参数实例化对象

interfaceaInterface{publicfunction__construct(aClass_Abstract$a,bClass_Abstract$b){}}classSampleimplementsaInterface{publicfunction__construct(aClass_Abstract$a,bClass_Abstract$b){//implementation$this->init();}publicfunctioninit(){//implementation}}如何在使用PHPUnit进行测试时设置它?...实现...测试...functionsetU

php - 在抽象类中测试私有(private)方法会扩展另一个方法

我正在尝试测试抽象类中的私有(private)方法。我有三个抽象类:abstractclassAbstractClass1extendsAbstractClass2{privatefunction_privateFunction(){//method'sbody}}abstractclassAbstractClass2extendsAbstractClass3{publicfunction__construct($param){parent::__construct($param)}}abstractclassAbstractClass3{publicfunction__constru

PHPUnit:如何模拟私有(private)方法?

这个问题在这里已经有了答案:MockprivatemethodwithPHPUnit(11个答案)关闭7年前。我有这样一个类:classA{privatefunctiontesting($x){//dosomething$this->privateMethod();}privatefunctionprivateMethod($number){//dosomething}}为了调用testing()我使用这个:$reflection=new\ReflectionClass('A');$method=$reflection->getMethod('testing');$method->se