我有正确验证从返回单篇文章的端点返回的文章的代码.我很确定它正常工作,因为当我故意不在文章中包含必填字段时,它会给出验证错误.
我也有这个代码,它试图验证从返回文章数组的端点返回的文章数组.但是,我很确定它没有正常工作,因为它总是说数据是有效的,即使我故意不在文章中包含必填字段.
如何根据模式正确验证数据数组?
完整的测试代码在下面作为独立的可运行测试.两个测试都应该失败,但只有其中一个测试失败.
<?php
declare(strict_types=1);
error_reporting(E_ALL);
require_once __DIR__ . '/vendor/autoload.php';
// Return the definition of the schema, either as an array
// or a PHP object
function getSchema($asArray = false)
{
$schemaJson = <<< 'JSON'
{
"swagger": "2.0",
"info": {
"termsOfService": "http://swagger.io/terms/",
"version": "1.0.0",
"title": "Example api"
},
"paths": {
"/articles": {
"get": {
"tags": [
"article"
],
"summary": "Find all articles",
"description": "Returns a list of articles",
"operationId": "getArticleById",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": …Run Code Online (Sandbox Code Playgroud) 在优化我的Apache + PHP内存使用时,我遇到了一个奇怪的问题.基本上,当尝试绑定MySQLi查询的结果时,代码会出现错误消息"致命错误:允许的内存大小为16777216字节耗尽(尝试分配50331646字节)".
相关表格是:
CREATE TABLE `note` (
`noteID` int(11) NOT NULL AUTO_INCREMENT,
`contentID` int(11) NOT NULL,
`text` mediumtext NOT NULL,
PRIMARY KEY (`noteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `content` (
`contentID` int(11) NOT NULL AUTO_INCREMENT,
`text` varchar(2048) NOT NULL,
`datestamp` datetime NOT NULL,
PRIMARY KEY (`contentID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Run Code Online (Sandbox Code Playgroud)
而爆炸的查询是:
select content.contentID,
content.text,
content.datestamp,
note.noteID,
note.contentID, note.text
from basereality.content as content
inner join basereality.note as note
on content.contentID = note.contentID
where content.contentID = 1028 ;
Run Code Online (Sandbox Code Playgroud)
在服务器上的MySQL中运行查询运行正常,返回的'note'大小不到千字节.
一个奇怪的是它试图分配50331646的大小是十六进制的0x2FFFFFE,这是一个可疑的圆数.这几乎就像PHP试图分配一个足够大的缓冲区来保存最大的中间文本字段,而不是实际为所检索的数据分配内存. …
我正在使用https://www.npmjs.com/package/pdf-image。
var PDFImage = require("pdf-image").PDFImage;
var pdfImage = new PDFImage("brochure.pdf");
pdfImage.convertPage(0).then(function (imagePath) {
// 0-th page (first page) of the slide.pdf is available as slide-0.png
fs.existsSync("slide-0.png") // => true
},function(err){
console.log(err);
});
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误
{ message: 'Failed to convert page to image',
error:
{ [Error: Command failed: /bin/sh -c convert 'brochure.pdf[0]' 'brochure-0.png'
/bin/sh: 1: convert: not found
]
killed: false,
code: 127,
signal: null,
cmd: '/bin/sh -c convert \'brochure.pdf[0]\' \'brochure-0.png\'' },
stdout: '',
stderr: '/bin/sh: 1: convert: not found\n' …Run Code Online (Sandbox Code Playgroud) 使用Selenium2Driver使用Behat和Mink时,有没有办法可靠地等待页面加载?
我继承了一些等待的遗留测试:
Background:
Given I am on "http://test.example.com"
And I wait for "20000"
Given I click on the element with css selector ".button1"
And I wait for "30000"
Given I click on the element with css selector ".button2"
And I wait for "30000"
Given I click on the element with css selector ".button1"
And I wait for "10000"
Run Code Online (Sandbox Code Playgroud)
即只需要这个单一测试需要1分30秒.
我想要做的是有一种通用的方式来等待前一次点击导致页面加载,而不必每次都等待很长的固定时间.
我可以看到等待页面加载的所有建议,都是指检查是否加载了特定的页面元素.
然而,这些测试针对各种遗留网站运行,其中并不总是存在可以检查存在的标准元素,因此我希望使用更通用的方法.
有人可以告诉我如何让 JustinRainbow Json 模式验证器能够找到引用。
这是我试图验证的 foobar 模式:
{
"title": "foobar schema",
"type": "object",
"properties": {
"pagination": {
"$ref": "#/definitions/pagination"
}
},
"required": ["pagination"]
}
Run Code Online (Sandbox Code Playgroud)
分页模式的定义包含在我计算机上的一个单独文件中。
尝试验证它而不告诉 JSON 验证器如何解析这样的引用:
$uriRetriever = new JsonSchema\Uri\UriRetriever();
$refResolver = new JsonSchema\RefResolver($uriRetriever, $uriResolver);
$schema = $refResolver->resolve("file://".realpath(__DIR__."/foobar.json"));
Run Code Online (Sandbox Code Playgroud)
给出错误信息:
File: file://features/foobar.json is found, but could not resolve fragment: #/definitions/pagination (JsonSchema\Exception\UnresolvableJsonPointerException)
Run Code Online (Sandbox Code Playgroud)
这是公平的,因为验证器无法知道如何找到包含分页模式定义的文件......那么我如何告诉 RefResolver 如何找到分页模式的定义?
我希望能够通过本地文件系统解析文件,而不必在网络服务器上使用 URL。
在Excel上的VBA中,我有数千个单元格的循环,这需要几分钟.
是否可以中止长期循环(如果是,如何)/我可以构建一个按钮或类似的东西来手动中断此循环?
构建一个按钮并用宏覆盖它不是问题,只是代码本身.
在我的Travis文件中,我有几个PHP版本和一个这样的脚本条目:
php:
- 5.6
- 5.5
- 5.4
- 5.3
script:
- export CFLAGS="-Wno-deprecated-declarations -Wdeclaration-after-statement -Werror"
- phpize #and lots of other stuff here.
- make
Run Code Online (Sandbox Code Playgroud)
我想export CFLAGS只在PHP版本匹配5.6时运行该行.
理论上我可以用一个讨厌的黑客从命令行中检测PHP版本,但我怎么能通过Travis配置脚本来做到这一点?
我刚刚将我的第一个库包发布到 NPM,并尝试在应用程序项目中使用它。
它是用 typescript 编写的,项目构建正常,并已发布到 NPM。但随后尝试使用它失败了,因为显然它不是一个有效的模块。
index.ts 文件中设置模块导出(afaik)的代码是:
const initByClass = (widgetBindings: WidgetClassBinding[], h: any, render: any) => {
for (const widgetBinding of widgetBindings) {
setupWidget(widgetBinding, h, render);
}
};
module.exports = {
initByClass
};
Run Code Online (Sandbox Code Playgroud)
库中的 tsconfig.json 文件是:
{
"compilerOptions": {
"esModuleInterop": true,
"target": "ES6",
"module": "ES6",
"moduleResolution": "node",
"declaration": true,
"outDir": "./lib",
"strict": true
},
"include": ["src"],
"exclude": ["node_modules", "**/__tests__/*"]
}
Run Code Online (Sandbox Code Playgroud)
在我的应用程序代码中,我已将包添加到 package.json (并运行 npm update),并尝试使用以下命令将其导入应用程序入口文件中:
import { initByClass } from "widgety";
Run Code Online (Sandbox Code Playgroud)
但它给了我一个错误:
TS2306:文件“/var/app/app/node_modules/widgety/src/index.ts”不是模块。
我需要更改什么才能使代码可以导入到另一个打字稿项目中?
如果它们有用,所有项目文件: https: //github.com/Danack/widgety/ 以及 …
我正在使用php中的多语言应用程序.
一切都很好,直到最近才被要求支持中文字符.我用来支持UTF-8字符的操作如下:
所有数据库表现在都是UTF-8
HTML模板包含标记 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
控制器发出一个标题,指定用于http响应的编码(utf-8)
一切都很好,直到我开始做一些字符串操作(substr和喜欢)
使用中文它将无法工作,因为中文表示为多字节,因此如果你执行一个正常的子字符串(substr),它将在分配的一个字节的中间大量剪切一个"字母",然后f*ck得到结果屏幕.
我通过在引导程序中添加它来解决所有问题
mb_internal_encoding("UTF-8");
并更换所有的strlen,substr,strstr与他们mb_同行.
在php中完全支持UTF-8还需要做些什么?
我希望能够选择将.PSD图像中的哪些图层合并到最终的.JPG输出图像中.
我可以合并图像中的所有图层:
$im = new Imagick('test.psd');
$im->flattenImages();
$im->setImageFormat('jpg');
$im->writeImage('test.jpg');
Run Code Online (Sandbox Code Playgroud)
但是.psd包含大约10个图层,我希望能够指定哪些特定图层应该合并在一起,以生成最终图像.
例如,我想只合并图层编号3,5和10或名称为"RED","GREEN","BLUE"的图层