phpunit

PHPUnit assert no method is called

旧街凉风 提交于 2019-12-21 06:47:30
问题 I have a ClassA that uses a ServiceB. In a certain case, ClassA should end up not invoking any methods of ServiceB. I now want to test this and verity no methods are indeed called. This can be done as follows: $classA->expects( $this->never() )->method( 'first_method' ); $classA->expects( $this->never() )->method( 'second_method' ); ... Is there a way to simply state "no method should be called on this object" rather then having to specify a restriction for each method? 回答1: Yes, it's quite

Mocking Laravel's Request::segment method

我的未来我决定 提交于 2019-12-21 05:49:12
问题 This is related to this question, but following that solution did not fix my issue. I also realize that Laravel's own documentation states that you should not mock the Request object, but I'm not sure how else to go about writing this test. Here's a semblance of the code I want to test: public function getThirdSegment() { return Request::segment(3); } Here's a test I currently have: /** * @test */ public function indexReturnsOk() { $this->prepareForTests(); $this->call('GET', '/api/v1/courses

select a option with selenium2+phpunit

大憨熊 提交于 2019-12-21 05:05:10
问题 I got a select element that look like this, now I want to open it up and select the option with value t3, so I tried it like this: <select id="selectMenu"> <option value=""> </option> <option value="t1">test 1</option> <option value="t2">test 2</option> <option value="t3">test 3</option> <option value="t4">test 4</option> <option value="t5">test 5</option> <option value="t6">test 6</option> </select> $this->byId('selectMenu')->click(); sleep(1); $type = $this->elements($this->using('css

How do I unit test socket code with PHPUnit?

夙愿已清 提交于 2019-12-21 04:17:04
问题 I currently have a Socket class, which is basically just an OO wrapper class for PHP's socket_* functions: class Socket { public function __construct(...) { $this->_resource = socket_create(...); } public function send($data) { socket_send($this->_resource, $data, ...); } ... } I don't think I can mock the socket resource since I'm using PHP's socket functions, so right now I'm stuck as to how to reliably unit test this class. 回答1: You appear to be missing a small piece to the unit test

echo in phpunit tests [duplicate]

心不动则不痛 提交于 2019-12-21 03:53:30
问题 This question already has answers here : How to output in CLI during execution of PHP Unit tests? (14 answers) Closed last year . I have been trying to echo stuff in my phpunit tests but no luck so far. I read the documentation about the xml config file and apparently the debug parameter is what I am looking for. Unfortunately it still doesn't work. Anyhow here is my xml config file: <?xml version="1.0" encoding="UTF-8"?> <phpunit colors="true" processIsolation="true" verbose="true" debug=

Re-run last failed test in PHPUnit

 ̄綄美尐妖づ 提交于 2019-12-21 03:49:05
问题 You may use --stop-on-failure flag to break the unit testing when one of the tests fails. Is there any way quick way to tell PHPUnit to re-run this failed test, instead providing the full path manually? 回答1: Take a look at the --filter cli option. You can find an example in the organisation docs and in the CLI Docs. --filter Only runs tests whose name matches the given pattern. The pattern can be either the name of a single test or a regular expression that matches multiple test names. Assume

Re-run last failed test in PHPUnit

血红的双手。 提交于 2019-12-21 03:49:03
问题 You may use --stop-on-failure flag to break the unit testing when one of the tests fails. Is there any way quick way to tell PHPUnit to re-run this failed test, instead providing the full path manually? 回答1: Take a look at the --filter cli option. You can find an example in the organisation docs and in the CLI Docs. --filter Only runs tests whose name matches the given pattern. The pattern can be either the name of a single test or a regular expression that matches multiple test names. Assume

Install PHPUNIT with Composer

一个人想着一个人 提交于 2019-12-21 03:43:24
问题 I have project on Symfony 2 and i would like use PHPUNIT on Windows 7. On githut phpunit is: Composer Simply add a dependency on phpunit/phpunit to your project's composer.json file if you use Composer to manage the dependencies of your project. Here is a minimal example of a composer.json file that just defines a development-time dependency on PHPUnit 3.7: { "require-dev": { "phpunit/phpunit": "3.7.*" } } For a system-wide installation via Composer, you can run: composer global require

PHPUnit print tests execution time

蹲街弑〆低调 提交于 2019-12-21 03:28:46
问题 is there a way to print the execution time of each test with PHPUnit? 回答1: You can implement your own test runner, for example by extending PHPUnit_TextUI_TestRunner and make it collect and print run times. 回答2: To add some more ways: You can write a custom Test listener and add it to the XML file. In that listener you can access the $testResult->time() . Some lines in your phpunit.xml and a 10 line PHP class. Not too much hassle. class SimpleTestListener implements PHPUnit_Framework

Equivalent of SimpleTest “partial mocks” in PHPUnit?

独自空忆成欢 提交于 2019-12-21 03:12:09
问题 I'm trying to migrate a bunch of tests from SimpleTest to PHPUnit and I was wondering if there is an equivalent for SimpleTest's partial mocks. Update: I can't seem to find anything in the docs which suggests that this feature is available, but it occurred to me that I could just use a subclass. Is this a good or bad idea? class StuffDoer { protected function doesLongRunningThing() { sleep(10); return "stuff"; } public function doStuff() { return $this->doesLongRunningThing(); } } class