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
6
votes
4 answers

How to Str::shouldReceive? (mocking Illuminate\Support\Str)

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 exist. I also tried to mock the class directly and…
toonevdb
  • 329
  • 1
  • 13
6
votes
1 answer

How can I specify Partial Mockup for a Laravel Facade?

First I tried this $mock = m::mock('Cartalyst\Sentry\Facades\Laravel\Sentry'); $mock->shouldReceive('getUser')->once()->andReturn($userInst); But it gave me Fatal error: Cannot redeclare…
user391986
  • 29,536
  • 39
  • 126
  • 205
6
votes
1 answer

Mocking callbacks in Laravel 4 (Mockery)

I'm currently writing tests for a package in Laravel 4. I am mocking the Illuminate\Database\Query\Builder which works nearly all the time except when a where method uses a callback, I cannot check if the methods inside the callback are called. I…
SamV
  • 7,548
  • 4
  • 39
  • 50
5
votes
1 answer

Carbon object in mockery php test

Thank you for your time. I have stripped out the fluff from the code/test. The furthest I have got with this is that setAttribute requires two strings as param´s, but i am passing in an Carbon object, which Mockery as a test suite does not like? Is…
Jeremy
  • 1,170
  • 9
  • 26
5
votes
1 answer

Golang mock context panic

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{} func init() { lis = bufconn.Listen(bufSize) s…
5
votes
2 answers

Laravel: how to mock dependency injection class methods

I'm using the GitHub API through a Laravel API Wrapper. I've created a dependency injection class. How can I mock the exists method within the App\Http\GitHub.php class? App\Http\GitHub.php: use GrahamCampbell\GitHub\GitHubManager; class Github { …
ahinkle
  • 2,117
  • 3
  • 29
  • 58
5
votes
1 answer

makePartial() returns Mockery\Exception\BadMethodCallException : Method does not exist on this mock object

I'm trying to test my Category class. I'm using Mockery::mock() method, with 'overload:' prefix and makePartial() method. When running test I have this error: Mockery\Exception\BadMethodCallException : Method…
Marshall
  • 65
  • 1
  • 6
5
votes
1 answer

Symfony 4 mock private services

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: public function testFetchingNewApps(FunctionalTester…
Bogdan Dubyk
  • 4,756
  • 7
  • 30
  • 67
5
votes
1 answer

Mockery Overload - Abstract Class

I'm fairly new to TDD and I'm currently writing tests in a Laravel project and I'm using the Mockery library. I've encountered an issue when trying to mock overload a new class instance. The problem seems to be that the mocked class loses its…
5
votes
2 answers

How to mock properly Illuminate\Http\Request class from Laravel

I'm trying to test a method from a class which contains a method using the request() helper from Laravel. This is the method: Category class public function getCanonicalUrl() { return preg_match('/\/sale\/./', request()->getRequestUri()) …
therealbigpepe
  • 1,489
  • 2
  • 16
  • 23
5
votes
1 answer

Mocking trait methods with mockery

I have a trait: trait A { function foo() { ... } } and a class that uses the trait like this: class B { use A { foo as traitFoo; } function foo() { $intermediate = $this->traitFoo(); ... …
Gonçalo Marrafa
  • 2,013
  • 4
  • 27
  • 34
5
votes
1 answer

Error using Mockery/phpUnit in Laravel

I'm a novice developer trying to get a test suite started for an existing laravel app but I have not experience in testing. Right now I'm just trying to get some tests built out to get some confidence and experience to write more substantial tests.…
brianfr82
  • 271
  • 1
  • 5
  • 19
5
votes
2 answers

how do I mock the DB facade in laravel?

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 this function: public function GetPassword($email) { …
Daniel Angel
  • 489
  • 1
  • 6
  • 14
5
votes
1 answer

Update mockery's andReturn

Can I somehow update shouldReturn value for specific shouldReceive? For example I have several tests that have use one return value, and only one that uses some other return value. So I have put this in…
Ivan Toncev
  • 532
  • 5
  • 15
5
votes
1 answer

How to mockery mock internal method

Target.php getData(); return true; } public function getData() { return array(); } } TargetTest.php
Chan
  • 1,947
  • 6
  • 25
  • 37