/** * Given the argument value array, return the string * representation. This is used to generate argument list * for method expectations. * If one of the argument is an object, return ''. * * @param array $arguments * * @return string */ public function renderMockedMethodArguments($arguments) { $argArray = []; if ($this->util->isObjectIncluded($arguments)) { // We don't support objects in method expectation arguments yet. // @TODO (ryang 9/16/14) : support objects in method expectation // arguments. return ''; } foreach ($arguments as $arg) { // convert the scalar value to its string representation. $argArray[] = $this->varExporter->exportVariable($arg); } $argumentsString = implode(', ', $argArray); return $argumentsString; }
/** * @covers \Box\TestScribe\Utils\Util::appendStringIfNotEmpty * @covers \Box\TestScribe\Utils\Util */ public function testAppendStringIfNotEmpty_non_empty_text() { // Execute the method under test. $executionResult = Util::appendStringIfNotEmpty('a', 'b'); // Validate the execution result. $expected = 'ab'; $this->assertSame($expected, $executionResult, 'Variable ( executionResult ) doesn\'t have the expected value.'); }
/** * Generate statements for setting up the mocks of the objects * injected by the dependency management system. * * @return string */ public function renderObjectInjectionStatements() { $objectInjectionStatements = $this->injectedMockObjectsRenderer->genMockedObjectStatements(); $mockClassInjectionStatements = $this->injectedMockClassesRenderer->genMockedClassesStatements(); $combinedStatements = ArrayUtil::joinNonEmptyStringsWithNewLine([$objectInjectionStatements, $mockClassInjectionStatements], 2); $comment = "// Setup mocks injected by the dependency management system.\n\n"; $result = Util::appendStringIfNotEmpty($comment, $combinedStatements); return $result; }
/** * @param string $generated_message * @param string $message * @return void * @throws mixed exception type, specified in the constructor to the Assert instance. */ private function throw_exception($generated_message, $message) { $cls = $this->exception_class; $full_message = "{$message}\n{$generated_message}"; $arguments = array($full_message); $arguments = Util::array_join_values($this->exception_args, $arguments); $reflection = new \ReflectionClass($cls); /** @var $exception \Exception */ $exception = $reflection->newInstanceArgs($arguments); throw $exception; }