phpunit

PHPUnit: stub methods undefined

吃可爱长大的小学妹 提交于 2019-12-30 07:55:13
问题 I must be missing something. I'm trying to stub methods on a class in PHPUnit, but when I invoke the method on the mock object, it tells me that method is undefined. Example class to stub: namespace MyApp; class MyStubClass { public function mrMethod() { // doing stuff } } To stub it, I write: // specifying all getMock() args to disable calling of class __construct() $stub = $this->getMock('MyStubClass', array(), array(), 'MockMyStubClass', false, false, false); $stub->expects($this->any()) -

PHPUnit loads all classes at once. Causes PHP Fatal error: Cannot redeclare class

泄露秘密 提交于 2019-12-30 07:01:36
问题 I've done my due diligence, but I don't think any of the questions so far have touched on this problem. I have a situation where my PHP code generates class definitions based on config properties. The class definitions are basically data holders and can have either: public properties or protected properties with a public interface that supplies getter/setters. In certain config cases, the generated CLASS NAMES WILL BE THE SAME but their FILE NAMES WILL BE DIFFERENT. In a real environment, the

Installing Phing & PHPUnit on MAMP

回眸只為那壹抹淺笑 提交于 2019-12-30 05:35:10
问题 I'm having problems running phpunit under MAMP on OS X 10.6. I've installed phpunit via PEAR and it is exists in the MAMP directory but when I run phpunit in terminal nothing happens. I'm guessing that this is a path problem but as a os x newbie, I don't know how to fix it. This is what happens when I try to run it from /Applications/MAMP/bin/php5.3/bin $ phpunit -bash: /usr/bin/phpunit: No such file or directory $ ./phpunit $ The problem looks very similar to this How to Install phpunit 3.5

keeping selenium browser open with phpunit/selenium

拈花ヽ惹草 提交于 2019-12-30 03:19:07
问题 when the tests fail, the browser that the selenium tests were running on closes. this is unhelpful when trying to debug. i know i have the option of a screen shot upon failure, but that doesn't help without the entire context. with the browser still available, i can hit back and inspect what was going on. is there a way to keep the browser open even when asserts fail or elements aren't found? 回答1: figured it out randomly many weeks later. when starting the server, use the option

PHP环境中安装pear、phpunit以及xdebug全攻略

拥有回忆 提交于 2019-12-29 11:58:39
首先,本文是基于wamp环境的基础上的,所以,如果您看到这里还没有搭建好wamp环境的话,介意您先把环境搭建好,因为这里都是一些实践性的内容。 1.准备 wamp环境中,我使用的各个软件的版本如下 windows 2003 Standard Edition SP2 apache HTTP Server 2.3 mysql 5.1.49 php 5.4.5 以上环境的搭建我就不赘述了,网上资料很多,通常也不会出现什么错误,但是如果您使用windows 7来部署的话,注意一下权限的问题就好了,所有的操作使用管理员权限,接下来的内容才是我要着重写的,因为这里经常会出一些意想不到让人头疼并且不容易解决的问题。 首先,需要准备如下内容 pear包,打开这个网址( 点击这里 ),将下载的文件保存到php的根目录里,go-pear.phar 2.安装 2.1安装pear 首先打开CMD命令, 如果您使用windows 7安装的话,之后所有的CMD命令行都介意用管理员权限来打开,当然,是在您可以获得管理员权限的前提下。 cd到php的安装目录(cd会吗?不会@百度吧), 执行命令:php go-pear.phar 这里输入“local”,回车 接下来是让您输入“yes”以确认操作,接下来一直回车就行了 , 不需要选什么1-12 最后出现如下提示 这里您在命令行中输入pear,出结果

Is it possible to create a mock outside a test case in PhpUnit?

时光毁灭记忆、已成空白 提交于 2019-12-29 08:41:51
问题 It may seem silly, hope not, but I want to create a service that will return mock objects for people that uses my project so they can mock all the classes from my project and test their code. My idea was to offer this kind of service so it can be called inside other project's test cases and obtain the appropriate mock for each test. Is that possible? Or there are other ways to do that. Btw, I can't use any mocking library because of project's limitations. 回答1: Yes, it is possible. Under the

Is it possible to create a mock outside a test case in PhpUnit?

痴心易碎 提交于 2019-12-29 08:41:29
问题 It may seem silly, hope not, but I want to create a service that will return mock objects for people that uses my project so they can mock all the classes from my project and test their code. My idea was to offer this kind of service so it can be called inside other project's test cases and obtain the appropriate mock for each test. Is that possible? Or there are other ways to do that. Btw, I can't use any mocking library because of project's limitations. 回答1: Yes, it is possible. Under the

Symfony2 functional testing InvalidArgumentException: The current node list is empty

杀马特。学长 韩版系。学妹 提交于 2019-12-29 07:28:19
问题 I get "InvalidArgumentException: The current node list is empty." running functional tests through PHPUnit. Here is test i wrote: public function testAdd() { $client = static::createClientWithAuthentication('main'); $crawler = $client->request('GET', 'en/manage'); $send_button = $crawler->selectButton('submit'); $form = $send_button->form(array( 'PrCompany[email]' => 'test@example.ua', 'PrCompany[first_name]' => 'Anton', 'PrCompany[last_name]' => 'Tverdiuh', 'PrCompany[timezone]' => 'Europe

PHP Mocking Final Class

喜夏-厌秋 提交于 2019-12-29 03:52:26
问题 I am attempting to mock a php final class but since it is declared final I keep receiving this error: PHPUnit_Framework_Exception: Class "Doctrine\ORM\Query" is declared "final" and cannot be mocked. Is there anyway to get around this final behavior just for my unit tests without introducing any new frameworks? 回答1: Since you mentioned you don't want to use any other framework, you are only leaving yourself one option: uopz uopz is a black magic extension of the runkit-and-scary-stuff genre,

配置PHP单元测试的方法实例

核能气质少年 提交于 2019-12-27 18:50:20
这篇文章主要介绍了PHP单元测试配置与使用方法,结合实例形式详细分析了PHP单元测试的具体安装、配置、使用方法及相关操作注意事项,需要的朋友可以参考下 本文实例讲述了PHP单元测试配置与使用方法。分享给大家供大家参考,具体如下: php与其他语言不太一样,单元测试需要自己安装和配置,相对麻烦一点,不过单元测试对于提高库的稳定性和健壮性还是非常给力的,下面教大家怎么配置PHP单元测试 注意:php需升级到7.1版本以上 配置说明 1.全局安装phpunit命令脚本 $ wget https://phar.phpunit.de/phpunit-7.0.phar $ chmod +x phpunit-7.0.phar $ sudo mv phpunit-7.0.phar /usr/local/bin/phpunit $ phpunit --version PHPUnit x.y.z by Sebastian Bergmann and contributors. 2.全局安装安装phpunit代码 composer global require phpunit/phpunit 3.创建 phpunit.xml放在你的项目根目录, 这个文件是 phpunit 会默认读取的一个配置文件: <phpunit bootstrap="vendor/autoload.php"> <testsuites