phpunit

ZF2 Testing: Failed asserting response code “302”, actual status code is “500”

无人久伴 提交于 2019-12-12 18:25:58
问题 I am implementing PHPUnit tests for an AuthenticationController . When I test the /logout route: public function testLogoutActionCanBeAccessed() { $this->dispatch('/logout'); $this->assertResponseStatusCode(302); $this->assertModuleName('Main'); $this->assertControllerName('Main\Controller\Authentication'); $this->assertControllerClass('AuthenticationController'); $this->assertMatchedRouteName('logout'); } I get the following error message: There was 1 failure: 1) MainTest\Controller

Symfony2 phpUnit YAML parse error

流过昼夜 提交于 2019-12-12 17:39:21
问题 I'm trying to run unit test in symfony2 project, but tests fails because of YAML parse error: The file "../services.yml" does not contain valid YAML in "../" Caused by: The reserved indicator "@" cannot start a plain scalar; you need to quote the scalar at line 6 (near "- [ setContainer, [ @service_container ] ]"). For sure, I should use quotes, but that's work on other PC, so what should I do to solve this error, but not using quotes? 来源: https://stackoverflow.com/questions/34454834/symfony2

How to get the PHP Code Coverage working with phpdbg on a Windows Server?

我与影子孤独终老i 提交于 2019-12-12 17:09:23
问题 Since I still have troubles with PHPUnit / PHP Code Coverage and Xdebug, I decided to try it another way -- with phpdbg. I did it as hier shown. Tried in CMD and also in Git Bash, but the result is the same, it fails: $ composer info | grep "phpunit" phpunit/php-code-coverage 4.0.0 Library that provides collectio... phpunit/php-file-iterator 1.4.1 FilterIterator implementation t... phpunit/php-text-template 1.2.1 Simple template engine. phpunit/php-timer 1.0.8 Utility class for timing phpunit

Selenium/PHPUnit: End a session when re-using browser sessions?

一世执手 提交于 2019-12-12 16:00:06
问题 I'm runnig Selenium tests with PHPUnit. I have some long test sequences split into several test files to make them easier to maintain. For higher speed I would like to re-use the browser session for these cases. I am able to reuse the sessions (PHPUnit_Extensions_SeleniumTestCase::shareSession(true)), but I cannot figure out how to end the session and open a new one before starting the next tests (which require a fresh browser session). I have tried using the following line in the tearDown()

How to avoid race conditions with PHP Unit testing

僤鯓⒐⒋嵵緔 提交于 2019-12-12 15:38:29
问题 Let's start from the proof that it's a race condition I'm facing here: Failed Test Case ❌ phpunit --filter testMethod testlass path/to/testFile.php PHPUnit 5.7.26 by Sebastian Bergmann and contributors. F 1 / 1 (100%) You should really fix these slow tests (>500ms)... 1. 6441ms to run testClass::testMethod Time: 6.49 seconds, Memory: 22.00MB There was 1 failure: 1) ≈ Unable to find row in database table [orders] that matched attributes [{"collect_cash":104,"id":1728,"final_total":100}].

selenium driver, option inside optgroup fails to execute

北战南征 提交于 2019-12-12 15:24:56
问题 I am using the PHP webdriver bindings here: http://code.google.com/p/php-webdriver-bindings/ I can select standard option elements in a <select> no problem, but when they are a child of an <optgroup> the click() method doesn't change the selected item. The element is found (i can var_dump the details of the element). The code I am using is: $xpath = "//select[@name='{$element}']/optgroup[@label='{$optgrp}']/option[@value='{$value}']"; $element = $this->_webdriver->findElementBy

Laravel 5.5: PHPUnit (with coverage) doesn't like routes from multiple files and throws “A facade root has not been set”. Without coverage it's green

喜欢而已 提交于 2019-12-12 15:14:28
问题 I have Laravel 5.5 where I decided to group routes in files to organise them in a more meaningful way. Here's a simplified example - the web route files live in: app/Http/Routes/Web/static.php app/Http/Routes/Web/test.php static.php contains: <?php declare(strict_types=1); namespace Foo\Http\Routes\Web; use Illuminate\Support\Facades\Route; Route::get('/', function () { return view('welcome'); }); test.php contains: <?php declare(strict_types=1); namespace Foo\Http\Routes\Web; use Illuminate

phpunit in symfony2 - No tests executed

孤者浪人 提交于 2019-12-12 15:13:14
问题 Solved - see answer below I have a problem. I'm trying to test some functional tests with phpunit. The problem is that when i use phpunit -c app in command prompt I get No tests executed! . It seems that the path to my application is not right. I tried to change the path in my phpunit.xml.dist . I changed it many times, but the "guess" standard code seems to be the best, <directory>../src/*/*Bundle/Tests</directory> <directory>../src/*/Bundle/*Bundle/Tests</directory> Those links doesn't seem

Fosrestbundle body empty when multipart request

白昼怎懂夜的黑 提交于 2019-12-12 14:57:23
问题 In the code bellow I expect the $request->getContents() to get the body content of the HTTP request. When sending non multipart request this works as expected though when using multipart requests the $body variable remains empty. public function postDebugAction(Request $request) { $body = $request->getContent(); if (empty($body)) { throw new \Exception('Body empty.'); } return $this->view(array(), 201); } After reading this question and answer I added a body listener aswell. <?php namespace

Select impossible value in select inputs with Symfony DomCrawler

梦想的初衷 提交于 2019-12-12 14:13:36
问题 I would like to test the behaviour of my application if I send wrong values in a select input in form. This is my form in HTML : <form (...)> (...) <select name="select_input"> <option value="1">text</option> </select> </select> In my test, in get the form with the crawler and try to "select" an incorrect value : $form['select_input'] = 9999999; $client->submit($form); /* EDIT */ /*I am expecting the user to not be redirected to the user page, and the server to respond with the same form,