phpunit

phpunit throws Uncaught exception 'PHPUnit_Framework_Exception

谁都会走 提交于 2020-01-11 05:14:08
问题 I have a Zend Framework project, and want to using unit testing to test it. In tests folder, I have the phpunit.xml as following; <phpunit bootstrap="./application/bootstrap.php" colors="true"> <testsuite name="Application Test Suite"> <directory>./</directory> </testsuite> <filter> <whitelist> <directory suffix=".php">../application/</directory> <exclude> <directory suffix=".phtml">../application/</directory> <file>../application/Bootstrap.php</file> <file>../application/controllers

ant -f build.xml: exec returned: 2 with phpunit?

别等时光非礼了梦想. 提交于 2020-01-07 07:50:09
问题 I'm going to integrate PHP project with Jenkins follow this guide. Here's my build.xml file This one is from the output when running ant -f build.xml : phpunit: [exec] PHPUnit 3.6.10 by Sebastian Bergmann. [exec] Usage: phpunit [switches] UnitTest [UnitTest.php] [exec] phpunit [switches] <directory> [exec] --log-junit <file> Log test execution in JUnit XML format to file. [exec] --log-tap <file> Log test execution in TAP format to file. [exec] --log-json <file> Log test execution in JSON

ThinkPHP开发必备composer扩展包

≡放荡痞女 提交于 2020-01-07 06:39:25
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 本文假设读者有能力正常使用composer 环境隔离 dotenv 真实世界的开发往往是这样, 多个团队成员共同开发, 线上线下的代码通过版本控制系统保持一致. 但你无法保证也没理由要求所有机器上的应用配置一致. 例如,要求所有成员使用相同的本地数据库用户名和密码是不合理的. 线上线下使用相同的数据库配置更加不合理. 我们有很多种方式避免这种问题, 一种常见的方法是, 将配置文件重命名为config.example.php, 然后在每个部署的环境再重命名为config.php,并在分发时排除这个文件. 这种方法很容易实现,但缺点是他是静态的. 每当你增加了一项配置, 或者减少了一项配置, 都需要告诉别人手动处理config.php. 否则, 它的程序可能无法正常运行. 通过专门的环境配置区分不同的部署环境,是另一种被广泛采用的方案. 它的原理很简单: 不同的部署环境中, 需要区别的配置往往非常有限, 所有将config.php纳入版本控制或者分发包中更合理. 这样config.php有变化时,其他环境中的应用可以第一时间更新. 那有限的几个有环境有关配置, 往往都是诸如数据库配置这种必不可少的. 将它们单独隔离出来更加合理. 通常, 实施这种方案会把 隔离的配置放在一个名为 .env 的文件中. 因此这种方案,

PHPUnit stubs - make expected calls independent of the order of invocation

倾然丶 夕夏残阳落幕 提交于 2020-01-06 14:17:11
问题 I have the following unit test code: $map = [ 'key1' => 'A', 'key2' => 'B' ]; $stub = $this->getMockBuilder('Phalcon\Session\Bag') ->setConstructorArgs([$sessionNamespace]) ->getMock(); $stub->expects($this->at(0)) // Always called first by: new Phalcon\Session\Bag() ->method('setDI') ->will($this->returnCallback(function($di) { $this->di = $di; })); $stub->expects($this->at(1)) // First, we're checking if session key is set ->method('__isset') ->will($this->returnCallback(function(

Change of baseUrl for PHPUnit in Laravel 5.4

删除回忆录丶 提交于 2020-01-06 06:55:10
问题 It seems that before Laravel 5.4 we could change the URL for testing by coding like this: protected $baseUrl = 'http://someurl.com'; But now it is not working and some suggest we have to use this method function setUp() { parent::setUp(); config(['app.url' => 'http://yourcustomeaddress.loc']); } Would anybody help me and tell Where I should put this method? 回答1: You may put it in tests/TestCase.php (Laravel 5.4 example): abstract class TestCase extends BaseTestCase { function setUp() { parent

phpunit error when testing an implementation with injected dependencies

梦想与她 提交于 2020-01-06 06:53:23
问题 I am trying to set up a phpunit test on a class I have built called EloquentListing which implements an interface called ListingInterface . The constructor for the EloquentListing model requires an Eloquent Model to be injected. As such I am using a service provider to bind the implementation to the interface and inject the model called RepoServiceProvider . However, I am getting the following error when I run phpunit: .PHP Fatal error: Cannot instantiate interface PlaneSaleing\Repo\Listing

PhpUnit + Symfony: Why coverage shows white instead of red and gives 100% on untested class?

こ雲淡風輕ζ 提交于 2020-01-06 05:23:44
问题 I have a problem and I have created an empty project to reproduce the minimal situation that makes it repeatable. Problem A project with untested classes gives 100% coverage. The problematic methods are not indirectly called from somewhere else. Although there are other methods of the untested class that are indirectly called when testing another class. How to reproduce Step 1: Create an empty new symfony project. I have created a new symfony 3.3 project with this command: symfony new

PHPUnit: expect method call with array as argument

守給你的承諾、 提交于 2020-01-05 14:05:24
问题 I have a PHPUnit test case, in which I am puzzled by the following snippet. I want to check that the method actionUpload calls the function exposeAndSaveDataLines correctly, i.e. that the first argument is an array as I expect it to be. public function test_actionUpload() { $sut = $this->getMockBuilder('MasterdataController') ->setMethods(array('exposeAndSaveDataLines', 'render')) ->disableOriginalConstructor() ->getMock(); $expectedLines = require_once ($this->dataDir . 'expectedLines.php');

Phing with PHPUnit 0 tests executed

不羁岁月 提交于 2020-01-05 13:27:43
问题 I'm trying to execute PHPUnit with phing but i'm finding some errors. I have my target: <target name="tests"> <phpunit pharlocation="C:/xampp/php/phpunit.phar" printsummary="true" haltonfailure="true" haltonerror="true"> <formatter type="xml" usefile="false"/> <batchtest> <fileset dir="."> <include name="tests/*Test*.php"/> </fileset> </batchtest> </phpunit> </target> But when i execute i have: [phpunit] <?xml version="1.0" encoding="UTF-8"?> [phpunit] <testsuites> [phpunit] <testsuite name=

Removing comment in ini file writen by ant when updating the ini file

南楼画角 提交于 2020-01-05 08:12:12
问题 I have an ant file which updates the data in ant file due this ini file gets updated and at the top it has a comment as follows #Thu, 07 Jul 2011 06:54:54 -0500 I don't want this comment as i am accessing this file by php using parse_ini. Due to this comment i get an failure Comments starting with '#' are deprecated in build.ini on line 1 so is there any way so that i will not get the comment in ini file. Thanks. EDIT: <propertyfile file="build.ini"> <entry key="build-number" type="int"