/** * @covers \Box\TestScribe\_fixture\_input\StaticCalculatorViaLocator::calculateWithACalculator * @covers \Box\TestScribe\_fixture\_input\StaticCalculatorViaLocator */ public function test_calculateWithACalculator() { // Setup mocks injected by the dependency management system. /** @var \Box\TestScribe\_fixture\_input\StaticCalculator $mockStaticCalculator */ $mockStaticCalculator = $this->shmock_class('\\Box\\TestScribe\\_fixture\\_input\\StaticCalculator', function ($shmock) { $shmock->order_matters(); /** @var $mock \Shmock\Spec */ $mock = $shmock->add(1, 2); $mock->return_value(3); }); \Box\TestScribe\_fixture\StaticServiceLocator::overwrite('\\Box\\TestScribe\\_fixture\\_input\\StaticCalculator', $mockStaticCalculator); // Execute the method under test. $objectUnderTest = new \Box\TestScribe\_fixture\_input\StaticCalculatorViaLocator(); $executionResult = $objectUnderTest->calculateWithACalculator(1, 2); // Validate the execution result. $expected = 3; $this->assertSame($expected, $executionResult, 'Variable ( executionResult ) doesn\'t have the expected value.'); }
/** * Used for testing service locator usage using a service locator for static invocations. * * @param int $value1 * @param int $value2 * * @return int */ public function calculateWithACalculator($value1, $value2) { $calc = StaticServiceLocator::resolve('\\Box\\TestScribe\\_fixture\\_input\\StaticCalculator'); $rc = $calc::add($value1, $value2); return $rc; }