Exemplo n.º 1
0
 /**
  * Set expected method calls
  *
  * @param mixed
  * @return \Mockery\Expectation
  */
 public function shouldReceive()
 {
     /** @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 a protected method and mocking protected methods is not allowed for this mock");
             }
         }
         $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;
 }
Exemplo n.º 2
0
 /**
  * Set expected method calls
  *
  * @param mixed
  * @return \Mockery\Expectation
  */
 public function shouldReceive()
 {
     $self =& $this;
     $lastExpectation = \Mockery::parseShouldReturnArgs($this, func_get_args(), function ($method) use($self) {
         $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;
 }
Exemplo n.º 3
0
 /**
  * Set expected method calls
  *
  * @param string $methodName,... one or many methods that are expected to be called in this mock
  * @return \Mockery\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;
 }