Mockery\Mock::shouldReceive PHP Method

shouldReceive() public method

Set expected method calls
public shouldReceive ( $methodName ) : Expectation
return Expectation
    public function shouldReceive($methodName)
    {
        if (func_num_args() < 1) {
            throw new \InvalidArgumentException("At least one method name is required");
        }
        foreach (func_get_args() as $method) {
            if ("" == $method) {
                throw new \InvalidArgumentException("Received empty method name");
            }
        }
        /** @var array $nonPublicMethods */
        $nonPublicMethods = $this->getNonPublicMethods();
        $self = $this;
        $allowMockingProtectedMethods = $this->_mockery_allowMockingProtectedMethods;
        $lastExpectation = \Mockery::parseShouldReturnArgs($this, func_get_args(), function ($method) use($self, $nonPublicMethods, $allowMockingProtectedMethods) {
            $rm = $self->mockery_getMethod($method);
            if ($rm) {
                if ($rm->isPrivate()) {
                    throw new \InvalidArgumentException("{$method}() cannot be mocked as it is a private method");
                }
                if (!$allowMockingProtectedMethods && $rm->isProtected()) {
                    throw new \InvalidArgumentException("{$method}() cannot be mocked as it is a protected method and mocking protected methods is not enabled for the currently used mock object.");
                }
            }
            $director = $self->mockery_getExpectationsFor($method);
            if (!$director) {
                $director = new \Mockery\ExpectationDirector($method, $self);
                $self->mockery_setExpectationsFor($method, $director);
            }
            $expectation = new \Mockery\Expectation($self, $method);
            $director->addExpectation($expectation);
            return $expectation;
        });
        return $lastExpectation;
    }

Usage Example

Exemplo n.º 1
0
 public function testFindOneById()
 {
     $image1 = $this->dummyData->getTag();
     $this->imageRepository->shouldReceive('findOneById')->with($image1->getId())->andReturn($image1)->once();
     $image = $this->imageService->findOneById($image1->getId());
     $this->assertEntitiesEqual($image1, $image);
 }
All Usage Examples Of Mockery\Mock::shouldReceive