/** * @covers Housekeeper\Eloquent\BaseRepository::inject * @covers Housekeeper\Eloquent\BaseRepository::sortAllInjections * @covers Housekeeper\Eloquent\BaseRepository::sortInjection */ public function testInjectAfterFlow() { $mockRepository = $this->makeMockRepository(); /** * Mock an injection that implements AfterInjectionInterface. */ $afterInjection = m::mock(InjectionInterface::class, AfterInjectionInterface::class); $afterInjection->shouldReceive('priority')->andReturn(1); /** * Call "inject" function, this injection should goes to "after" * injections. */ $methodInject = getUnaccessibleObjectMethod($mockRepository, 'inject'); $methodInject->invoke($mockRepository, $afterInjection); /** * Get all injections and check them. */ $injections = getUnaccessibleObjectPropertyValue($mockRepository, 'injections'); $this->assertCount(1, $injections['after']); $this->assertEquals($afterInjection, $injections['after'][0]); }
/** * @runInSeparateProcess * @covers Housekeeper\Repository::newPlan */ public function testNewPlanWhenDoNotHaveDefault() { $mockRepository = $this->makeMockRepository(MockSetupRepository::class, false); setUnaccessibleObjectPropertyValue($mockRepository, 'defaultPlan', null); setUnaccessibleObjectPropertyValue($mockRepository, 'plans', [1]); setUnaccessibleObjectPropertyValue($mockRepository, 'planStep', 0); $methodNewPlan = getUnaccessibleObjectMethod($mockRepository, 'newPlan'); $offset = $methodNewPlan->invoke($mockRepository); $propertyPlanStep = getUnaccessibleObjectPropertyValue($mockRepository, 'planStep'); $propertyPlans = getUnaccessibleObjectPropertyValue($mockRepository, 'plans'); $this->assertEquals(1, $offset); $this->assertEquals(1, $propertyPlanStep); $this->assertCount(2, $propertyPlans); $plan = $propertyPlans[1]; $this->assertInstanceOf(\Housekeeper\Plan::class, $plan); }