/** * @return \Box\TestScribe\Execution\ExecutionResult * * @throws \Box\TestScribe\Exception\AbortException * @throws \Exception */ public function runInstanceMethod() { // Even when the real constructor throws an exception, // the mocked object of the class under test is still needed // to generate the mock statements to cause the exception // to happen. $config = $this->globalComputedConfig; $className = $config->getFullClassName(); $methodName = $config->getMethodName(); $methodObj = $config->getInMethod(); $mockClassUnderTest = $this->mockClassLoader->createAndLoadMockClass($className, $methodName); $mockCreationResult = $this->classUnderTestMockCreator->createMockObjectForTheClassUnderTest($mockClassUnderTest); $constructorArgs = $mockCreationResult->getConstructorArgs(); $mockObj = $mockCreationResult->getMockObj(); $exceptionFromExecution = $mockCreationResult->getException(); if ($exceptionFromExecution === null) { $methodArgs = $this->argumentsCollector->collect($methodObj); $result = $this->expectedExceptionCatcher->execute([$this->reflectionUtil, 'invokeMethodRegardlessOfProtectionLevel'], [$mockObj, $methodObj, $methodArgs]); $exceptionFromExecution = $result->getException(); $executionResult = $result->getResult(); } else { $methodArgs = new Arguments([]); $executionResult = null; } $returnValue = new ExecutionResult($constructorArgs, $methodArgs, $mockClassUnderTest, $executionResult, $exceptionFromExecution); return $returnValue; }
/** * @param string $className * * @return \Box\TestScribe\Mock\MockClass */ public function createMockObject($className) { $mockClass = $this->mockClassLoader->createAndLoadMockClass($className, ''); // The fully mocked objects are assumed to have the original // constructors overwritten to not call the original constructors. // Thus the arguments to the original constructors are ignored. $mockObj = $this->mockObjectFactory->createMockObjectFromMockClass($mockClass, []); $mockClass->setMockedDynamicClassObj($mockObj); // Only show the mock message when full mocking is requested. // Since in most cases when partial mocking is not needed // the class under test won't be mocked. // Showing this message actually can cause confusion. $fullName = $mockClass->getClassNameBeingMocked(); $mockObjectName = $mockClass->getMockObjectName(); // @TODO (ryang 5/27/15) : display line number $msg = "Mocked ( {$fullName} ) id ( {$mockObjectName} ).\n"; $this->output->writeln($msg); return $mockClass; }