phpunit

How do I test this class using phpunit?

喜你入骨 提交于 2020-01-14 14:01:31
问题 I am using Laravel 4.2 and am trying to get into using phpunit to test my code rather than manually test everything. I have read Jeffrey Way's book 'Laravel Testing Decoded' but I still finding my very first test tricky. The class I am trying to test is below. What I am struggling with is - what should I test? I don't think I should test the database or the Model $advert as these should have their own tests. In which case I think I need to either mock $advert or create a factory for it but I

How do I test this class using phpunit?

谁都会走 提交于 2020-01-14 14:01:16
问题 I am using Laravel 4.2 and am trying to get into using phpunit to test my code rather than manually test everything. I have read Jeffrey Way's book 'Laravel Testing Decoded' but I still finding my very first test tricky. The class I am trying to test is below. What I am struggling with is - what should I test? I don't think I should test the database or the Model $advert as these should have their own tests. In which case I think I need to either mock $advert or create a factory for it but I

After updating phpunit to version 3.6.3, assertRedirectTo() fails

会有一股神秘感。 提交于 2020-01-14 11:53:53
问题 Before updating phpunit everything was ok, function assertRedirectTo() worked as it should, but after updating it shows this error: Declaration of Zend_Test_PHPUnit_Constraint_Redirect::evaluate() should be compatible with that of PHPUnit_Framework_Constraint::evaluate() Can anybody explain what exactly happened? 回答1: Yes, I ran into this problem too two days ago. But on the unfortunetly Zend Framework 1.x is not going to support PHPunit 3.6 or higher :-( So the best thing is that you go back

Unit Testing Magic Methods

浪子不回头ぞ 提交于 2020-01-14 09:48:54
问题 When it comes to unit-testing implementations of magic methods in PHP, what is the recommended means of invoking those methods? I see three options available: Invoking them explicitly/directly: $object->__get('someValue'); Invoking them indirectly (using whatever action is intended to trigger them): $object->someValue; \\ Where __get() is implemented. Invoking them using both methods. Are there any unit testing veterans that could explain which (if any) would be the obvious choice, and why

phpunit - Help needed about risky tests

南楼画角 提交于 2020-01-14 08:35:31
问题 i'm implementing some tests for a site. In a particular test, this result occurred: { "event": "test", "suite": "Example_V_test", "test": "Example_V_test::test_3", "status": "error", "time": 13.469105958939, "trace": [ { "file": "\/opt\/lampp\/htdocs\/buy\/application\/tests\/phpunit.phar", "line": 569, "function": "main", "class": "PHPUnit_TextUI_Command", "type": "::" } ], "message": "Risky Test: Test code or tested code did not (only) close its own output buffers", "output": "" }R 3 / 3

Can't Unit Test: $_SESSION empties before each test is ran

微笑、不失礼 提交于 2020-01-13 11:47:09
问题 I can't unit test my code. $_SESSION clears every time the next test is run. When I run testStartProductSession() my object adds some data to the $_SESSION variable. But when I run the next test method ( testSessionIdIsKept() ) the $_SESSION is empty again. Looks like $_SESSION becomes local variable when unit testing. I don't know what else to do. Please check the output bellow: // session_start() on bootrap.php; class MC_Session_ProductTest extends PHPUnit_Framework_TestCase { /** * @return

Unit Testing Dababase Applications

好久不见. 提交于 2020-01-13 09:43:32
问题 I am trying to get in to the TDD realm, and I'm having a hard time unit testing a few user models I have. I'm trying to test the validation of my models, and the business requirements are as follows: >= 6 character username required >= 5 character password, with at least 1 letter and number valid email format required ... blah blah blah username and email cannot already exist in the DB All requirements are easily testable, except 5, which requires the database to be in a known state. I know

Unit Testing Dababase Applications

柔情痞子 提交于 2020-01-13 09:41:50
问题 I am trying to get in to the TDD realm, and I'm having a hard time unit testing a few user models I have. I'm trying to test the validation of my models, and the business requirements are as follows: >= 6 character username required >= 5 character password, with at least 1 letter and number valid email format required ... blah blah blah username and email cannot already exist in the DB All requirements are easily testable, except 5, which requires the database to be in a known state. I know

Laravel 4 Model Events don't work with PHPUnit

核能气质少年 提交于 2020-01-13 08:58:08
问题 I build a model side validation in Laravel 4 with the creating Model Event : class User extends Eloquent { public function isValid() { return Validator::make($this->toArray(), array('name' => 'required'))->passes(); } public static function boot() { parent::boot(); static::creating(function($user) { echo "Hello"; if (!$user->isValid()) return false; }); } } It works well but I have issues with PHPUnit. The two following tests are exactly the same but juste the first one pass : class UserTest

Running phpunit tests using HHVM (HipHop)

情到浓时终转凉″ 提交于 2020-01-12 14:27:46
问题 I am trying to run PHPUnit unit tests via HHVM on a virtual Ubuntu 12.04 (64-bit Server) install. The tests usually run using a phpunit.xml file located in my tests directory, which includes a bootstrap file to handle autoloading, and the tests run fine on an ordinary php install. However, I keep getting: HipHop Fatal error: File not found: File/Iterator/Autoload.php in /usr/share/php/PHPUnit/Autoload.php on line 64 When running: hhvm -f /usr/bin/phpunit /path/to/my/testsDirectory/SomeTest