gpt4 book ai didi

javascript - 读取本地 Json PHPUnit 日志文件 JQuery

转载 作者:行者123 更新时间:2023-11-30 18:34:32 25 4
gpt4 key购买 nike

我一直在尝试使用 jquery 解析 phpunit json 日志,但它返回错误。

我用下面的代码来解析

 <html>
<head>
<title>PHPUnit Report</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="./jquery-1.6.2.min.js"></script>
</head>
<body>
<script type="text/javascript">
var json = $.getJSON('logfile.json', function(data){
alert(data);
}).success(function() { alert("second success"); })
.error(function() { alert("error"); });
</script>
</body>
</html>

这是json日志文件

 {"event":"suiteStart","suite":"","tests":22}{"event":"suiteStart","suite":"Application_Model_CarrinhoTest","tests":4}{"event":"testStart","suite":"Application_Model_CarrinhoTest","test":"Application_Model_CarrinhoTest::testCriacaoObjeto"}{"event":"test","suite":"Application_Model_CarrinhoTest","test":"Application_Model_CarrinhoTest::testCriacaoObjeto","status":"pass","time":0.013954162597656,"trace":[],"message":""}{"event":"testStart","suite":"Application_Model_CarrinhoTest","test":"Application_Model_CarrinhoTest::testAdicionarProduto"}{"event":"test","suite":"Application_Model_CarrinhoTest","test":"Application_Model_CarrinhoTest::testAdicionarProduto","status":"pass","time":0.015092134475708,"trace":[],"message":""}{"event":"testStart","suite":"Application_Model_CarrinhoTest","test":"Application_Model_CarrinhoTest::testRemoverProduto"}{"event":"test","suite":"Application_Model_CarrinhoTest","test":"Application_Model_CarrinhoTest::testRemoverProduto","status":"pass","time":0.0048158168792725,"trace":[],"message":""}{"event":"testStart","suite":"Application_Model_CarrinhoTest","test":"Application_Model_CarrinhoTest::testLimparCarrinho"}{"event":"test","suite":"Application_Model_CarrinhoTest","test":"Application_Model_CarrinhoTest::testLimparCarrinho","status":"pass","time":0.0047218799591064,"trace":[],"message":""}{"event":"suiteStart","suite":"Application_Model_ProdutoTest","tests":3}{"event":"testStart","suite":"Application_Model_ProdutoTest","test":"Application_Model_ProdutoTest::testaCriacaoProduto"}{"event":"test","suite":"Application_Model_ProdutoTest","test":"Application_Model_ProdutoTest::testaCriacaoProduto","status":"pass","time":0.0066261291503906,"trace":[],"message":""}{"event":"testStart","suite":"Application_Model_ProdutoTest","test":"Application_Model_ProdutoTest::testaErroCriacao"}{"event":"test","suite":"Application_Model_ProdutoTest","test":"Application_Model_ProdutoTest::testaErroCriacao","status":"pass","time":0.0081219673156738,"trace":[],"message":""}{"event":"testStart","suite":"Application_Model_ProdutoTest","test":"Application_Model_ProdutoTest::testaCadastroProduto"}{"event":"test","suite":"Application_Model_ProdutoTest","test":"Application_Model_ProdutoTest::testaCadastroProduto","status":"pass","time":0.086114883422852,"trace":[],"message":""}{"event":"suiteStart","suite":"Default_CarrinhoControllerTest","tests":4}{"event":"testStart","suite":"Default_CarrinhoControllerTest","test":"Default_CarrinhoControllerTest::testIndexAction"}{"event":"test","suite":"Default_CarrinhoControllerTest","test":"Default_CarrinhoControllerTest::testIndexAction","status":"fail","time":0.18276596069336,"trace":[],"message":"Failed asserting node denoted by div#view-content p CONTAINS content \"View script for controller <b>Carrinho<\/b> and script\/action name <b>index<\/b>\""}{"event":"testStart","suite":"Default_CarrinhoControllerTest","test":"Default_CarrinhoControllerTest::testAdicionarProdutoAction"}{"event":"test","suite":"Default_CarrinhoControllerTest","test":"Default_CarrinhoControllerTest::testAdicionarProdutoAction","status":"pass","time":0.038674831390381,"trace":[],"message":""}{"event":"testStart","suite":"Default_CarrinhoControllerTest","test":"Default_CarrinhoControllerTest::testRemoverProdutoAction"}{"event":"test","suite":"Default_CarrinhoControllerTest","test":"Default_CarrinhoControllerTest::testRemoverProdutoAction","status":"pass","time":0.039582967758179,"trace":[],"message":""}{"event":"testStart","suite":"Default_CarrinhoControllerTest","test":"Default_CarrinhoControllerTest::testAlterarQuantidadeProdutoAction"}{"event":"test","suite":"Default_CarrinhoControllerTest","test":"Default_CarrinhoControllerTest::testAlterarQuantidadeProdutoAction","status":"pass","time":0.038434982299805,"trace":[],"message":""}{"event":"suiteStart","suite":"Default_CategoriaControllerTest","tests":2}{"event":"testStart","suite":"Default_CategoriaControllerTest","test":"Default_CategoriaControllerTest::testIndexAction"}{"event":"test","suite":"Default_CategoriaControllerTest","test":"Default_CategoriaControllerTest::testIndexAction","status":"fail","time":0.043931007385254,"trace":[],"message":"Failed asserting node denoted by div#view-content p CONTAINS content \"View script for controller <b>Categoria<\/b> and script\/action name <b>index<\/b>\""}{"event":"testStart","suite":"Default_CategoriaControllerTest","test":"Default_CategoriaControllerTest::testDetalheAction"}{"event":"test","suite":"Default_CategoriaControllerTest","test":"Default_CategoriaControllerTest::testDetalheAction","status":"pass","time":0.040285110473633,"trace":[],"message":""}{"event":"suiteStart","suite":"Default_IndexControllerTest","tests":1}{"event":"testStart","suite":"Default_IndexControllerTest","test":"Default_IndexControllerTest::testIndexAction"}{"event":"test","suite":"Default_IndexControllerTest","test":"Default_IndexControllerTest::testIndexAction","status":"fail","time":0.045408964157104,"trace":[],"message":"Failed asserting node denoted by div#welcome h3 CONTAINS content \"This is your project's main page\""}{"event":"suiteStart","suite":"Default_ProdutoControllerTest","tests":2}{"event":"testStart","suite":"Default_ProdutoControllerTest","test":"Default_ProdutoControllerTest::testIndexAction"}{"event":"test","suite":"Default_ProdutoControllerTest","test":"Default_ProdutoControllerTest::testIndexAction","status":"fail","time":0.04747200012207,"trace":[],"message":"Failed asserting last controller used <\"error\"> was \"Produto\""}{"event":"testStart","suite":"Default_ProdutoControllerTest","test":"Default_ProdutoControllerTest::testDetalheAction"}{"event":"test","suite":"Default_ProdutoControllerTest","test":"Default_ProdutoControllerTest::testDetalheAction","status":"fail","time":0.042054891586304,"trace":[],"message":"Failed asserting last controller used <\"error\"> was \"Produto\""}{"event":"suiteStart","suite":"Default_ProdutosControllerTest","tests":3}{"event":"testStart","suite":"Default_ProdutosControllerTest","test":"Default_ProdutosControllerTest::testIndexAction"}{"event":"test","suite":"Default_ProdutosControllerTest","test":"Default_ProdutosControllerTest::testIndexAction","status":"pass","time":0.046010971069336,"trace":[],"message":""}{"event":"testStart","suite":"Default_ProdutosControllerTest","test":"Default_ProdutosControllerTest::testBuscarAction"}{"event":"test","suite":"Default_ProdutosControllerTest","test":"Default_ProdutosControllerTest::testBuscarAction","status":"pass","time":0.043781995773315,"trace":[],"message":""}{"event":"testStart","suite":"Default_ProdutosControllerTest","test":"Default_ProdutosControllerTest::testDetalheAction"}{"event":"test","suite":"Default_ProdutosControllerTest","test":"Default_ProdutosControllerTest::testDetalheAction","status":"pass","time":0.04433798789978,"trace":[],"message":""}{"event":"suiteStart","suite":"Default_UsuarioControllerTest","tests":3}{"event":"testStart","suite":"Default_UsuarioControllerTest","test":"Default_UsuarioControllerTest::testIndexAction"}{"event":"test","suite":"Default_UsuarioControllerTest","test":"Default_UsuarioControllerTest::testIndexAction","status":"pass","time":0.048629999160767,"trace":[],"message":""}{"event":"testStart","suite":"Default_UsuarioControllerTest","test":"Default_UsuarioControllerTest::testLogarAction"}{"event":"test","suite":"Default_UsuarioControllerTest","test":"Default_UsuarioControllerTest::testLogarAction","status":"pass","time":0.046178817749023,"trace":[],"message":""}{"event":"testStart","suite":"Default_UsuarioControllerTest","test":"Default_UsuarioControllerTest::testSairAction"}{"event":"test","suite":"Default_UsuarioControllerTest","test":"Default_UsuarioControllerTest::testSairAction","status":"pass","time":0.04793381690979,"trace":[],"message":""}

怎么了?我该如何解析它?

最佳答案

我认为您的 JSON 应该是这样的,phpunit 在事件发生时输出 JSON...这些事件中的每一个都可以很容易地被解析,但是将它们全部作为一个会抛出错误。

我也希望有一种格式可以直接在 JS 或使用 php 的 json_decode 中解析,但看起来暂时不会发生...

https://github.com/sebastianbergmann/phpunit/issues/142

关于javascript - 读取本地 Json PHPUnit 日志文件 JQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8652221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com