phpunit

Why does PHPUnit hide my xdebug backtrace?

混江龙づ霸主 提交于 2020-01-19 13:10:00
问题 I have PHPUnit and xdebug installed, and in my php.ini files for CLI I've got: display_errors = On xdebug.default_enable = 1 I've verified that an xdebug backtrace is printed when I create an error using the interactive console, but when an error occurs while running phpunit, there is no backtrace? What is happening to the backtrace? Is phpunit hiding it from me? Is there some setting I'm missing? Thanks! 回答1: What is happening to the backtrace? Is phpunit hiding it from me? Yes, PHPUnit

Why does PHPUnit hide my xdebug backtrace?

雨燕双飞 提交于 2020-01-19 13:09:05
问题 I have PHPUnit and xdebug installed, and in my php.ini files for CLI I've got: display_errors = On xdebug.default_enable = 1 I've verified that an xdebug backtrace is printed when I create an error using the interactive console, but when an error occurs while running phpunit, there is no backtrace? What is happening to the backtrace? Is phpunit hiding it from me? Is there some setting I'm missing? Thanks! 回答1: What is happening to the backtrace? Is phpunit hiding it from me? Yes, PHPUnit

Laravel unit test with input with array name

痞子三分冷 提交于 2020-01-17 01:22:06
问题 Input I am trying to fill: <input type="text" id="order-number" name="order_numbers[]" class="form-control"> My unit test code: public function testSearch() { $this->actAsUser(); $this->visit('/orders') ->type('12001546', 'order_numbers[]'); } Error I am getting: 1) OrdersTest::testSearch InvalidArgumentException: Unreachable field "" 回答1: I had the same problem, couldn't find a better solution than // TestCase.php protected function storeArrayInput($values, $name) { $this->inputs[$name] =

Failing tests after upgrade to laravel 5.8 / PHPUnit 8

南楼画角 提交于 2020-01-16 08:58:49
问题 After Upgrading to laravel 5.8 / PHPUnit 8 I had several tests that started failing. For example the following test. public function testAdminCanPromoteUsers() { // While using a admin account try to promote non-admin user $this->actingAs($this->admin) ->post('user/promote', ['userPromoteId' => $this->user->id, 'name' => $this->user->name]); // check if user was promoted to admin $user = User::find($this->user->id); $this->assertTrue((bool) $user->isAdmin); } Routes | POST | user/allow | App

How to mock built-in php socket functions?

三世轮回 提交于 2020-01-15 14:29:22
问题 I'm working on some code that reads from a socket, and it goes wrong when it gets a certain large input. I went to add a unit test for this, before fixing it, but got stuck because I cannot mock fread (and the other PHP built-in functions I'm using such as fsockopen , feof , etc.). In simple terms my problem is that this code fails with " Fatal error: Cannot redeclare fgets() ... ": function fgets($fp){ return "xxx"; } I realize I could create a socket wrapper class, that my real code uses,

how to mock global functions and classes used by another class

≯℡__Kan透↙ 提交于 2020-01-15 07:51:25
问题 I am trying to write a test, and one of my methods makes use of a global function web() which takes a (string) url, and creates and returns new instance of UrlHelper . This gives my app some shortcuts to some helper methods. (Yes DI would be better, but this is in a larvel app...) The method I'm trying to test, uses this global helper to get the content of the given url and compares it to another string. Using phpunit, how can i intercept the call to web or the creation of UrlHelper so i can

Testing Private Methods Not Working

霸气de小男生 提交于 2020-01-15 06:12:09
问题 Here is my Test Class; <?php namespace stats\Test; use stats\Baseball; class BaseballTest extends \PHPUnit_Framework_TestCase { public function setUp() { $this->instance = new Baseball(); } public function tearDown() { unset($this->instance); } public function testOps() { $obp = .363; $slg = .469; $ops = $this->instance->calc_ops($obp, $slg); //line 23 $expectedops = $obp + $slg; $this->assertEquals($expectedops, $ops); } } And this is my Baseball Class; <?php namespace stats; class Baseball

Testing Private Methods Not Working

流过昼夜 提交于 2020-01-15 06:10:15
问题 Here is my Test Class; <?php namespace stats\Test; use stats\Baseball; class BaseballTest extends \PHPUnit_Framework_TestCase { public function setUp() { $this->instance = new Baseball(); } public function tearDown() { unset($this->instance); } public function testOps() { $obp = .363; $slg = .469; $ops = $this->instance->calc_ops($obp, $slg); //line 23 $expectedops = $obp + $slg; $this->assertEquals($expectedops, $ops); } } And this is my Baseball Class; <?php namespace stats; class Baseball

Port 80 blocked on cpanel due to phpunit malicious file eval-stdin.php

社会主义新天地 提交于 2020-01-14 19:05:32
问题 I have added google plus login to my website (hosted on shared server). While composing dependent libraries through composer.json for google login, the phpunit library was downloaded as a part. It contains a file phpunit\phpunit\src\Util\PHP\eval-stdin.php. Due to this file port 80 for my domain is blocked as they said its a malware file. The repository link is https://github.com/sebastianbergmann/phpunit Following is the code in eval-stdin.php file eval('?>' . file_get_contents('php://input'

Port 80 blocked on cpanel due to phpunit malicious file eval-stdin.php

◇◆丶佛笑我妖孽 提交于 2020-01-14 19:05:13
问题 I have added google plus login to my website (hosted on shared server). While composing dependent libraries through composer.json for google login, the phpunit library was downloaded as a part. It contains a file phpunit\phpunit\src\Util\PHP\eval-stdin.php. Due to this file port 80 for my domain is blocked as they said its a malware file. The repository link is https://github.com/sebastianbergmann/phpunit Following is the code in eval-stdin.php file eval('?>' . file_get_contents('php://input'