phpunit

How do you manage the unit test files in projects? do you add them in git?

无人久伴 提交于 2019-12-22 10:27:11
问题 How do you manage your PHPUnit files in your projects? Do you add it to your git repository or do you ignore them? Do you use @assert tag in your PHPdocs codes? 回答1: Setup I'm not using php currently, but I'm working with python unit testing and sphinx documentation in git. We add our tests to git and even have certain requirements on test passing for pushing to the remote devel and master branches ( master harder than devel ). This assures a bit of code quality (test coverage should also be

Fatal error: Class 'PHPUnit_Framework_TestCase' not found

て烟熏妆下的殇ゞ 提交于 2019-12-22 09:37:35
问题 I am using XAMPP 1.8.1, Windows 7 64 bit, Netbeans IDE 7.4 I have installed PHPUnit. When I run a code, I am getting the below error. Fatal error: Class 'PHPUnit_Framework_TestCase' not found in D:\xampp\htdocs\PHPUnit\index.php on line 6 The Code is: <?php class StackTest extends PHPUnit_Framework_TestCase { public function testPushAndpop() { $stack = array(); $this->assertEquals(0, count($stack)); array_push($stack, 'foo'); $this->assertEquals('foo', $stack[count($stack) - 1]); $this-

ZF + Doctrine2 phpUnit error: PDOExeption: You cannot serialize or unserialize PDO instances

前提是你 提交于 2019-12-22 08:54:38
问题 I'm using DynamicGuys doctrine2 integration into zend framework(https://github.com/dynamicguy/zf1doctrine2). It works, but if i want to make tests with phpUnit i get this error: PDOExeption: You cannot serialize or unserialize PDO instances I've searched a bit, and i found out that if i comment out line 44 in this file: https://github.com/dynamicguy/zf1doctrine2/blob/master/library/ZendX/Doctrine2/Application/Resource/Entitymanagerfactory.php phpUnit works, but of course the rest of the

Use a different email config during unit testing in CakePHP

五迷三道 提交于 2019-12-22 06:36:19
问题 I'm sending an email using the CakeEmail class in an action of one of my controllers. I have a unit test for this controller that was working fine before adding the email code. After adding the email I get this error: SocketException: Could not send email. This is down to the fact that I don't have any way of sending emails off my local machine. So I thought that maybe a good idea would be to have two different configuration options inside the EmailConfig class in Config/email.php (Similar to

How to load routes based on application/json header in Laravel

*爱你&永不变心* 提交于 2019-12-22 06:31:39
问题 I'm using the application/json header to control how my controller acts when a request is received. I need for the POST in my unit test to include an application/json header. I've tried: public function testStore() { $this->validator ->shouldReceive('validate') ->once() ->with($this->attributes) ->andReturn(true); $this->repository ->shouldReceive('create') ->once() ->with($this->attributes) ->andReturn($this->entity); $this->controller ->shouldReceive('creationSucceeded') ->once() ->with(

Why is CIUnit needed in order to use PHPUnit with CodeIgniter?

三世轮回 提交于 2019-12-22 05:57:50
问题 We've decided to use PHPUnit (with Jenkins) in our next project. We're considering different PHP frameworks, one of which is CodeIgniter. I see that a lot of people use My CIUNIT to "bridge" PHPUnit and Codeigniter. There is little to no explanation in the online documentation. Why is it needed? Other frameworks don't seem to need a "cool bridge" like this. 回答1: Reasons: Codeigniter's components are tightly coupled. You need some big basic parts running (the loader, the router, the CFG object

Yii - Model Unittesting an upload form

扶醉桌前 提交于 2019-12-22 05:33:09
问题 I have the following uploadform model class TestUploadForm extends CFormModel { public $test; public function rules() { return array( array(test, 'file', 'types' => 'zip, rar'), ); } My Question is, how can I unit test this? I've tried something like: public $testFile = 'fixtures/files/yii-1.1.0-validator-cheatsheet.pdf'; public function testValidators() { $testUpload = new TestUploadForm; $testUpload->test = $this->testFile ; assertTrue($testUpload ->validate()); $errors= $testUpload -

LARAVEL UNIT TEST - Opposite of seeInDatabase

本小妞迷上赌 提交于 2019-12-22 05:26:09
问题 In Laravel 5.1 there is a method that asset if some data are in database using the seeInDatabase($table,$fields)... Is there a way to assert if the some data arent in database? Something like dontSeeInDatabase... Similiar to dontSeeJson 回答1: Laravel v5.6 Assertion name has changed ->assertDatabaseMissing(string $table, array $data, string $connection = null) the opposite would be ->assertDatabaseHas(string $table, array $data, string $connection = null) Previous Laravel versions There are two

Best Practices for Data Providing - PHPUnit

泪湿孤枕 提交于 2019-12-22 05:04:31
问题 I'm currently writing units tests for a library, after refactoring business logic from the data, I'm now in a bit of confused state over how to now test the logic! For example, I have a quite complex process which an array of data get's passed through, I'm going to use a data provider for this so I can make sure it will work for all sorts of cases. With the data that I'm going to be passing in through the data provider, should I also be passing an expected outcome? Or should this be

How to make a PHPUnit test that depends on ~real~ POST/GET data?

瘦欲@ 提交于 2019-12-22 04:45:16
问题 I've created a PHP class that envelopes filter_input functions to make our developer's life easier. To validate an HTML form with url , name and age fields, the code would be like that: $post = Filter::POST(); if ($post->validate_string('name') && $post->validate_integer('age')) { $url = $post->sanitize_url('url'); } It would be the same as: if (filter_input(INPUT_POST,'name',FILTER_UNSAFE_RAW) && filter_input(INPUT_POST,'age',FILTER_VALIDATE_INTEGER)) { $url = filter_input(INPUT_POST,'url'