start() public static method

Example: PHP global namespace function setcookie() needs to be overridden in order to test if a cookie gets set. When setcookie() is called from inside a class in the namespace \Foo\Bar the mock setcookie() created here will be used instead to the real function.
public static start ( PHPUnit_Framework_TestCase $testCase, string $namespace ) : PHPUnit_Extension_FunctionMocker
$testCase PHPUnit_Framework_TestCase
$namespace string
return PHPUnit_Extension_FunctionMocker
示例#1
0
 /**
  * @runInSeparateProcess
  * @expectedException \RuntimeException
  */
 public function testRandomWithFailure()
 {
     $this->php = FunctionMocker::start($this, 'Chromabits\\Nucleus\\Support')->mockFunction('function_exists')->mockFunction('openssl_random_pseudo_bytes')->getMock();
     $this->php->expects($this->once())->method('function_exists')->will($this->returnValue(true));
     $this->php->expects($this->once())->method('openssl_random_pseudo_bytes')->will($this->returnValue(false));
     Str::random();
 }
 public function setUp()
 {
     $this->executor = $this->getMockBuilder('Procrastinator\\Executor\\Executor')->getMock();
     $this->decorator = new PhpFpmExecutorDecorator($this->executor);
     $this->executable = $this->getMockBuilder('Procrastinator\\Executable')->getMock();
     $this->deferred = $this->getMockBuilder('Procrastinator\\Deferred\\Deferred')->getMock();
     $this->functions = \PHPUnit_Extension_FunctionMocker::start($this, __NAMESPACE__)->mockFunction('function_exists')->mockFunction('fastcgi_finish_request')->getMock();
 }
 public function setUp()
 {
     $this->executor = $this->getMockBuilder('Procrastinator\\Executor\\Executor')->getMock();
     $this->decorator = new SetTimeLimitDecorator($this->executor, 120);
     $this->executable = $this->getMockBuilder('Procrastinator\\Executable')->getMock();
     $this->deferred = $this->getMockBuilder('Procrastinator\\Deferred\\Deferred')->getMock();
     $this->functions = \PHPUnit_Extension_FunctionMocker::start($this, __NAMESPACE__)->mockFunction('set_time_limit')->getMock();
 }
示例#4
0
 public function testMockSameFunctionIsDifferentNamespaces()
 {
     $this->assertMockFunctionNotDefined('My\\TestNamespace\\foofunc');
     $this->functionMocker->mockFunction('foofunc');
     $this->assertMockFunctionNotDefined('My\\TestNamespace\\foofunc');
     $this->functionMocker->getMock();
     $this->assertMockFunctionDefined('My\\TestNamespace\\foofunc', 'My\\TestNamespace');
     $this->functionMocker = PHPUnit_Extension_FunctionMocker::start($this, 'My\\TestNamespace2');
     $this->assertFalse(function_exists('My\\TestNamespace2\\foofunc'));
     $this->functionMocker->mockFunction('foofunc');
     $this->assertFalse(function_exists('My\\TestNamespace2\\foofunc'));
     $this->functionMocker->getMock();
     $this->assertMockFunctionDefined('My\\TestNamespace2\\foofunc', 'My\\TestNamespace2');
 }
 public function setup()
 {
     $this->php = \PHPUnit_Extension_FunctionMocker::start($this, 'Bolt\\Configuration')->mockFunction('is_writable')->mockFunction('is_dir')->getMock();
 }
示例#6
0
 public function setup()
 {
     $this->php = \PHPUnit_Extension_FunctionMocker::start($this, 'Bolt')->mockFunction('file_exists')->mockFunction('is_readable')->mockFunction('is_dir')->mockFunction('copy')->mockFunction('file_get_contents')->getMock();
     $this->php2 = \PHPUnit_Extension_FunctionMocker::start($this, 'Bolt\\Tests\\Asset\\Mock')->mockFunction('file_get_contents')->getMock();
 }
示例#7
0
 public function setUp()
 {
     $this->php = \PHPUnit_Extension_FunctionMocker::start($this, 'Bolt\\Twig\\Handler')->mockFunction('shuffle')->getMock();
 }
示例#8
0
 public function setUp()
 {
     $this->php = \PHPUnit_Extension_FunctionMocker::start($this, 'Bolt\\Configuration')->mockFunction('is_readable')->mockFunction('is_writable')->mockFunction('file_exists')->mockFunction('is_dir')->mockFunction('copy')->mockFunction('error_get_last')->getMock();
     $this->php2 = \PHPUnit_Extension_FunctionMocker::start($this, 'Bolt\\Exception')->mockFunction('error_get_last')->getMock();
     $this->errorResponses = ['core' => ['type' => E_ERROR, 'file' => TEST_ROOT . '/src', 'line' => 16, 'message' => 'src error'], 'extensions' => ['type' => E_ERROR, 'file' => PHPUNIT_WEBROOT . '/extensions', 'line' => 1, 'message' => 'extension error'], 'extension' => ['type' => E_ERROR, 'file' => PHPUNIT_WEBROOT . '/extensions/vendor/gawain/clippy', 'line' => 1, 'message' => 'extension error'], 'vendor' => ['type' => E_ERROR, 'file' => TEST_ROOT . '/vendor', 'line' => 1, 'message' => 'vendor error'], 'unknown' => ['type' => E_ERROR, 'file' => TEST_ROOT, 'line' => 1, 'message' => 'unknown error']];
 }
示例#9
0
 public function setUp()
 {
     $this->php = PHPUnit_Extension_FunctionMocker::start($this, 'PHPUnitTests\\Extension\\Fixtures')->mockFunction('strpos')->getMock();
 }