phpunit

How to mock dependency injection with phpunit?

為{幸葍}努か 提交于 2019-12-19 06:01:22
问题 I wish to test methods in this class: class EmailerService { protected $mailer; protected $router; protected $em; protected $emailMan; protected $emailReminderMan; protected $secret; /** * Construct * * @param \Swift_Mailer $mailer * @param \Symfony\Bundle\FrameworkBundle\Routing\Router $router * @param \Doctrine\ORM\EntityManager $em * @param EmailManager $emailMan * @param EmailReminderManager $emailReminderMan * @param $secret */ public function __construct(Swift_Mailer $mailer, Router

PHPUnit , PEAR upgrading Errors

时光总嘲笑我的痴心妄想 提交于 2019-12-19 05:43:13
问题 Note : I've read all questions about this problem PEAR is installed and configured on my system (Ubuntu 11.10 + Apache/2.2.20). Because <?php require_once 'System.php'; var_dump(class_exists('System', false)); ?> Returning this : bool(true) (PEAR Manual : Checking if PEAR works Step 4) When i tried to use phpunit i'm getting this error. PHP Warning: require_once(PHP/CodeCoverage/Filter.php): failed to open stream: No such file or directory in /usr/bin/phpunit on line 38 PHP Fatal error:

Unit Testing Guzzle inside of Laravel Controller with PHPUnit

谁说胖子不能爱 提交于 2019-12-19 03:15:58
问题 I'm not quite sure which way to approach unit testing in this scenario. None of the examples for unit testing Guzzle quite make sense to me how to implement in this scenario, or perhaps I'm just looking at it incorrectly all together. The setup: Laravel 4.2 REST API - A controller method is using Guzzle in the method to request data from another api as follows: <?php class Widgets extends Controller { public function index(){ // Stuff $client = new GuzzleHttp\Client(); $url = "api.example.com

Mockery specifying expected arguments for multiple calls

淺唱寂寞╮ 提交于 2019-12-18 19:40:26
问题 I am trying to mock an object that gets two calls to the same function but with different arguments. It's pretty straight forward to give back different return values for multiple calls but I can't find anywhere how to do it with the argument validation. I tried: $this->eventDispatcher ->shouldReceive('dispatch') ->twice() ->with(Events::SELECT,\Mockery::type('\Not\Really\A\Namespace\Event')) ->with(Events::ACTIVITY,\Mockery::type('\Not\Really\A\Namespace\Event'); And $this->eventDispatcher -

How to mock a service (or a ServiceProvider) when running Feature tests in Laravel?

血红的双手。 提交于 2019-12-18 17:25:57
问题 I'm writing a small API in Laravel, partly for the purposes of learning this framework. I think I have spotted a gaping hole in the docs, but it may be due to my not understanding the "Laravel way" to do what I want. I am writing an HTTP API to, amongst other things, list, create and delete system users on a Linux server. The structure is like so: Routes to /v1/users connect GET , POST and DELETE verbs to controller methods get , create and delete respectively. The controller App\Http

Laravel multiple databases PHPUnit [duplicate]

天涯浪子 提交于 2019-12-18 16:54:04
问题 This question already has answers here : How to use multiple databases in Laravel (4 answers) Closed last year . I am developing a application with multiple database access and I want to have PHPUnit tests with this. My current approache is to have in the config\databases.php multiple connections (mysql, mysql2, mysql3) so I can have in the env file a different access for all of them. Because of this, the models have the $connection variable defined. In my first feature test I want to access

Laravel - Testing what happens after a redirect

徘徊边缘 提交于 2019-12-18 14:12:11
问题 I have a controller that after submitting a email, performs a redirect to the home, like this: return Redirect::route('home')->with("message", "Ok!"); I am writing the tests for it, and I am not sure how to make phpunit to follow the redirect, to test the success message: public function testMessageSucceeds() { $crawler = $this->client->request('POST', '/contact', ['email' => 'test@test.com', 'message' => "lorem ipsum"]); $this->assertResponseStatus(302); $this->assertRedirectedToRoute('home'

PHPUnit - creating Mock objects to act as stubs for properties

家住魔仙堡 提交于 2019-12-18 12:53:17
问题 I'm trying to configure a Mock object in PHPunit to return values for different properties (that are accessed using the __get function) Example: class OriginalObject { public function __get($name){ switch($name) case "ParameterA": return "ValueA"; case "ParameterB": return "ValueB"; } } I'm trying to mock this using: $mockObject = $this->getMock("OrigionalObject"); $mockObject ->expects($this->once()) ->method('__get') ->with($this->equalTo('ParameterA')) ->will($this->returnValue("ValueA"));

PHPUnit : Fatal error handling

拥有回忆 提交于 2019-12-18 12:49:11
问题 I use PHPUnit for unit tests, but when a fatal error is triggered, the script dies and I have no correct PHPUnit output. I'd like that the PHPUnit output stays correctly formated , because it is read by a plugin for Eclipse. Actually the fatal error stops PHPUnit and in Eclipse the plugin can't interpret anything (because the PHPUnit script had an error, instead of handling it). Thanks 回答1: You need to use PHPUnit's process isolation features - start each test suite in a new process. phpunit

Write UnitTest for Symfony EventListener

社会主义新天地 提交于 2019-12-18 11:49:52
问题 I have a SymfonyBundle here, which is really not more then a custom EventDispatcher, and an EventListener. How would I go about unit testing this code ? I know how to create functional tests for controllers etc, but am not really sure how to go about writing tests for this dispatcher and listener.. Can someone point me in the right direction pls, google doesnt seem to help me out much on this one . Thanks in advance. Sam J edit: 04/04/2014 : This is the bundle im trying to create tests for I