应该如何用phpunit php web应用程序测试xss + sql注入?我想找到输出xss +其他攻击的程序来测试我的应用程序表单.应该使用新的xss和其他新攻击随时更新此程序/服务.是否存在此类服务/程序,如果不是今天如何完成?如果可以,请举一些例子.
(我使用php 5.3 + zend framework + mysql)
编辑:
我询问测试!而不是阻止我也知道的技术.
谢谢,
优素福
我想知道如何验证"类"是否具有函数.assertClassHasAttribute不起作用,这是正常的,因为Function不是Attribute.
我正在使用PHPUnit进行单元测试我使用模拟对象来测试是否使用正确的参数调用方法.当我只想这样做一次时,这很好用.
$logMock = $this->getMockBuilder('Logger')
->disableOriginalConstructor()
->getMock();
//check if it updates the correct record
$logMock->expects($this->exactly(1))
->method('updateLog')
->with(456, 'some status');
Run Code Online (Sandbox Code Playgroud)
现在,我想测试是否第二次调用updateLog(使用不同的参数).我不知道如何用'with'方法做到这一点.
有人有建议吗?
我使用openid(例如使用google,myopenid,yahoo)在ZF中登录我的网站.它运作良好.但我不知道如何为它编写单元测试.
例如,我想编写单元测试:
public function testUserLogsSuccessfullyUsingGoogle() {
// don't know how to dispach/mock that my action
// will take a user to google, and google will
// return authentication data (e.g. email)
// Once user is authenticated by google,
// I make Zend_Auth for the user.
//
$this->asertTrue(Zend_Auth::getInstance()->getIdentity());
}
public function testUserLogsUnSuccessfullyUsingGoogle() {
// don't know how to dispach/mock that my action
// will take a user to google, and USER WILL NOT ALLOW
// for authentication. Then off course I …Run Code Online (Sandbox Code Playgroud) 我最近继承了一个编程良好的PHP应用程序(sarcasm)的开发和维护.该应用程序基于商业软件(我不会命名),并且有一层基于它的定制(我们的).
不幸的是,这个应用程序使用了大量的全局和单例(双关语).我已经为我们覆盖的所有事情构建了测试用例.然而,很多事情都依赖于一些全球状态,这可能会导致竞争条件和各种奇怪的东西.
为了捕获大部分这些奇怪的东西(我喜欢称之为),我已经构建了一个PHPUnit TestDecorator,[如手册中所述] [1].这个:
class PHPUnit_Extensions_Randomizer extends PHPUnit_Extensions_TestDecorator
{
public function __construct(PHPUnit_Framework_Test $test)
{
$tests = $test->tests();
$shuffle = array();
foreach ($tests as $t) {
if ($t instanceof PHPUnit_Framework_TestSuite) {
$shuffle = array_merge($shuffle, $t->tests());
} else {
$shuffle[] = $t;
}
}
shuffle($shuffle);
$suite = new PHPUnit_Framework_TestSuite();
foreach ($shuffle as $t) $suite->addTest($t);
parent::__construct($suite);
}
}
Run Code Online (Sandbox Code Playgroud)
它基本上随机化测试顺序,以确保测试不依赖于可能正确或可能不正确的全局状态.
当来测试我的自定义装饰器时出现了问题.我没有在手册,谷歌或Stack Overflow中的任何地方找到如何加载它.
在分析代码时,我看到PHPUnit本身正在实例化方法中的RepeatedTest装饰器TextUI_TestRunner::doRun().我知道我可以子类化TestRunner,覆盖doRun(),安排我的装饰器被创建然后只需调用parent::doRun()我的装饰器实例作为参数,覆盖TextUI_Command并创建一个新的CLI脚本来使用我的东西而不是内置的东西. …
我开始编写Doctrine 2 Mongo ODM单元测试,但发现我的代码中没有一个好的策略来做到这一点.我想运行测试并实际持久保存对象,但我想让我的测试数据在tearDown中轻松删除.必须从我在注释中看到的内容中指定集合和数据库名称,并且不能覆盖它,因此我不能仅创建测试数据库并在以后擦除它.
有没有人有他们认为最佳测试方法的最佳实践或示例?
我在Symony2中创建了一个非常简单的REST控制器,其中包含控制器操作中的数据库插入/更新/删除.
是否有一种很好的方法可以为这些控制器操作编写单元/集成测试而不会污染生产数据库?我是否必须使用不同的环境 - 或者是否有来自框架供应商的建议方法?
电流控制器示例:
public function postAction()
{
$json = $this->getRequest()->getContent();
$params = json_decode($json);
$name = $params->name;
$description = $params->description;
$sandbox = new Sandbox();
$sandbox->setName($name);
$sandbox->setDescription($description);
$em = $this->getDoctrine()->getManager();
$em->persist($sandbox);
$em->flush();
$response = new Response('/sandbox/'.$sandbox->getId());
$response->setStatusCode(201);
return $response;
}
Run Code Online (Sandbox Code Playgroud)
目前的测试示例:
class SandboxControllerTest extends WebTestCase
{
public function testRest()
{
$client = static::createClient();
$crawler = $client->request('POST', '/service/sandbox', array(), array(), array(), json_encode(array('name' => 'TestMe', 'description' => 'TestDesc')));
$this->assertEquals(
201, $client->getResponse()->getStatusCode()
);
}
}
Run Code Online (Sandbox Code Playgroud) Zend的优秀人员以及一些博主推荐ZF2的新服务定位器/管理器,而不是内置的依赖注入系统.
我的问题是,将模拟对象注入服务是否可行/方便?我在模块的PHPUnit引导程序中看到了一些略显笨拙的尝试.但有没有一种方法可以使用这种服务系统,比如ZF1 + Yadif干净方便?
phpunit dependency-injection service-locator zend-framework2
我的任务是调查持续集成,我正在研究的一件事是Gitlab CI.
我已经设置了Gitlab,Gitlab CI和两个跑步者,但我绝对坚持如何真正使用它.我怎么能做一些事情,比如创建一个单元测试,将其推送到repo,并让其中一个跑步者测试它?
或者我完全忽略了这一点?我是这个CI的新手(因为我昨天被要求这样做,这是我第一次接触CI)所以如果我错过了这一点,请告诉我并指出我一些资源.
非常感谢.
我刚刚开始使用 Laravel 8 测试套件,并选择为我的帐户创建过程创建功能测试。我已经运行php artisan make:test AccountCreation并编写了第一个测试用例作为函数,但是,当我运行时php artisan test它没有选择我的功能测试,为什么?
同样,如果我尝试删除默认示例测试,我会收到一条错误消息,告诉我找不到该测试?我缺少什么?
测试/功能/AccountCreation.php
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class AccountCreation extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
public function test_creates_user_account_successfully()
{
$response = $this->post('/api/account/create');
$response->assertStatus(201);
}
}
Run Code Online (Sandbox Code Playgroud)
我需要为 Laravel 运行一个特殊的命令来进行这些测试吗?