JSON数据错误PHP
我试图运行下面提到的php代码,但它出错了 PHP代码:JSON数据错误PHP,php,json,Php,Json,我试图运行下面提到的php代码,但它出错了 PHP代码: <?php public function setUp() { parent::setUp(); $this->citationStyles = $this->sm->get('CitationstyleConversion\Model\Citationstyles'); $this->resetTestData(); } p
<?php
public function setUp()
{
parent::setUp();
$this->citationStyles = $this->sm->get('CitationstyleConversion\Model\Citationstyles');
$this->resetTestData();
}
public function testSubmitActionCannotBeAccessedLoggedOut()
{
$this->dispatch($this->buildQuery('submit', array(), false));
$this->assertResponseStatusCode(403);
}
public function testSubmitAction()
{
$styleMap = $this->citationStyles->getStyleMap();
$keys = array_keys($styleMap);
$data = array(
'fileName' => "Testfile.txt",
'fileContent' => base64_encode('Test Content'),
'citationStyleHash' => $keys[0],
);
$this->dispatch($this->buildQuery('submit', $data));
$this->assertResponseStatusCode(200);
$response = json_decode($this->getResponse()->getContent());
print_r($response); //to print the json result
$this->assertTrue(is_object($response));
$this->assertSame($response->status, 'success');
$this->assertNotEmpty($response->id);
}
我不确定我在代码中哪里做错了。我有参数“fileName”,但错误表明缺少文件名。我不知道怎么解决它。请帮帮我 关于两个字符串相同的唯一断言是
$this->assertSame($response->status,'success')代码>。响应状态似乎是错误
。你需要检查你的$response
变量,看看哪里出了问题。$response
的输出是stdClass对象([error]=>文件名(fileName)参数丢失。[status]=>error[flashMessages]=>Array())
对不起,我没有仔细查看输出!您正在测试的服务如何处理该请求?也许这是该服务中的一个bug,因为正如您所说,fileName
似乎正在填充。如果没有您正在测试的服务背后的代码的详细信息,我怀疑是否有人能够帮助您。我正在尝试运行一个shell程序,从中调用此php代码。我只收到此代码中的错误,没有解决此问题的线索。
Configuration read from /home/quotequadsco/public_html/xmlps/phpunit.xml
.................FstdClass Object
(
[error] => File name (fileName) parameter is missing.
[status] => error
[flashMessages] => Array
(
)
)
Time: 4.17 seconds, Memory: 43.00Mb
There was 1 failure:
1) ApiTest\Controller\ApiControllerTest::testSubmitAction
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-error
+success
/home/quotequadsco/public_html/xmlps/module/Api/test/ApiTest/Controller/JobControllerTest.php:64
FAILURES!
Tests: 18, Assertions: 56, Failures: 1.