Questions tagged [mockery]

Mockery is a PHP library used to create Mocks of Objects for testing purpose.

Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succint API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL).

https://github.com/padraic/mockery

529 questions
4
votes
1 answer

PHPUnit method call expectations vs. assertions

Creating mock classes usually involves configuring method call expectations on the mocks/test doubles. E.g. in 'vanilla' PHPUnit we can stub a method call and set an expectations like…
luqo33
  • 8,001
  • 16
  • 54
  • 107
4
votes
1 answer

In Laravel, mocking an eloquent query on a model

I'm stuck on Laravel 4.2 for now (with phpunit and mockery) but the same should apply to later versions. I have a Repository for my FxRate model. It has a method to get an FX rate vs GBP which contains this eloquent call: $query =…
harryg
  • 23,311
  • 45
  • 125
  • 198
4
votes
1 answer

Laravel 5 mock PasswordBroker

From the boilerplate PasswordController::postEmail() I'm trying to mock (using Mockery) this part: // $this->password is an instance of PasswordBroker $response = $this->passwords->sendResetLink($request->only('email'), function($m) { …
Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206
4
votes
1 answer

How to test routes in Laravel 5, or Trying to "MockStub" something, or I have no idea of TDD

I'm starting with TDD and Laravel. Specifically, I'm starting with routes. I defined some and I defined it badly, so excited as I was with the "new" concept of TDD I wanted to write some test for them. The idea was to test the routes and only the…
Alvaro Maceda
  • 604
  • 1
  • 7
  • 21
4
votes
1 answer

Setting attributes on models while testing

I am trying to test a controller and am mocking the models. All seems to go well until the view is loaded, it's unable to retrieve properties on that view that are supposed to be loaded via relationships. I've tried setting those properties using…
user1669496
  • 32,176
  • 9
  • 73
  • 65
4
votes
1 answer

What's the proper approach to testing controllers in Laravel?

I'm rewriting an existing Laravel 4 application to ensure that there is adequate testing. Long story short, I've rewritten my AccountController class using TDD methods and I'm running into a bit of a headache. Consider the following method that…
Kryten
  • 15,230
  • 6
  • 45
  • 68
4
votes
3 answers

Mocking method with callback param

I am trying to mock this method: $transformer = $this->transformerFactory->createProductTransformer($product, function (ProductInterface $product) use ($discount) { $product->setDiscount($discount); }); It accepts callback parameter as a second…
acid
  • 2,099
  • 4
  • 28
  • 41
4
votes
1 answer

Mocking Static Eloquent Models Methods including find()

I've been following the general Mockery and PHP-Unit tutorials - including Jeffrey Way's introduction to testing Laravel with PHP-Unit and Mockery. However, for this app - we're fine with a dependency on Eloquent, and would rather not create a…
Blue Waters
  • 725
  • 1
  • 4
  • 17
4
votes
0 answers

How to actually run PHPUnit tests in a specific order

This question: Run PHPUnit Tests in Certain Order has an accepted answer which I agree with, but the design problem is with PHP and PHPUnit. The project I'm testing uses ZF2 and Doctrine. The AbstractHttpControllerTestCase has a method "dispatch"…
user168660
  • 41
  • 2
3
votes
1 answer

Writing Tests in Go by Receiving Interfaces and Returning Structs

I'm having some issues implementing interface substitution for the Go code. Previously the code was not written with unit tests in mind and I am going back and adding support for testing (Testify and Mockery) and writing all of the Go tests for my…
3
votes
1 answer

mockery::mock and mockery::stub do not work properly with quasiquotation?

I've written an import function that gets a single file from an aws s3-bucket. That function itself is a wrapper around aws.s3::s3read_using() which takes a reading function as its first argument. Why do I wrap around aws.s3::s3read_using() ?…
y3kMyRon
  • 71
  • 7
3
votes
2 answers

Laravel Mockery - This test did not perform any assertions

I am trying to create a mockery unit test but it giving me this error This test did not perform any assertions public function testGetById() { $mock = Mockery::mock(PostService::class)->makePartial(); $mock->shouldReceive('getById') …
Tala Naji
  • 31
  • 1
  • 2
3
votes
1 answer

How to mock laravel helper function request

How do you mock the request() helper function? For example if I have a function that makes a call $name = request()->input('name') How do mock that call, I have tried the following but I get an error that it was never called $requestMock =…
Scot
  • 59
  • 7
3
votes
1 answer

Mocking laravel cache helper

Using the PESTPHP testing framework, I want to mock Laravel's cache helper but when I try it, I get an error like this: Method Mockery_2_Illuminate_Cache_CacheManager::remember() does not exist on this mock object` I want to mock the…
3
votes
1 answer

How to mock httpclient using mockery

I am trying to use Mockery to mock a Http client, but when I try to pass in the return value I get an error saying type http.Response is not an expression Below is my interface and handler type HTTPClient interface { Get(url string) (resp…
user6248190
  • 1,233
  • 2
  • 16
  • 31