phpunit

Zend Framework Unit Test fails on assertResponseCode(200)

北慕城南 提交于 2019-12-25 16:42:48
问题 I am running some unit test on my Zend Framework application. What I cant understand is that the following test fails: public function testCreateFaqItem() { $this->LoginUser(); $this->dispatch('/faq/admin-faq/create'); var_dump($this->getResponse()); $this->assertResponseCode(200); $this->assertQueryContentContains('h1', 'Create'); $this->assertController('admin-faq'); $this->assertAction('edit'); } it fails if on assertResponseCode(200), when i remove the assertResponseCode(200), the test

Cannot extend controller test class

懵懂的女人 提交于 2019-12-25 10:01:15
问题 I have a Base class to be extended by the controller tests: //Base.php namespace AppBundle\Tests\System; abstract class Base extends \PHPUnit_Framework_TestCase { ... } But when I try to extend it: //DefaultControllerTest.php namespace AppBundle\Tests\Controller; use AppBundle\Tests\System\Base; class DefaultControllerTest extends Base { ... } I get this error: /usr/bin/php /tmp/ide-phpunit.php --configuration /server/project/phpunit.xml /server/project/src/AppBundle/Tests Testing started at

Lumen 5.5 JSON API File Upload test breaks with UploadedFile

做~自己de王妃 提交于 2019-12-25 09:49:07
问题 I am building a file upload JSON API with Lumen and trying to write phpunit API tests. The problem I am having though is that as soon as I try to simulate a file upload with a real image constructed like ["file" => new UploadedFile(TestUtils::tempPath('test.jpg'), 'test.jpg', "image\jpeg", 100, null, true)] and sending it via $this->json('POST', '/chunk', $data); , I can't do anything with the uploaded file because it is an array and I get the error Call to a member function move() on array

How do I deal with Class 'PHPUnit_Framework_TestCase' not found error?

北战南征 提交于 2019-12-25 08:27:48
问题 I am trying to integrate to visa direct API. I decided to to it in PHP. However, as I am doing some tests from a sample code they have provided, I got stuck at Fatal error: Class 'PHPUnit_Framework_TestCase' not found error. I have PHPUnit installed since when I check via phpunit --version .. I get PHPUnit 5.6.2 by Sebastian Bergmann and contributors. Below is my code using PHPUnit, would someone direct me where my mistake is? Thank you. <?php class MVisaTest extends \PHPUnit_Framework

phpunit : how to get the count of tests in a test directory without running test

喜你入骨 提交于 2019-12-25 07:11:50
问题 I would like to statically get a count of number of tests in a directory. Is there something available that I can use? Phpunit seems to have a count before test runs say 0/100 and increments it as the test completes. I would like to fetch that number before hand and exit the run possibly. 回答1: The --count-tests option of phploc can give you, just like the grep / wc -l line shown above, an estimate of the number of tests. Due to data providers, for instance, there cannot be an exact number

Why isn't PHPUnit counting this function as having ran?

本秂侑毒 提交于 2019-12-25 05:07:58
问题 I have code like this inside my unit test: // $item_id was defined above $originalMock = $this->getMock( 'Item', array( 'foo' ), array( $item_id )); $originalMock->expects( $this->once() )->method( 'foo' ); $originalMock->functionThatCallsFoo(); It is saying I'm not calling foo at all, even though functionThatCallsFoo & foo are var_dumping out from within. There are several function calls between the publicly called function and the one I'm expecting. I made sure there are no static functions

PHPUnit Selenium2 not returning text

 ̄綄美尐妖づ 提交于 2019-12-25 03:52:06
问题 I am trying to get the text value from an element and I tried lots of variation. nothing worked.. this is my latest attempt: $totalFlightPrice = $row->elements($row->using('css selector')->value('span[class="totalPriceToBook"]')); echo 'counted: '.count($totalFlightPrice)."\n"; foreach ($totalFlightPrice as $tp) { echo 'text: '.$tp->text()."\n"; } when I'm using var_dump on totalFlightPrice I am receving the Object, which means its able to find the div. but when im using the text function

PHPUnit Selenium2 not returning text

梦想的初衷 提交于 2019-12-25 03:51:10
问题 I am trying to get the text value from an element and I tried lots of variation. nothing worked.. this is my latest attempt: $totalFlightPrice = $row->elements($row->using('css selector')->value('span[class="totalPriceToBook"]')); echo 'counted: '.count($totalFlightPrice)."\n"; foreach ($totalFlightPrice as $tp) { echo 'text: '.$tp->text()."\n"; } when I'm using var_dump on totalFlightPrice I am receving the Object, which means its able to find the div. but when im using the text function

Unit testing of json encoding/decoding against errors

微笑、不失礼 提交于 2019-12-25 02:50:38
问题 So basically I have the code which is giving me the message from json_last_error(): $msg = 'Unknown error'; switch (json_last_error()) { case JSON_ERROR_NONE: $msg = null; break; case JSON_ERROR_DEPTH: $msg = 'Maximum stack depth exceeded'; break; case JSON_ERROR_STATE_MISMATCH: $msg = 'Underflow or the modes mismatch'; break; case JSON_ERROR_CTRL_CHAR: $msg = 'Unexpected control character found'; break; case JSON_ERROR_SYNTAX: $msg = 'Syntax error, malformed JSON'; break; case JSON_ERROR

Compare object with datetime properties without microseconds

一世执手 提交于 2019-12-25 00:44:27
问题 As of new phpunit versions \DateTime objects are compared with microseconds precision. It's not always a good idea, because if I have an object like this: class QueueItem { public function __construct() { $this->setCreatedAt(new \DateTime('now', new \DateTimeZone('UTC'))); $this->setUpdatedAt(new \DateTime('now', new \DateTimeZone('UTC'))); } } I'll never be able to use assertEquals for the whole object in my tests, because datetime properties will always be different due to microseconds. It