phpunit

Doctrine's entity manager crashes and stays down

痴心易碎 提交于 2020-01-02 04:16:06
问题 So, when I run tests on my ZF/Doctrine application, some tests happen to break the Doctrine Entity Manager, and all the sequential tests fail due to EM being closed. I set the EM up in my tests/bootstrap.php: $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $application->bootstrap(); (...) $bootstrap = $application->getBootstrap(); $em = $bootstrap->getResource('doctrinemanager'); Then I set it inside the test setUp() function ($this->

Symfony2 Functional test: Passing form data directly

谁都会走 提交于 2020-01-02 03:23:28
问题 I am using phpunit to run functional tests but I am having a problem with a few of the forms. The problem is that phpunit is not aware of JS, and I have a form with a dynamically populated select box that needs jQuery. So I need to pass the form data directly. The 'book' gives the following example: // Directly submit a form (but using the Crawler is easier!) $client->request('POST', '/submit', array('name' => 'Fabien')); When I used this example the controller didn't receive any of the form

How to upgrade phpunit to new version?

余生长醉 提交于 2020-01-02 03:12:09
问题 Current, I installed phpunit. i use OS win 10. I think i installed new version from https://phpunit.de/ (current version 5.6, beta 5.7). But when check version with command line, it version 3.7. My version PHP Unit i read these post: How do I update phpunit?. But i can't understand. Help me !!! :( 回答1: Just download the latest version and replace the old one. It is provided from the phpunit homepage. $ wget https://phar.phpunit.de/phpunit.phar $ chmod +x phpunit.phar $ sudo mv phpunit.phar

PHPUnit strict mode - how to change default timeout

时光总嘲笑我的痴心妄想 提交于 2020-01-02 01:47:08
问题 I'd like to keep running my unit tests in strict mode so that I'm aware of any exceptionally long tests easily, but at the same time the default timeout of 1s is not enough. Can I change it for all tests? I know I can set timeout for each class (and individual tests) using @short / @medium / @long annotations, but is there something like that for all tests? Perhaps in phpunit.xml? This is to avoid PHP_Invoker_TimeoutException: Execution aborted after 1 second that happens once in a while. 回答1

PHPUnit: How to mock today's date without passing it as an argument?

这一生的挚爱 提交于 2020-01-02 01:01:18
问题 I am testing a method on my class that does some date checking. The problem is that the method depends on today's date (which changes every day), which makes this difficult to test. How can I mock today's date so that my tests will still pass tomorrow? 回答1: I know nothing about PHP, but in both Java and C# I would pass in a "clock" of some description - not today's date itself, but an object which you can ask for the current date/time. Then in unit tests you can pass in an object which can

PHPUnit Error: Class not found

孤者浪人 提交于 2020-01-01 19:25:11
问题 I'm using symfony 4.0 and using "symfony/phpunit-bridge": "^4.0" in composer.json. I have installed phpunit-bridge using command composer require --dev phpunit . Now when I run vendor\bin\simple-phpunit tests/Handler It shows this error C:\xampp\htdocs\symfonydemo>vendor\bin\simple-phpunit tests/Handler PHPUnit 6.3.1 by Sebastian Bergmann and contributors. Testing tests/Handler E 1 / 1 (100%) Time: 173 ms, Memory: 4.00MB There was 1 error: 1) App\Tests\Handler\CalculatorResultHandlerTest:

Configuring File Names for PHPUnit

余生长醉 提交于 2020-01-01 10:28:13
问题 I am a new user of PHPUnit, and I am converting our existing tests (asserts) into the PHPUnit framework to provide a better test environment and code coverage. However, I need to know how to try to get PHPUnit working with our testing code structure. Our project directories are similar to the following: Application1/ CREDIT_CARD.class - Class naming convention for CREDIT_CARD CREDIT_CARD.class.test - Automated Tests for CREDIT_CARD.class File.php - Application File File.php.test - Automated

SecurityComponent black-holing my controller test case

放肆的年华 提交于 2020-01-01 10:13:46
问题 Here's my UsersController test case: <?php App::uses('UsersController', 'Controller'); class TestUsersController extends UsersController { public $autoRender = false; public function redirect($url, $status = null, $exit = true) { $this->redirectUrl = $url; } public function render($action = null, $layout = null, $file = null) { $this->renderedAction = $action; } public function _stop($status = 0) { $this->stopped = $status; } } class UsersControllerTestCase extends ControllerTestCase { public

Symfony 3 composer, ext-dom and ext-xml missing [duplicate]

廉价感情. 提交于 2020-01-01 08:40:21
问题 This question already has answers here : PHPUnit working in IDE, but server says class not found (2 answers) Closed 2 years ago . I am running Linux Mint 18.1. My IDE is PhpStorm and I am trying to install PHPUnit trough the composer. I followed the installation steps at https://getcomposer.org/download/. Problem 1 - Installation request for phpunit/phpunit 6.4.x-dev -> satisfiable by phpunit/phpunit[6.4.x-dev]. - phpunit/phpunit 6.4.x-dev requires ext-dom * -> the requested PHP extension dom

PHPUnit: How do I mock this file system?

南笙酒味 提交于 2020-01-01 08:33:04
问题 Consider the following scenario (this is not production code): class MyClass { public function myMethod() { // create a directory $path = sys_get_temp_dir() . '/' . md5(rand()); if(!mkdir($path)) { throw new Exception("mkdir() failed."); } // create a file in that folder $myFile = fopen("$path/myFile.txt", "w"); if(!$myFile) { throw new Exception("Cannot open file handle."); } } } Right, so what's the problem? Code coverage reports that this line is not covered: throw new Exception("Cannot