PHPUnit知识点汇聚(持续更新)
0、PHPUnit手册:https://phpunit.de/manual/current/zh_cn/phpunit-book.html
1、读取XML文件
developer-a.xml
<?xml version="1.0" encoding="UTF-8" ?> <phpunit> <php> <var name="DB_DSN" value="mysql:dbname=myguestbook;host=localhost" /> <var name="DB_USER" value="root" /> <var name="DB_PASSWD" value="123456" /> <var name="DB_DBNAME" value="fetion" /> </php> </phpunit>
MyTest.php
<?php class MyTest extends PHPUnit_Framework_TestCase { public function testPushAndPop() { $stack = array(); $this->assertEquals(0, count($stack)); array_push($stack, $GLOBALS['DB_USER']); $this->assertEquals('root', $stack[count($stack)-1]); //$this->assertEquals(1, count($stack)); //$this->assertEquals('foo', array_pop($stack)); //$this->assertEquals(0, count($stack)); } } ?>
测试命令:
写道
phpunit --configuration developer-a.xml MyTest.php
2、例 2.3: 利用测试之间的依赖关系
<?php class MultipleDependenciesTest extends PHPUnit_Framework_TestCase { public function testProducerFirst() { $this->assertTrue(true); return 'first'; } public function testProducerSecond() { $this->assertTrue(true); return 'second'; } /** * @depends testProducerFirst * @depends testProducerSecond */ public function testConsumer() { $this->assertEquals( array('first', 'second'), func_get_args() ); } } ?>测试命令行:
相关推荐
hebiwtc 2020-04-22
Nicolase 2019-12-27
田野 2017-10-17
wqzbxh 2015-01-21
limuxia 2011-11-28
SuperMenyII 2019-07-01
huanxueruxi 2019-07-01
wzllai 2019-07-01
xhqiang 2019-06-30
spinachcqb 2019-06-30
yboker 2019-06-30
ahxxx 2019-06-30
aikudeyu 2016-07-01
Ykbug 2016-06-09
zhangkala 2016-01-08
麦盟Maimob 2015-08-26
怕什么真理无穷 2019-06-26
cxymds 2019-06-26
xishizhaohua 2019-06-26