setFunctionProvider() public method

Use this method if you want to set the mocked behaviour with a {@link FunctionProvider}. Alternatively, you can use {@link setFunction()} to set it with a callable.
See also: setFunction()
public setFunctionProvider ( phpmock\functions\FunctionProvider $provider ) : MockBuilder
$provider phpmock\functions\FunctionProvider The mock function provider.
return MockBuilder
Beispiel #1
0
 /**
  * Tests build().
  *
  * @test
  */
 public function testBuild()
 {
     $builder = new MockBuilder();
     $builder->setNamespace(__NAMESPACE__)->setName("time")->setFunction(function () {
         return 1234;
     });
     $mock = $builder->build();
     $mock->enable();
     $this->assertEquals(1234, time());
     $mock->disable();
     $builder->setFunctionProvider(new FixedValueFunction(123));
     $mock = $builder->build();
     $mock->enable();
     $this->assertEquals(123, time());
     $mock->disable();
 }
 public function testCreateServiceSession()
 {
     // Arrange
     $builder = new MockBuilder();
     $builder->setNamespace('PhpAb\\Storage');
     $builder->setName("session_status");
     $builder->setFunctionProvider(new FixedValueFunction(PHP_SESSION_ACTIVE));
     $sessionStatusMock = $builder->build();
     $sessionStatusMock->enable();
     $serviceLocator = $this->getMockForAbstractClass(ServiceLocatorInterface::class);
     $serviceLocator->expects($this->once())->method('get')->with($this->equalTo('Config'))->willReturn(['phpab' => ['storage' => 'session', 'storage_options' => ['name' => 'namespace']]]);
     $service = new StorageFactory();
     // Act
     $storage = $service->createService($serviceLocator);
     // Assert
     $this->assertInstanceOf(Session::class, $storage);
 }