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
0
votes
1 answer

PHP Mockery not returning mocked object from mocked function

I'm setting up some unit tests for a class that uses Predis to connect to a Redis DB. I'm trying to mock the Client and Connection objects so that I can do the unit test. This is the section of my class that deals with the Predis Client…
Sean Hagen
  • 752
  • 10
  • 30
0
votes
1 answer

Using PHPSpec with array?

I've been starting to use PHPSpec 2, and am loving it with Mockery, but ran into an issue I can't figure out. I have an array returned by a static function, and I want to validate this array. Make sure all the keys needed are there, etc. I…
Jess
  • 8,628
  • 6
  • 49
  • 67
0
votes
1 answer

Laravel Mockery Integration Test

I am a little lost on how to perform integration test using mockery. I have the following classes: TeacherController TeacherManager - Interface TeacherManagerImpl - Implementation When it comes to mockery / PHPUnit, how do I call a method from my…
Trevor
  • 363
  • 7
  • 20
0
votes
2 answers

Using Hamcrest's hasKeyValuePair with laravel's unit test

I have the following test: public function testTestNameRequired(){ Validator::shouldReceive("make")->once() ->with(array(1,2,3), hasKeyValuePair("name",array("required"))) ->andReturn(m::mock(["passes"=>true])); $r =…
jasonlfunk
  • 5,159
  • 4
  • 29
  • 39
0
votes
1 answer

Is there a better way to write this test?

I'm fairly new to unit testing with Laravel and Mockery and I wrote the following test. It passes and seems to work. However, I think that it's probably could be written in a better way. It seems that the test is more likely to break than the…
jasonlfunk
  • 5,159
  • 4
  • 29
  • 39
0
votes
1 answer

How to pass JSON to route from unit test?

I am unit testing my Laravel 4 Controller by mocking my repository that the controller expects. The problem is with the "store" function. This is the function that is called by Laravel when I do a POST to the given controller. The function gets…
Thelonias
  • 2,918
  • 3
  • 29
  • 63
0
votes
1 answer

Testing __call method

public function __call($method, $args) { if ( ! in_array($method, $this->validMethods)) { throw new \BadMethodCallException("Not a valid method: {$method}"); } } How do I test the __call method to make sure $method is in my list…
Jürgen Paul
  • 14,299
  • 26
  • 93
  • 133
0
votes
2 answers

Mockery - creating a mock in the constructor

Is there a way to create a mock in the test class constructor/class setUp function such that the mock is available to all test methods? I have tried creating in the constructor like: public class testMocks extends PHPUnit_Framework_TestCase { …
BIOS
  • 1,655
  • 5
  • 20
  • 36
0
votes
1 answer

Using pear with PHPUnit, eclipse sees PHPUnit but not Mockery

I have installed Pear and used Pear to install PHPUnit and Mockery. I have PHPUnit running successfully in elipse (the pear directory is configured as an include path in the project). I would like to use Mockery but eclipse keeps giving me this…
dorothy Dorothy
  • 309
  • 2
  • 7
0
votes
0 answers

Using mockery, how do you make a method on mock expect a specific DateTime object

I built some functionality around laravel 4's query builder, and to test out a certain part, i need to do something like this: $dateTimeObject = new DateTime; // some other stuff with this object $q->shouldReceive('where')->once()->with('baz', '>=',…
kapv89
  • 1,692
  • 1
  • 17
  • 20
-1
votes
1 answer

Why I am unable to assert that method has been called on my mocked service?

I have made a simple class named MyService namespace App\Services; class MyService { private $anotherService; public function setService(AnotherService $anotherService) { $this->anotherService = $anotherService; } …
Dimitrios Desyllas
  • 9,082
  • 15
  • 74
  • 164
-1
votes
1 answer

PHPUnit/Mockery - Partially mock a function

Say i have this function. In this function i create a Mollie payment using the Mollie Laravel API Wrapper. The function $molliePayment needs to be mocked as i don't want to call the API during testing. How can i achieve this? public static function…
jadsghx
  • 3
  • 3
-1
votes
1 answer

How to create phpunit testcase for file upload functionality in laravel

Controller.php public function uploadDocument($request,$profileId) { $s3Bucket = 's3.' . $request->input('fileType'); $file = $request->file('document'); $name = $file->hashName(); } Testcase.php use Illuminate\Http\Request; use…
RBC
  • 478
  • 1
  • 3
  • 12
-1
votes
2 answers

Mocking laravel DB facades when method using mockery/mockery

I am using mockery/mockery to mock laravel db facade on my unit test. But I don't know how to create a stub for the when method. So here is my class that I want to test.
KevDev
  • 541
  • 2
  • 6
  • 20
-1
votes
1 answer

Error:Call to a member function create() on null , unit test (Mockery)

I'm trying to unit test "AdminService" class that has "create()" method and in the constructor I need a dependency which is AdminRepository. I used mockery to mock the repository and passed this mock to AdminService _contsruct() but i got and…
Lama Sonmez
  • 93
  • 1
  • 16
1 2 3
35
36