ShortifyPunit\ShortifyPunit::mock PHP Méthode

mock() public static méthode

Mocking interfaces & classes
public static mock ( $mockedClass ) : mixed
$mockedClass
Résultat mixed
    public static function mock($mockedClass)
    {
        $reflection = self::getMockReflection($mockedClass);
        return static::mockClass($reflection, self::$namespace, self::$classBasePrefix);
    }

Usage Example

 public function testOnKernelController()
 {
     $request = ShortifyPunit::mock('Symfony\\Component\\HttpFoundation\\Request');
     $requestStack = ShortifyPunit::mock('Symfony\\Component\\HttpFoundation\\RequestStack');
     $sandboxResponseManager = ShortifyPunit::mock('danrevah\\SandboxBundle\\Managers\\SandboxResponseManager');
     $event = ShortifyPunit::mock('Symfony\\Component\\HttpKernel\\Event\\FilterControllerEvent');
     $parameterBag = ShortifyPunit::mock('Symfony\\Component\\HttpFoundation\\ParameterBag');
     ShortifyPunit::when($request)->getContent()->returns('');
     $request->query = $parameterBag;
     $request->request = $parameterBag;
     ShortifyPunit::when($requestStack)->getCurrentRequest()->returns($request);
     ShortifyPunit::when($event)->getController()->returns([0, 1]);
     ShortifyPunit::when($event)->setController(anything())->returns(1);
     $sandboxListener = new SandboxListener($requestStack, $sandboxResponseManager);
     $sandboxListener->onKernelController($event);
     $this->assertTrue(ShortifyPunit::verify($event)->setController(anything())->atLeastOnce());
     $response = [false, 0, 0, 0];
     ShortifyPunit::when($sandboxResponseManager)->getResponseController(anything(), anything(), anything(), anything(), anything())->returns($response);
     $event2 = ShortifyPunit::mock('Symfony\\Component\\HttpKernel\\Event\\FilterControllerEvent');
     ShortifyPunit::when($event2)->setController(anything())->returns('');
     ShortifyPunit::when($event2)->getController(anything())->returns([0, 1]);
     $sandboxListener = new SandboxListener($requestStack, $sandboxResponseManager);
     $sandboxListener->onKernelController($event2);
     $this->assertTrue(ShortifyPunit::verify($event2)->setController(anything())->neverCalled());
 }
All Usage Examples Of ShortifyPunit\ShortifyPunit::mock