有没有办法为不同的输入参数定义不同的模拟期望?例如,我有一个名为DB的数据库层类.此类具有名为"Query(string $ query)"的方法,该方法在输入时采用SQL查询字符串.我可以为此类(DB)创建模拟,并为依赖于输入查询字符串的不同Query方法调用设置不同的返回值吗?
我想就php/mysql连接的长期问题向你提供帮助.
每次执行"SHOW PROCESSLIST"命令时,它都会向我显示从我们的5个Web服务器出现的大约400个空闲(状态:睡眠)连接到数据库服务器.
从来没有出现太多问题(我没有找到快速的解决方案),直到最近流量数量增加,从那时起MySQL反复报告"到多个连接"的问题,即使这样的350多个连接处于"睡眠"状态.即使存在与同一服务器的睡眠连接,服务器也无法获得MySQL连接.
重新启动Apache服务器时,所有这些连接都会消失.
用于创建数据库连接的PHP代码使用普通的"mysql"模块,"mysqli"模块,PEAR :: DB和Zend Framework Db适配器.(不同的项目).没有项目使用持久连接.
提高连接限制是可能的,但似乎不是一个好的解决方案,因为它现在是450,并且一直只有20-100个"真实"连接.
我的问题:
为什么在睡眠状态下有这么多连接,我该如何预防呢?
- 更新:
一次运行的Apache请求数永远不会超过50个并发请求,所以我猜关闭连接有问题,或者apache保持端口打开而没有连接phpscript或者什么(?)
my.cnf万一有用:
innodb_buffer_pool_size = 1024M
max_allowed_packet = 5M
net_buffer_length = 8K
read_buffer_size = 2M
read_rnd_buffer_size = 8M
query_cache_size = 512M
myisam_sort_buffer_size = 128M
max_connections = 450
thread_cache = 50
key_buffer_size = 1280M
join_buffer_size = 16M
table_cache = 2048
sort_buffer_size = 64M
tmp_table_size = 512M
max_heap_table_size = 512M
thread_concurrency = 8
log-slow-queries = /daten/mysql-log/slow-log
long_query_time = 1
log_queries_not_using_indexes
innodb_additional_mem_pool_size = 64M
innodb_log_file_size = 64M
innodb_log_buffer_size = …
Run Code Online (Sandbox Code Playgroud) 我们目前正在为您的C++开发构建QA堆栈.
我们已经运行了多个Jenkins实例,并且结合其他语言(如java和php)为CI服务器提供了非常好的体验.
我要求的是指向可用于与Jenkins进行C++开发的工具链的指针.
更具体(大括号中的java/php示例):
虽然我对我的问题得到了可接受的答案,但我被要求提供更多工具/选项/理由来使用Jenkins来完成这个项目.
在过去,我在这方面的商业工具方面做得不够理想.(什么?你想要保存!那些报告?然后你需要购买额外的10k Bucks/Year插件,可以为你生成花哨的GRAPHS!)我可能在这里错了所以请告诉我,不管我是谁.
但主要是我正在寻找一套完整的工具来与Jenkins一起用于C++开发和QA
当我试图在phpunit中运行testclass时,我收到此错误.
C:\xampp\htdocs\unittest>phpunit UnitTest usertest.php
PHP Warning: require_once(File/Iterator/Autoload.php): failed to open stream No such file or directory in C:\xampp\php\pear\PHPUnit\Autoload.php on line 45
PHP Stack trace:
PHP 1. {main}() C:\xampp\php\phpunit:0
PHP 2. require() C:\xampp\php\phpunit:41
Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in C:\xampp\php\pear\PHPUnit\Autoload.php on line 45
Call Stack:
0.0004 325352 1. {main}() C:\xampp\php\phpunit:0
0.0026 366520 2. require('C:\xampp\php\pear\PHPUnit\Autoload.php')xampp\php\phpunit:41
PHP Fatal error: require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.;C:\php\pear') in C:\xampp\php\pear\PHPUnit\Autoload.php on line 45
PHP Stack trace:
PHP 1. {main}() C:\xampp\php\phpunit:0' …
Run Code Online (Sandbox Code Playgroud) 我将列命名postDate
为timestamp.当我直接打印它:
echo $result['postDate'];
Run Code Online (Sandbox Code Playgroud)
2011-03-16 16:48:24
另一方面,当我通过日期函数打印时,我确实得到了存储的内容(例如):
echo date('F/j/Y',$result['postDate'])
Run Code Online (Sandbox Code Playgroud)
我明白了 December/31/1969
我究竟做错了什么?
非常感谢
我一直在努力让PHPunit为我的zend框架项目工作,并遇到了各种各样的问题.我重新安装了PEAR并卸载了PHPunit,并重新安装了它们.
我目前的错误是
demian @ dimbo-TP:〜$ phpunit PHP警告:require_once(PHPUnit/Framework/MockObject/Autoload.php):无法打开流:/usr/share/php/PHPUnit/Autoload.php上没有这样的文件或目录48 PHP致命错误:require_once():无法打开所需的'PHPUnit/Framework/MockObject/Autoload.php'(include_path ='.:/ usr/share/php /:/ usr/local/share/php/library')in第48行的/usr/share/php/PHPUnit/Autoload.php
我使用的是ubuntu 11.10,PHP 5.3.6-13ubuntu3.2
如果有人能给我一些指示,我将非常感激.我在谷歌上看了很多,但似乎没有什么能解决我的问题.
谢谢,
德棉.
这是我的shell转储,它显示了我最近所做的事情:
demian@dimbo-TP:~$ phpunit
The program 'phpunit' is currently not installed. You can install it by typing:
sudo apt-get install phpunit
demian@dimbo-TP:~$ sudo pear channel-discover pear.phpunit.de
[sudo] password for demian:
Channel "pear.phpunit.de" is already initialized
demian@dimbo-TP:~$ sudo pear channel-discover pear.symfony-project.com
Channel "pear.symfony-project.com" is already initialized
demian@dimbo-TP:~$ sudo pear channel-discover components.ez.no
Channel "components.ez.no" is already initialized
demian@dimbo-TP:~$ sudo pear update-channels
Updating channel "components.ez.no"
Channel …
Run Code Online (Sandbox Code Playgroud) 如何在PHPUnit中存根一个由test的构造函数中的类调用的方法?例如,下面的简单代码将无法工作,因为在我声明存根方法时,已经创建了存根对象,并且我的方法被调用,取消存储.
要测试的类:
class ClassA {
private $dog;
private $formatted;
public function __construct($param1) {
$this->dog = $param1;
$this->getResultFromRemoteServer();
}
// Would normally be private, made public for stubbing
public getResultFromRemoteServer() {
$this->formatted = file_get_contents('http://whatever.com/index.php?'.$this->dog);
}
public getFormatted() {
return ("The dog is a ".$this->formatted);
}
}
Run Code Online (Sandbox Code Playgroud)
测试代码:
class ClassATest extends PHPUnit_Framework_TestCase {
public function testPoodle() {
$stub = $this->getMockBuilder('ClassA')
->setMethods(array('getResultFromRemoteServer'))
->setConstructorArgs(array('dog52'))
->getMock();
$stub->expects($this->any())
->method('getResultFromRemoteServer')
->will($this->returnValue('Poodle'));
$expected = 'This dog is a Poodle';
$actual = $stub->getFormatted();
$this->assertEquals($expected, $actual);
}
}
Run Code Online (Sandbox Code Playgroud) 我们最近讨论过是否有可能构建一个trait Singleton
PHP Traits,我们在其中使用了一个可能的实现但遇到了构建问题的问题.
这是一项学术活动.我知道这一点Singletons have very little - if not to say no - use in PHP
,one should 'just create one'
但仅仅是为了探索特征的可能性:
<?php
trait Singleton
{
protected static $instance;
final public static function getInstance()
{
return isset(static::$instance)
? static::$instance
: static::$instance = new static;
}
final private function __construct() {
static::init();
}
protected function init() {}
final private function __wakeup() {}
final private function __clone() {}
}
class A {
use Singleton;
public …
Run Code Online (Sandbox Code Playgroud) 我想轻松地使用php单元从我的多个测试用例类中执行一些选定的测试用例.
由于我的1-2个测试用例在一堆测试用例中失败,并且发现这两个测试用例再次难以执行整个测试套件,是否有任何方法无需向其他人添加注释或在不同的套件中复制这两种方法.
感谢所有提前
我正在为SOA系统编写功能测试,因此需要从前端测试后端子系统.
这是一个标准的CRUD系统.我有一个测试,测试我可以创建一个对象,它返回我的新对象的ID.在后续的测试中,我想编辑然后删除这个对象,但phpunit似乎每次都重新实例化测试类,所以我丢失了我的实例变量.
我怎样才能做到这一点?在架构中的每个服务器上运行功能测试不是一种选择.
php ×9
phpunit ×6
mysql ×2
unit-testing ×2
c++ ×1
jenkins ×1
mocking ×1
qa ×1
selenium-rc ×1
traits ×1