Category : mockery

I have model method public static function getDetails( array $fields, array $where_condition ) { return Event::select($fields) ->where($where_condition)->first(); } I am calling this method like this $logo = Event::getDetails( [‘logo’], [‘id’ => $id] )->logo; so what I tried to mock method in below way but not working $mock = $this->mock(Event::class, function (MockInterface $mock) { $collection = ..

Read more

I’m trying to use overload option of Mockery library on Laravel 5. I write this test case: <?php namespace TestsUnit; use Mockery; use TestsTestCase; /** * @runTestsInSeparateProcesses * @preserveGlobalState disabled */ class RenewSignatureTest extends TestCase { public function testHandle() { /** @var mixed $mock */ $mock = Mockery::mock(‘overload:AppFooClass’); $mock->shouldReceive(‘callBar’)->times(2); } } According to documentation, this ..

Read more

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’) ->withSomeOfArgs(1); $mock->getById(1); } ! get by id→ This test did not perform any assertions testsUnitPostControllerTest.php:30 Tests: 1 risked Time: 0.32s Warning: TTY mode is not ..

Read more

I’m trying to mock a function that will be called by another one. example class TestClass { private static function foo(){ return false } public static function bar() { return self::foo() } } I tried like this $TestClassMock = Mockery::mock(TestClass::class)->shouldAllowMockingProtectedMethods()->makePartial(); $TestClassMock->shouldReceive(‘foo’)->andReturnTrue(); $this->assertEqual($TestClassMock::bar(),true); But it doesn’t work the function is not moocked yet if I use ..

Read more

I mocked the laravel DB facade and my assert passed but mockery complains you didn’t assert DatabaseManager::connection() which i don’t need. DB::partialMock()->shouldReceive(‘table->where->first’)->andReturn((object) [ ‘id’ => 2, ‘name’ => ‘Alex’ ]); But i’ll got this : MockeryExceptionBadMethodCallException : Received Mockery_1_Illuminate_Database_DatabaseManager::connection(), but no expectations were specified Sourc..

Read more

I have the following middleware to update the user’s last_seen_at field and I’ve used it only for routes that an authenticated user can call it: // app/Http/Middleware/LastSeen.php public function handle($request, Closure $next) { $user = $request->user(); $user->last_seen_at = now(); $user->save(); return $next($request); } // app/Http/Kernel.php protected $routeMiddleware = [ // other middleware ‘lastseen’ => AppHttpMiddlewareLastSeen::class ..

Read more

I have run into an issue where when I try to mock a model that’s used in a static method of some class AND I have an instance of the model being referenced in a repository service provider, Mockery will always error: Could not load mock AppRepositoriesOrganisationContactsEloquentOrganisationContact, class already exists I spent a couple hours ..

Read more

Hello I’m trying to mock a query like this with mockery but I’m not sure how to mock the anonymous function parts: // $this->stores is a IlluminateDatabaseEloquentModel $this->stores->where(‘a’, $a) ->when($b, function ($q) use ($title) { return $query->where(‘title’, $title); }) ->when($name, function ($q) use ($name) { return $query->where(‘name’, $name); }) ->orderBy(‘date’) ->orderBy(‘name’) ->get(); My mock for ..

Read more

Here is my situation. I have this test UpdateAdditionalCommandHandlerTest which is a test for UpdateAdditionalCommandHandler And here is the code: class UpdateAdditionalCommandHandler implements CommandHandler { use DispatchableTrait; use ValidationCommandBus; /** * @var AdditionalRepository */ protected $repository; /** * @param AdditionalRepository $repository */ public function __construct(AdditionalRepository $repository) { $this->repository = $repository; } /** * @param UpdateAdditionalCommand ..

Read more

I am developing a system using Laravel 7.28.4 In the system I have created a SMSService to be able to send SMS message, below is the SMSService code https://codeshare.io/aYjDRM as the code above contains code from configuration i attached the source for the config staticdata file and the .env file https://codeshare.io/5N8lgm https://codeshare.io/aVLAB4 i also attached ..

Read more

I have this class: <?php namespace AppHttpControllersAlerts; use AppHttpControllersController; use AppModelsAlert; use AppModelsFiredAlert; use AppModelsUnitReport; use AppNotificationsAlertSetup; use CarbonCarbon; use IlluminateHttpRequest; use IlluminateSupportFacadesNotification; class AlertController extends Controller { /** * @param Alert $alert * @param null $schema */ public static function checkForInactivity(Alert $alert, $schema = null): void { …some code… } /** * Get int ..

Read more

I want to test that the Auth facade, when createUserProivder() method is called, returns my user provider. The problem is that with the following code, with the commented out part, the AuthManager is still the original, not the mock. With the uncommented part, I get an error: MockeryExceptionBadMethodCallException : Method Mockery_2_Illuminate_Auth_AuthManager::validate() does not exist on ..

Read more

Basically I want to test that when I call a method 2 times another method is called once but I get the following Exception: MockeryExceptionBadMethodCallException : Received Mockery_0_App_Repository_DimensionRepository::getThinClientDimension(), but no expectations were specified My test is as follows class HostRepositoryTest extends TestCase { /** * @var HostRepository */ private $hostRepository; /** * @var Dimension */ ..

Read more