protected function setUpMocks() { $this->reflector_mock = TestFactory::mockClassReflector(); $this->files_mock = TestFactory::mockFilesystem(); $this->class_name_getter_mock = TestFactory::mockGetClassName(); $this->reflection_class_mock = TestFactory::mockReflectionClass(); $this->reflection_method_mock = TestFactory::mockReflectionMethod(); }
protected function setUpMocks() { $this->decipher_mock = TestFactory::mockDecipherDocBlock(); $this->decipher_mock->shouldReceive('process')->withAnyArgs()->andReturn('Results from DecipherDocBlock'); $this->reflection_mock = TestFactory::mockReflectionClass(); $this->reflection_mock->shouldReceive('getMethods')->withAnyArgs()->andReturn([TestFactory::makeClass(['class' => 'Some\\Namespace\\SomeClass', 'name' => '__constructor'], ['getDocComment' => '/** Comment */']), TestFactory::makeClass(['class' => 'Some\\Namespace\\SomeClass', 'name' => 'MethodOne'], ['getDocComment' => '/** Comment */']), TestFactory::makeClass(['class' => 'Some\\Namespace\\ParentClass', 'name' => 'BaseMethod'], ['getDocComment' => '/** Comment */'])]); $this->reflection_mock->shouldReceive('getShortName')->withNoArgs()->andReturn('SomeClass'); $this->reflector_mock = TestFactory::mockClassReflector(); $this->reflector_mock->shouldReceive('reflect')->withAnyArgs()->andReturn($this->reflection_mock); $this->class_name_getter_mock = TestFactory::mockGetClassName(); }
/** * @test */ public function it_returns_the_expected_results() { $expected = ['getArray', 'getObject', 'getString']; // Just does not have "get" in it $methodThatIsNotAGetter = TestFactory::mockReflectionMethod(); $methodThatIsNotAGetter->shouldReceive('getName')->withNoArgs()->andReturn('methodThatIsNotAGetter')->once(); // Has "get" in the middle of the method name $forgetMethod = TestFactory::mockReflectionMethod(); $forgetMethod->shouldReceive('getName')->withNoArgs()->andReturn('forgetMethod')->once(); // Letter after "get" is not caps $getter = TestFactory::mockReflectionMethod(); $getter->shouldReceive('getName')->withNoArgs()->andReturn('getter')->once(); $getArray = TestFactory::mockReflectionMethod(); $getArray->shouldReceive('getName')->withNoArgs()->andReturn('getArray')->once(); $getObject = TestFactory::mockReflectionMethod(); $getObject->shouldReceive('getName')->withNoArgs()->andReturn('getObject')->once(); $getString = TestFactory::mockReflectionMethod(); $getString->shouldReceive('getName')->withNoArgs()->andReturn('getString')->once(); $reflection_mock = TestFactory::mockReflectionClass(); $reflection_mock->shouldReceive('getMethods')->with(ReflectionMethod::IS_PUBLIC)->andReturn([$methodThatIsNotAGetter, $forgetMethod, $getter, $getArray, $getObject, $getString])->once(); $this->reflecter_mock->shouldReceive('reflect')->with('SomeResultClass')->andReturn($reflection_mock)->once(); $response = $this->getter->process('SomeResultClass'); $this->assertEquals($expected, $response); }