/** * @covers \Box\TestScribe\_fixture\_input\PartialMockingExample::calc * @covers \Box\TestScribe\_fixture\_input\PartialMockingExample */ public function test_calc() { // Setup mocks injected by the dependency management system. /** @var \Box\TestScribe\_fixture\_input\Logger $mockLogger */ $mockLogger = $this->shmock('\\Box\\TestScribe\\_fixture\\_input\\Logger', function ($shmock) { $shmock->order_matters(); $shmock->disable_original_constructor(); $shmock->log('internal calc called'); }); \Box\TestScribe\_fixture\ServiceLocator::overwrite('\\Box\\TestScribe\\_fixture\\_input\\Logger', $mockLogger); // Execute the method under test. /** @var \Box\TestScribe\_fixture\_input\PartialMockingExample $mockPartialMockingExample */ $mockPartialMockingExample = $this->shmock('\\Box\\TestScribe\\_fixture\\_input\\PartialMockingExample', function ($shmock) { $shmock->order_matters(); // Setup mocks for parameters to the constructor. /** @var \Box\TestScribe\_fixture\_input\CalculatorFactory $mockCalculatorFactory */ $mockCalculatorFactory = $this->shmock('\\Box\\TestScribe\\_fixture\\_input\\CalculatorFactory', function ($shmock) { $shmock->order_matters(); $shmock->disable_original_constructor(); }); $shmock->set_constructor_arguments($mockCalculatorFactory); /** @var $mock \Shmock\Spec */ $mock = $shmock->internalCalc(); $mock->return_value(3); }); $executionResult = $mockPartialMockingExample->calc(); // Validate the execution result. $expected = 4; $this->assertSame($expected, $executionResult, 'Variable ( executionResult ) doesn\'t have the expected value.'); }
/** * @covers \Box\TestScribe\_fixture\_input\CalculatorViaLocator::calculateWithACalculator * @covers \Box\TestScribe\_fixture\_input\CalculatorViaLocator */ public function test_calculateWithACalculator() { // Setup mocks injected by the dependency management system. /** @var \Box\TestScribe\_fixture\_input\CalculatorWithState $mockCalculatorWithState */ $mockCalculatorWithState = $this->shmock('\\Box\\TestScribe\\_fixture\\_input\\CalculatorWithState', function ($shmock) { $shmock->order_matters(); $shmock->disable_original_constructor(); /** @var $mock \Shmock\Spec */ $mock = $shmock->add(2); $mock->return_value(3); }); \Box\TestScribe\_fixture\ServiceLocator::overwrite('\\Box\\TestScribe\\_fixture\\_input\\CalculatorWithState', $mockCalculatorWithState); // Execute the method under test. $objectUnderTest = new \Box\TestScribe\_fixture\_input\CalculatorViaLocator(); $executionResult = $objectUnderTest->calculateWithACalculator(2); // Validate the execution result. $expected = 3; $this->assertSame($expected, $executionResult, 'Variable ( executionResult ) doesn\'t have the expected value.'); }
/** * @param \Box\TestScribe\_fixture\_input\CalculatorFactory $factory */ function __construct(CalculatorFactory $factory) { $this->factory = $factory; $this->logger = ServiceLocator::resolve('\\Box\\TestScribe\\_fixture\\_input\\Logger'); }
/** * Used for testing service locator usage. * * @param int $additionalValue * * @return int */ public function calculateWithACalculator($additionalValue) { $calc = ServiceLocator::resolve('\\Box\\TestScribe\\_fixture\\_input\\CalculatorWithState', [1]); $rc = $calc->add($additionalValue); return $rc; }