techguy92 left a reply on Function Used By __construct($val) Not Being Mocked
I'm going to make a test Object that extends the original object to test the other functions, by prepopulate the origin data.
I'm new to Testing and mocking. I need help on how to mock particular functions in my __construct class for one of my objects. These functions pull data from a database and return values to populate object properties.
Here is what I have
$testResponse = (object)[ 'name' => 'LISD TEST Event', 'description' => 'LISD Test Event', 'beginDate' => '2018-05-04', 'orgCode' => '014', ]; $event = Mockery::mock(Event::class, [self::TEST_EVENT_ID])->makePartial(); $event->shouldAllowMockingProtectedMethods(); $event->shouldReceive('getCampusName') ->with('014') ->atLeast(1) ->andReturn('LHS Harmon'); $event->shouldReceive('getEventInformation') ->with(self::TEST_EVENT_ID) ->atLeast(1) ->andReturn($testObject);
But instead of mocking the functions, I get the data from the database and not the data from my $testResponse. Am I doing this all wrong or what am I missing to get this to retrieve the data from the mocked functions instead of the pulling from the actual database