mockery Questions

2

Solved

I need to test how some code I wrote will behave when it calls a method on another class multiple times, where one of the calls will cause an exception to be thrown. I am using Mockery to mock the...
Cymbal asked 17/6, 2018 at 22:5

6

Solved

I have an application that makes use of socialite, I want to create test for Github authentication, So I used Socialite Facade to mock call to the Socialite driver method, but when I run my test it...
Ergocalciferol asked 9/2, 2016 at 14:13

3

Solved

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 { protecte...
Ioyal asked 19/4, 2016 at 15:54

4

I have a class that uses Str::random() which I would like to test. But when I use Str::shouldReceive('random') in my test, I get a BadMethodCallException saying the method shouldReceive does not e...
Specialistic asked 28/6, 2014 at 21:39

5

Solved

I'm trying to properly mock a chained call to an Eloquent model in a controller. In my controller I'm using dependancy injection to access the model so that it should be easy to mock, however I'm n...
Caenogenesis asked 13/2, 2014 at 1:26

3

I need to test, that the code creates a new instance of a class with certain parameters: $bar = new ProgressBar($output, $size); I tried to create an alias mock and set an expectation for the __...
Undershoot asked 1/6, 2015 at 13:42

2

Solved

I'm writing my unit tests and by default they should not hit the database. by general rule I always use eloquent to get the results, but some more complex queries I have to use the raw DB I have ...
Condemn asked 25/1, 2016 at 20:37

3

Solved

I am new to using Mockery and confused with the terminology alias and overload. Can anyone please explain to me when to use which?
Eanes asked 4/7, 2015 at 10:25

9

I want to use a mock object (Mockery) in my PHPUnit test. The mock object needs to have both some public methods and some public properties set. The class is a Laravel Eloquent model. I tried this:...
Zabrina asked 7/4, 2014 at 10:0

3

Solved

I'm trying to get Mockery to assert that a given method is called at least once. My test class is: use \Mockery as m; class MyTest extends \PHPUnit_Framework_TestCase { public function testSet...
Hugh asked 16/4, 2013 at 11:11

2

Solved

Consider the example classes (apologies for it being so convoluted, but it's as slim as possible): class RecordLookup { private $records = [ 13 => 'foo', 42 => 'bar', ]; function __con...
Jamille asked 28/4, 2015 at 11:13

2

Solved

I'm looking for a way to mock an object and populate its properties. Here's an example of a method who uses a property of another object: class MyClass { private $_object; public function meth...
Bozovich asked 15/6, 2017 at 15:7

4

Solved

I have the following code in one of my routes: return Response::download('cv.pdf'); Any idea how to test this? I've tried to use shouldReceive() but that doesn't seem to work ('shouldReceive() un...
Millepore asked 13/1, 2014 at 12:19

1

This should be incredibly simple but it is driving me mad this afternoon, what is the correct way to unit test a custom symfony validator? All the articles I can find have exactly the same way as I...
Rusert asked 18/8, 2020 at 16:55

1

Solved

So I'm making unit test in golang using mockery and testify The test code goes like this: const bufSize = 1024 * 1024 var lis *bufconn.Listener var mockAccountService = &mocks.AccountService{...
Antabuse asked 2/7, 2020 at 11:52

2

Solved

I'm using PHPUnit 6.5.13 and Laravel 5.5 on PHP 7.4. I recently upgraded from PHP 7.2 to 7.4. and it seems like that triggered the error. In my test I use $this->expectsEvents in order to test...
Romeyn asked 16/12, 2019 at 13:59

2

Solved

I can't figure out why I'm getting this error during this test. My test appears to be matching the rest of the code exactly. What am I overlooking? In my test I have: $passwordBroker = m::mock('...
Fancied asked 8/4, 2014 at 19:20

2

Solved

I've been successfully using Mockery with PHPUnit tests lately. Yet, there is a dependency in a project I'm currently working that uses static method calls to interact with an API. I'm struggling t...
Anele asked 29/3, 2019 at 18:48

1

Solved

I have this Service class and use repository class in my Service : class VisitorStatisticAction { protected $repository; public function __construct(VisitorStatisticRepository $repository) { ...
Longdrawnout asked 12/3, 2019 at 8:29

2

Solved

TLDR; How do I get value1 first time and value2 the second time when calling the mockery shouldReceive('method)` with same parameter? Lets say I have an $order object that implements this signatur...
Jenjena asked 6/3, 2019 at 15:52

1

Trying to write a test for laravel php artisan command with ask() function. I have never used mockery before, but when i try to run test, it freezes, so i guess, i'm doing something wrong. MyComman...
Huron asked 9/5, 2018 at 13:24

1

Solved

I have appplication which responsible to fetch various api's to collect data. I'm using Codeception As my testing framework and I need to mock API client class in my functional tests like this: p...
Lei asked 5/11, 2018 at 19:24

1

In my application code, I've got a method_exists check to authorize some hooking in a create process: // Note: $myClass is implementing a ListItemFactory interface. if ($isCreate) { $methodName ...
Thumbscrew asked 22/11, 2015 at 15:3

1

Solved

I have situation like this. I have some 3rd party trait (I don't want to test) and I have my trait that uses this trait and in some case runs 3rd party trait method (in below example I always run i...
Vietcong asked 4/8, 2018 at 8:45

3

Solved

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...
Burthen asked 29/6, 2015 at 16:12

© 2022 - 2024 — McMap. All rights reserved.