phpunit

Laravel REST API Testing in phpunit

别说谁变了你拦得住时间么 提交于 2021-02-08 11:31:29
问题 I am trying to test a Laravel REST API, through phpunit. While testing REST calls, I am unable to isolate REST calls test. In Laravel, I understand a few options like using traits DatabaseMigrations , DatabaseRefresh , DatabaseTransactions . But I can't use these for the following reasons: DatabaseMigrations : The app does not have proper migrations. Even if it had, those would be quite in-efficient. DatabaseRefresh : Same as above. DatabaseTransactions . The problem I see is that call to

How to mock an Object Factory

心已入冬 提交于 2021-02-07 12:23:28
问题 I use Factories (see http://www.php.net/manual/en/language.oop5.patterns.php for the pattern) a lot to increase the testability of our code. A simple factory could look like this: class Factory { public function getInstanceFor($type) { switch ($type) { case 'foo': return new Foo(); case 'bar': return new Bar(); } } } Here is a sample class using that factory: class Sample { protected $_factory; public function __construct(Factory $factory) { $this->_factory = $factory; } public function

Testing special characters with PHP Unit

…衆ロ難τιáo~ 提交于 2021-02-07 08:20:07
问题 I am testing my controller from Symfony2 with PHPUnit and the class WebTestCase return self::$client->request( 'POST', '/withdraw', array("amount" => 130), array(),array()); $this->assertEquals( "You can withdraw up to £100.00.", $crawler->filter("#error-notification")->text()); But I get this error: Expected: "You can withdraw up to £100.00." Actual: "You can withdraw up to £100.00." The thing is that in the webpage and the source code it looks fine, so I am thinking that maybe PHPUnit is

Testing special characters with PHP Unit

十年热恋 提交于 2021-02-07 08:17:27
问题 I am testing my controller from Symfony2 with PHPUnit and the class WebTestCase return self::$client->request( 'POST', '/withdraw', array("amount" => 130), array(),array()); $this->assertEquals( "You can withdraw up to £100.00.", $crawler->filter("#error-notification")->text()); But I get this error: Expected: "You can withdraw up to £100.00." Actual: "You can withdraw up to £100.00." The thing is that in the webpage and the source code it looks fine, so I am thinking that maybe PHPUnit is

The xdebug extension is not loaded

让人想犯罪 __ 提交于 2021-02-07 05:21:47
问题 I've got xdebug installed fine (showing up in phpinfo()) but I'm trying to get it to work with PHPUnit's code coverage functionality. It keeps telling me "The XDebug extension is not loaded". I've got phpunit working fine with WAMP. When i run php -m i don't see xdebug listed in neither php modules nor zend modules which points as to why phpunit is not find the xdebug extension Does anyone have any idea of this problem? My detailed configuration is as follows: Windows 7 php 5.3.0 Apache 2.2

The xdebug extension is not loaded

冷暖自知 提交于 2021-02-07 05:21:30
问题 I've got xdebug installed fine (showing up in phpinfo()) but I'm trying to get it to work with PHPUnit's code coverage functionality. It keeps telling me "The XDebug extension is not loaded". I've got phpunit working fine with WAMP. When i run php -m i don't see xdebug listed in neither php modules nor zend modules which points as to why phpunit is not find the xdebug extension Does anyone have any idea of this problem? My detailed configuration is as follows: Windows 7 php 5.3.0 Apache 2.2

Mocking PDO with phpunit

笑着哭i 提交于 2021-02-06 09:58:23
问题 I am trying to mock PDO object to use when writing some tests with phpunit, but I find it pretty complicated and can't find too much documentation about it. I created this xml structure: <dataset> <table name="providers"> <column>id</column> <column>name</column> <column>description</column> <row> <value>1</value> <value>provdier_1</value> <value>phpunit first provider</value> </row> </table> </dataset> and now I want to query providers table and get the data back but I just cant figure out

PHpUnit with xdebug Breaks at BaseTestRunner instead of the actual test

拟墨画扇 提交于 2021-01-29 13:40:46
问题 I have setup Xdebug remote debugging with the following configuration: I placed a breakpoint in my phpunit test: <?php declare (strict_types = 1); namespace Tests\Api; class MyControllerTest extends ApiTestCase { public function myTest() { // Breakpoint goes here //Rest Of code } } Then I set the Xdebug to listen for the xdebug. ON the remote server (vagrant VM) I run the following commands: export XDEBUG_CONFIG="idekey=VSCODE" phpunit ./tests/app/MyControllerTest.php But my VSCode (ufing

How to filter for multiple tests in PHPUnit?

允我心安 提交于 2021-01-28 16:43:07
问题 I am able to run a single test from a suite using --filter option. I am wondering if there is a way to dynamically run multiple tests under the suite? Thanks 回答1: A simple regex to filter for multiple tests could look like --filter '/test1|test2|test4/' . This will match any tests which contain 'test1' 'test2' or 'test4' so for example test43 would be included, but test3 would not get run. The check is case-sensitive. 回答2: The --filter option runs tests whose name matches the given regular

How can be any service injected into WebTestCase subclass in Symfony?

强颜欢笑 提交于 2021-01-28 08:26:04
问题 Maybe I am missing something... doh, I think so, but could not find an answer to that. WebTestCase generates this constructor sample: public function __construct(?string $name = null, array $data = [], string $dataName = '') { parent::__construct($name, $data, $dataName); } Was trying to add my service as the first or last argument - Symfony throws an error: Type error: Too few arguments to function Tests\AppBundle\Manager\ContactManagerTest::__construct(), 0 passed in /Library/WebServer