mockery

method does not exist on this mock object - Laravel , Mockery

巧了我就是萌 提交于 2019-12-07 15:05:18
问题 i'm trying to test a simple class. I'm following this tutorial( http://code.tutsplus.com/tutorials/testing-laravel-controllers--net-31456 ). I have this error, while running tests: Method Mockery_0_App_Interfaces_MealTypeRepositoryInterface::getValidator() does not exist on this mock object Im using repository structure. So, my controller calls repository and that returns Eloquent's response. I'm relatively new in php and laravel. And I've started learning to test a few days ago, so I'm sorry

mockery->shouldReceive() passing when it shouldnt?

被刻印的时光 ゝ 提交于 2019-12-07 05:17:19
问题 I am learning unit testing in laravel using phpunit and mockery. I am currently trying to test UsersController::store(). I am mocking User Model and using it to test the index method and that seems to work. When I take out $this->user->all() the test fails and when its in it passes. When testing the store method though I am using the mock to test that the user model receives validate() once. The store method is empty but the test passes. I have left out the irrelevant pieces of the class for

Laravel 5 - Using Mockery to mock Eloquent model

岁酱吖の 提交于 2019-12-06 09:36:01
Been looking all over the internet but don't seem to find an answer to my problem. I've been diving into testing controllers in Laravel using PHPUnit and Mockery. However, I don't seem to get my Eloquent based models mocked correctly. I did manage to mock my Auth::user() the same way, although this is not used in the test below. Function in AddressController that needs to be tested: public function edit($id) { $user = Auth::user(); $company = Company::where('kvk', $user->kvk)->first(); $address = Address::whereId($id)->first(); if(is_null($address)) { return abort(404); } return view('pages

method does not exist on this mock object - Laravel , Mockery

早过忘川 提交于 2019-12-05 18:36:01
i'm trying to test a simple class. I'm following this tutorial( http://code.tutsplus.com/tutorials/testing-laravel-controllers--net-31456 ). I have this error, while running tests: Method Mockery_0_App_Interfaces_MealTypeRepositoryInterface::getValidator() does not exist on this mock object Im using repository structure. So, my controller calls repository and that returns Eloquent's response. I'm relatively new in php and laravel. And I've started learning to test a few days ago, so I'm sorry for that messy code. My test case: class MealTypeControllerTest extends TestCase { public function

mockery->shouldReceive() passing when it shouldnt?

不羁岁月 提交于 2019-12-05 11:21:05
I am learning unit testing in laravel using phpunit and mockery. I am currently trying to test UsersController::store(). I am mocking User Model and using it to test the index method and that seems to work. When I take out $this->user->all() the test fails and when its in it passes. When testing the store method though I am using the mock to test that the user model receives validate() once. The store method is empty but the test passes. I have left out the irrelevant pieces of the class for brevities sake <?php class UsersController extends BaseController { public function __construct(User

Unittesting Laravel 5 Mail using Mock

让人想犯罪 __ 提交于 2019-12-05 11:05:30
Is there a way to test Mail in Laravel 5? tried the only legit Mock example I see on the internet but it seems it only works on Laravel 4. current code below. $mock = Mockery::mock('Swift_Mailer'); $this->app['mailer']->setSwiftMailer($mock); ...some more codes here... $mock->shouldReceive('send')->once() ->andReturnUsing(function($msg) { $this->assertEquals('My subject', $msg->getSubject()); $this->assertEquals('foo@bar.com', $msg->getTo()); $this->assertContains('Some string', $msg->getBody()); }); this is the contents of ApiClient.php, the last line is line 155, which is indicated in the

Mockery and Laravel constructor injection

馋奶兔 提交于 2019-12-05 10:20:22
I am using laravel 5 with php unit to create a laravel package. I have a Repository .. namespace Myname\Myapp\Repositories; use Myname\Myapp\Models\PersonModel; class PersonRepository { protected $personModel; public function __construct(PersonModel $personModel) { $this->personModel = $personModel; } public function testFunction($var) { return $this->personModel->find($var); } } ..which implements a Model . namespace Myname\Myapp\Models; use Illuminate\Database\Eloquent\Model; class PersonModel extends Model { protected $table = 'person'; } Laravels IoC automatically injects PersonModel into

Error when mocking interfaces in PHP using Mockery

拈花ヽ惹草 提交于 2019-12-05 04:17:27
I have run into a problem when mocking Interfaces using Mockery in PHP (im using the laravel framework but I'm not sure this is relevant. I have defined an interface <?php namespace MyNamespace\SomeSubFolder; interface MyInterface { public function method1(); } And I have a class that typehints that interface on one of the methods... <?php namespace MyNamespace\SomeSubFolder; use MyNamespace\SomeSubFolder\MyInterface; class MyClass { public function execute(MyInterface $interface) { //does some stuff here } } ...and I am trying to test MyClass. I have created a test that looks something like

Mocking a call with chained methods and arguments

蹲街弑〆低调 提交于 2019-12-03 21:17:55
问题 Im learning how to use mockery in order to run some unit test and Im not sure what to do to mock my database class. It consists of separate methods that can be chained like these two examples: $db->select('someTblName',['fieldName']) ->where('fieldName', 'someValue') ->runQuery() ->fetch(); //returns array or null Another use could be like: $db->select('someTblName') ->where('fieldName', 'someValue') ->where('fieldName', array('>=' , 'someValue') ->runQuery() ->fetch(); //returns array or

What is the difference between overload and alias in Mockery?

三世轮回 提交于 2019-12-03 15:07:52
I am new to using Mockery and confused with the terminology alias and overload . Can anyone please explain to me when to use which? Overload is used to create an "instance mock". This will "intercept" when a new instance of a class is created and the mock will be used instead. For example if this code is to be tested: class ClassToTest { public function methodToTest() { $myClass = new MyClass(); $result = $myClass->someMethod(); return $result; } } You would create an instance mock using overload and define the expectations like this: public function testMethodToTest() { $mock = Mockery::mock(