我有以下测试用例:
include_once('../Logger.php');
class LoggerTest extends PHPUnit_Framework_TestCase {
public function providerLogger() {
return new Logger;
}
/**
* @dataProvider providerLogger
*/
public function testAddStream($logger) {
$this->assertTrue(false);
}
}
Run Code Online (Sandbox Code Playgroud)
当我在PHPUnit中运行它时,我得到:
PHPUnit 3.4.14 by Sebastian Bergmann.
..........
Time: 0 seconds, Memory: 5.75Mb
OK (1 tests, 0 assertions)
Run Code Online (Sandbox Code Playgroud)
测试应该失败,但事实并非如此.我试过:
public function providerLogger() {
return array(new Logger);
}
Run Code Online (Sandbox Code Playgroud)
但我得到:
The data provider specified for LoggerTest::testAddStream is invalid.
Run Code Online (Sandbox Code Playgroud)
我试着宣布它static(就像手册所说的那样),但仍然没有区别.
我记得以前以类似的方式工作,但我可能是错的.我错过了什么?
在此先感谢您的帮助.
PHP 5.3.3上的PHPUnit 3.4.14(取自PEAR)
我试图找出我在这里做错了什么.我正在尝试使用二进制读取器来简化从流中获取初始四个字节到Int32值,该值告诉我其余数据的预期时间.
static void Main(string[] args)
{
MemoryStream stream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(stream);
string s = "Imagine this is a very very long string.";
writer.Write(s.Length);
writer.Write(s);
writer.Flush();
BinaryReader reader = new BinaryReader(stream);
reader.BaseStream.Seek(0, SeekOrigin.Begin);
char[] aChars = new char[reader.ReadInt32()];
reader.Read(aChars, 0, aChars.Length);
Console.WriteLine(new string(aChars));
}
Run Code Online (Sandbox Code Playgroud)
输出应该是输入,但我得到这个(注意第一个字符从字符串更改为字符串)
(想象一下,这是一个非常长的字符串
有人可以向我解释我做错了什么吗?理想情况下,第二次读取将继续,直到总读取字节数等于前四个字节的值.此代码只是一个简化,以显示我遇到的问题.流的位置似乎是正确的(4)但它几乎看起来像是从2开始读取.
function Entity() {
this.a = {a: 4};
this.b = 5;
}
function Thing() {}
Thing.prototype = new Entity;
var thing1 = new Thing;
thing1.a.a = 3;
thing1.b = 4;
var thing2 = new Thing;
console.log(thing2.a.a); // prints 3 instead of 4. I would like 4.
console.log(thing2.b) // prints 5 as wanted
Run Code Online (Sandbox Code Playgroud)
我在javascript中设置原型继承时遇到了困难.理想情况下,我希望thing1和thing2都拥有自己的"新实体原型"的干净副本.
使用this.__proto__是我想避免的
[编辑]
我对这是如何工作有一个大概的了解.
设置thing1.b在Thing实例上设置b属性.它不接触原型链中定义的Entity.b.
在Thing实例上设置thing1.aa的地方无法完成,因为它会抛出"无法设置未定义"错误.那是当它上升到原型链以找到定义的Entity.a并将Entity.aa设置为新值.
[进一步编辑]
正如@IvoWetzel所说设置thing1.b不会触及原型链,因为设置属性不会.设置thing1.aa的地方有两个步骤.在thing1.a上的一个getter,触及原型链,后跟一个.a的setter
抓住我的头.jQuery的标签,我尝试使用ajaxOptions之前,我加载到数据发布到网页.
所以我在网页上的表单我卡口与一些输入字段之前.即
<form id="myform" method="post">
<!-- inputs etc -->
</form>
Run Code Online (Sandbox Code Playgroud)
然后是我的标签
<div id="tabs">
<ul>
<li><a href="#tabs-1">Preloaded</a></li>
<li><a href="ajax/content1.html">Tab 1</a></li>
</ul>
<div id="tabs-1">
<p>Initital content</p>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
好的,所以现在我应该能够序列化我的表单,所以当点击一个标签时它应该是一个帖子请求,即,
$( "#tabs" ).tabs({
ajaxOptions: {
type: 'post',
data: $("#myform").serialize(),
error: function( xhr, status, index, anchor ) {
$( anchor.hash ).html(
"Couldn't load this tab. We'll try to fix this as soon as possible. " +
"If this wouldn't be a demo." );
}
}
});
Run Code Online (Sandbox Code Playgroud)
它确实执行post请求,但表单数据始终为空.
有什么想法吗?
谢谢
背风处
我在构造函数参数列表上使用类型提示,如下所示:
public function __construct(FooRepository $repository)
Run Code Online (Sandbox Code Playgroud)
有没有办法使用PHP Reflection API来获取提示类型?换句话说,我想要一个反射函数,我可以调用它以某种方式返回字符串"FooRepository".我试过通过反射获取构造函数,然后获取参数,如果构造函数,但我没有看到任何会给我提示类型的字符串.
什么是保护站点形式DoS攻击的最佳方法.知道流行的网站/服务如何处理这个问题?
应用程序,操作系统,网络,托管级别中的工具/服务是什么?
如果有人可以分享他们处理的真实经验会很好.
谢谢
嗨,我正在使用Voldemort来存储我的数据.我的关键是一个单词,值是单词和URL的出现次数.例如:
key :question
value: 10, www.stackoverflow.com
Run Code Online (Sandbox Code Playgroud)
我正在使用Json对象来放置我的值.我的代码看起来像这样
import org.json.JSONObject;
import com.metaparadigm.jsonrpc.JSONSerializer;
import voldemort.client.ClientConfig;
import voldemort.client.SocketStoreClientFactory;
import voldemort.client.StoreClient;
import voldemort.client.StoreClientFactory;
public class ClientExample {
public static void main (String [] args) {
String bootstrapUrl = "tcp://localhost:6666";
ClientConfig cc = new ClientConfig ();
cc.setBootstrapUrls (bootstrapUrl);
String[] valuePair = new String[2];
int val = 1;
StoreClientFactory factory = new SocketStoreClientFactory (cc);
StoreClient client = factory.getStoreClient("test");
JSONObject json = new JSONObject();
json.put("occurence",val);
json.put("url", "www.cnn.com");
client.put("foo", json);
}
}
Run Code Online (Sandbox Code Playgroud)
我的store.xml看起来像这样
<stores>
<store>
<name>test</name>
<persistence>bdb</persistence>
<routing>client</routing> …Run Code Online (Sandbox Code Playgroud) 我有一个充当服务器的 Python (2.7) 脚本,因此它将运行很长一段时间。该脚本有一堆值需要跟踪,这些值可以根据客户端输入随时更改。
\n\n我理想的追求是能够在内存中保留 Python 数据结构(基本上具有、 、 和dict\ listxe2 unicode\ x80\x93 JSON 类型的值),让我可以根据需要更新它(除了引用任何多次引用类型实例),同时还在人类可读的文件中保持这些数据是最新的,这样即使拔掉电源插头,服务器也可以启动并继续使用相同的数据。intfloat
我知道我基本上是在谈论数据库,但我保存的数据非常简单,大多数时候可能小于 1 kB,所以我正在寻找可能的最简单的解决方案,可以为我提供所描述的数据的完整性。有没有好的 Python (2.7) 库可以让我做这样的事情?
\n在Ubuntu中运行这个非常短的脚本时接收段错误.
from osgeo import ogr, osr
shpfile = 'Census_County_TIGER00_IN.shp'
def cust_field(field):
'''cust_field(shpfile, field) creates a field definition, which, by calling cust_field(), can be used to create a field using the CreateField() function.
cust_field() DOES NOT create a field -- it simply creates a "model" for a field, that can then be called later. It's weird, but that's GDAL/OGR, as far as I can tell.'''
fieldDefn = ogr.FieldDefn(field, ogr.OFTInteger)
fieldDefn.SetWidth(14)
fieldDefn.SetPrecision(6)
return fieldDefn
ds = ogr.Open(shpfile, 1)
lyr = ds.GetLayerByIndex(0)
field …Run Code Online (Sandbox Code Playgroud) 以下代码可以在所有浏览器中完美运行,禁止IE浏览器.照常.这是需要发生的事情:
正如我所说,到目前为止代码工作得非常好,除了在IE中.任何有新鲜眼睛(和完整的发际线)的人都可以看看这个吗?可以做到与众不同吗?
function getRGB(color) {
// Function used to determine the RGB colour value that was passed as HEX
var result;
// Look for rgb(num,num,num)
if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color)) return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
// Look for rgb(num%,num%,num%)
if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color)) return [parseFloat(result[1]) * 2.55, parseFloat(result[2]) * 2.55, parseFloat(result[3]) * 2.55];
// Look for #a0b1c2
if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color)) return [parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16)];
// Look for #fff
if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color)) return …Run Code Online (Sandbox Code Playgroud) jquery ×2
php ×2
python ×2
binaryreader ×1
c# ×1
colors ×1
database ×1
dataprovider ×1
file ×1
hex ×1
javascript ×1
json ×1
memory ×1
memorystream ×1
osgeo ×1
phpunit ×1
prototype ×1
prototyping ×1
python-2.7 ×1
reflection ×1
rgb ×1
scope ×1
security ×1
this ×1
unit-testing ×1