/** @test */ public function simpleStubWithPhake() { $service = \Phake::mock('\\Acme\\ServiceInterface'); \Phake::when($service)->readTemp()->thenReturn(10)->thenReturn(12)->thenReturn(14); $temperature = new Temperature($service); $this->assertEquals(12, $temperature->average()); }
public function setUp() { $this->httpFoundationRequestHandler = \Phake::mock('Symfony\\Component\\Form\\Extension\\HttpFoundation\\HttpFoundationRequestHandler'); $this->jsonRequestHandler = new JsonRequestHandler($this->httpFoundationRequestHandler); $this->form = \Phake::mock('Symfony\\Component\\Form\\FormInterface'); $this->request = \Phake::mock('Symfony\\Component\\HttpFoundation\\Request'); }
/** * Sets up the test fixture */ public function setUp() { Phake::initAnnotations($this); $this->matcher = $this->getMock('Phake_Matchers_MethodMatcher', array(), array(), '', false); $this->stubMapper = Phake::mock('Phake_Stubber_StubMapper'); $this->binder = new Phake_Stubber_AnswerBinder($this->matcher, $this->stubMapper); }
protected function setUp() { $this->paginUrl = \Phake::mock('Behoimi\\Pager\\PagingUrl'); \Phake::when($this->paginUrl)->getPrev()->thenReturn('hoge'); \Phake::when($this->paginUrl)->getNext()->thenReturn('fuga'); $this->target = new ListResult(true, array((object) array('id' => 1, 'name' => 'name')), $this->paginUrl, null); }
private function createIUT(array $cssAssets = array(), array $jsAssets = array()) { $container = \Phake::mock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); \Phake::when($container)->get('modera_mjr_integration.css_resources_provider')->thenReturn($this->createMockProvider($cssAssets)); \Phake::when($container)->get('modera_mjr_integration.js_resources_provider')->thenReturn($this->createMockProvider($jsAssets)); return new AssetsProvider($container); }
/** * @test */ public function it_grants_access_from_token_roles() { $user = \Phake::mock('Symfony\\Component\\Security\\Core\\User\\UserInterface'); \Phake::when($user)->getRoles()->thenReturn(array('ROLE_USER', 'ROLE_ADMIN')); $context = new MockTokenContext($user); $this->assertTrue($context->isGranted('ROLE_USER')); }
/** * {@inheritdoc} */ protected function setUp() { $this->container = \Phake::mock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $this->webUploader = \Phake::mock(WebUploader::clazz()); $this->ctr = new UniversalUploaderController(); $this->ctr->setContainer($this->container); }
/** * Sets up test fixture */ public function setUp() { $this->matcher1 = Phake::mock('Phake_Matchers_IChainableArgumentMatcher'); $this->obj = $this->getMock('Phake_IMock'); PhakeTestUtil::setStubMapper($this->obj, Phake::mock('Phake_Stubber_StubMapper')); $this->proxy = new Phake_Proxies_CallStubberProxy($this->matcher1, false); }
public function setUp() { $this->target = new Session(new Request(array(), array()), array()); $_SESSION = array('HOGE' => 1, 'FUGA' => 2, 'PIYO' => array('FIZZ' => 'BUZZ')); $this->bindable = \Phake::mock('\\Hoimi\\Bindable'); \Phake::when($this->bindable)->getSessionKey()->thenReturn('bindable.dummy'); }
/** * @expectedException Symfony\Component\Security\Core\Exception\AccessDeniedException */ public function testGetAction() { $ctrl = $this->createStoredFileController(); $request = \Phake::mock('Symfony\\Component\\HttpFoundation\\Request'); $resp = $ctrl->getAction($request, ''); $this->assertEquals(Response::HTTP_NOT_FOUND, $resp->getStatusCode()); $this->assertEquals('File not found.', $resp->getContent()); $content = 'Hello World!'; $storageKey = 'storage-key/repository-name/file-name.txt'; $ctrl->storedFile = $this->createStoredFile($storageKey, $content); $resp = $ctrl->getAction($request, 'storage-key'); $this->assertEquals(Response::HTTP_OK, $resp->getStatusCode()); $this->assertEquals($content, $resp->getContent()); $this->assertNull($resp->headers->get('content-disposition')); $resp = $ctrl->getAction($request, $storageKey); $this->assertEquals(Response::HTTP_OK, $resp->getStatusCode()); $this->assertEquals($content, $resp->getContent()); $this->assertNull($resp->headers->get('content-disposition')); $content = 'Download test'; $ctrl->storedFile = $this->createStoredFile($storageKey, $content); \Phake::when($request)->get('dl')->thenReturn(''); $resp = $ctrl->getAction($request, 'storage-key/repository-name/download-me.txt'); $this->assertEquals(Response::HTTP_OK, $resp->getStatusCode()); $this->assertEquals($content, $resp->getContent()); $this->assertEquals('attachment; filename="download-me.txt"', $resp->headers->get('content-disposition')); $resp = $ctrl->getAction($request, 'storage-key/foo.txt'); $this->assertEquals(Response::HTTP_OK, $resp->getStatusCode()); $this->assertEquals($content, $resp->getContent()); $this->assertEquals('attachment; filename="foo.txt"', $resp->headers->get('content-disposition')); $ctrl->setEnabled(false); $resp = $ctrl->getAction($request, 'Exception'); }
/** @test */ public function should_convert_segment_to_string() { $segment = new Segment('XXX'); $segment->var = 'value'; $segmentMapping = new SegmentMapping('XXX'); $segmentMapping->addDataElement(1, new DataElementMapping(2345, true, DataElementType::A, 'var')); $message = new Message(); $message->setReferenceNumber(34834); $message->setIdentifier(["type" => 'TEST', "version" => 'S', "release" => '404', "controllingAgency" => 'PG']); $message->addSegment($segment); // $messageMapping = new MessageMapping(); // $messageMapping->setDefaults(["0065" => 'TEST', "0052" => 'S', "0054" => '404', "0051" => 'PG']); // $messageMapping->addSegment(new MessageSegmentMapping('UNH', 1, true)); // $messageMapping->addSegment(new MessageSegmentMapping('XXX', 99, true)); // $messageMapping->addSegment(new MessageSegmentMapping('UNT', 1, true)); $interchange = new Interchange(); $interchange->setSyntax(["name" => 'UNOC', "version" => 3]); $interchange->setSender(['id' => 'zenon']); $interchange->setRecipient(['id' => 'stefan']); $interchange->setTime(['date' => '20150101', 'time' => '1034']); $interchange->setControlReference('17'); $interchange->setMessages([$message]); $mappingLoader = \Phake::mock(MappingLoader::class); \Phake::when($mappingLoader)->loadSegments(\Phake::anyParameters())->thenReturn(['XXX' => $segmentMapping]); $encoder = new Encoder(new AnnotationPrinter(new AnnotationReader()), new SegmentPrinter(), $mappingLoader); $result = $encoder->encode($interchange); $this->assertEquals("UNB+UNOC:3+zenon+stefan+20150101:1034+17'UNH+34834+TEST:S:404:PG'XXX+value'UNT+1+34834'UNZ+1+17'", $result); }
public function setUp() { $this->mockReader = Phake::mock('Phake_MockReader'); $this->stubMapper = Phake::mock('Phake_Stubber_StubMapper'); $this->callRecorder = Phake::mock('Phake_CallRecorder_Recorder'); $this->resetter = new Phake_Mock_Resetter($this->mockReader); }
public function setUp() { $this->mock = $this->getMock('Phake_IMock'); $this->mockReader = Phake::mock('Phake_MockReader'); Phake::when($this->mockReader)->getName($this->mock)->thenReturn('Phake_IMock'); $this->call = new Phake_CallRecorder_Call($this->mock, 'someMethod', array('foo', 'bar'), $this->mockReader); }
public function testBuild() { $containerBuilder = \Phake::mock('Symfony\\Component\\DependencyInjection\\ContainerBuilder'); $bundle = new ModeraRoutingBundle(); $bundle->build($containerBuilder); \Phake::verify($containerBuilder, \Phake::atLeast(2))->addCompilerPass($this->isInstanceOf('Symfony\\Component\\DependencyInjection\\Compiler\\CompilerPassInterface')); }
protected function setUp() { parent::setUp(); $this->container = \Phake::mock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); \Phake::when($this->container)->get('modera_server_crud.persistence.default_handler')->thenReturn(new DummyDoctrinePersistenceHandler()); \Phake::when($this->container)->get('doctrine.orm.entity_manager')->thenReturn(new DummyDoctrineEntityManager()); }
public function testGetUrl() { $container = \Phake::mock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); \Phake::when($container)->getParameter(ModeraFileRepositoryExtension::CONFIG_KEY . '.default_url_generator')->thenReturn('default_url_generator'); \Phake::when($container)->getParameter(ModeraFileRepositoryExtension::CONFIG_KEY . '.url_generators')->thenReturn(array('foo' => 'foo_url_generator', 'bar' => 'bar_url_generator')); $defaultUrlGenerator = \Phake::mock('Modera\\FileRepositoryBundle\\StoredFile\\UrlGeneratorInterface'); \Phake::when($container)->get('default_url_generator')->thenReturn($defaultUrlGenerator); $fooUrlGenerator = \Phake::mock('Modera\\FileRepositoryBundle\\StoredFile\\UrlGeneratorInterface'); \Phake::when($container)->get('foo_url_generator')->thenReturn($fooUrlGenerator); \Phake::when($container)->get('bar_url_generator')->thenReturn('not_url_generator'); $context = array(); $splFile = new \SplFileInfo(__FILE__); $repository = \Phake::mock('Modera\\FileRepositoryBundle\\Entity\\Repository'); \Phake::when($repository)->generateStorageKey($splFile, $context)->thenReturn('storage-key'); $storedFile = new StoredFile($repository, $splFile, $context); $storedFile->init($container); \Phake::when($defaultUrlGenerator)->generateUrl($storedFile)->thenReturn('default_url'); \Phake::when($fooUrlGenerator)->generateUrl($storedFile)->thenReturn('foo_url'); \Phake::when($repository)->getConfig()->thenReturn(array('filesystem' => 'foo')); $this->assertEquals('foo_url', $storedFile->getUrl()); \Phake::when($repository)->getConfig()->thenReturn(array('filesystem' => 'bar')); $this->assertEquals('default_url', $storedFile->getUrl()); \Phake::when($repository)->getConfig()->thenReturn(array('filesystem' => 'baz')); $this->assertEquals('default_url', $storedFile->getUrl()); }
public function setUp() { $this->mockReader = Phake::mock('Phake_MockReader'); $this->callRecorder = Phake::mock('Phake_CallRecorder_Recorder'); Phake::when($this->mockReader)->getCallRecorder($this->anything())->thenReturn($this->callRecorder); $this->handler = new Phake_ClassGenerator_InvocationHandler_MagicCallRecorder($this->mockReader); }
/** * @depends test_exceptions_returns_error_response * @dataProvider provider_exception_error_messages * * @param $exception_class * @param $expected_error */ public function test_exceptions_return_correct_error_response($exception_class, $expected_error) { Phake::when($this->white_label_service)->createUser(Phake::anyParameters())->thenThrow(Phake::mock($exception_class)); $this->client->white_label_pair_callback(); Phake::verify($this->facade)->wp_send_json(Phake::capture($response)); $this->assertEquals($expected_error, $response['error']); }
/** * @param Phake_IMock $mock * @return Phake_Mock_Info */ public static function getMockedInfo(Phake_IMock $mock) { if (empty($mock->__PHAKE_info)) { $mock->__PHAKE_info = Phake::mock('Phake_Mock_Info'); } return $mock->__PHAKE_info; }
public function setUp() { $this->person = new Person("Richard"); $this->enterprise = \Phake::mock('tp2\\Enterprise'); $this->HRDepartment = new HRDepartment($this->enterprise); \Phake::when($this->enterprise)->employ($this->person)->thenReturn(false); }
public function testFreeze() { $client = Phake::mock('Phake_Client_IClient'); $this->freezer->freeze($this->mockInfo, $client); Phake::verify($client)->processObjectFreeze(); Phake::verify($this->mockInfo)->freezeObject(); }
/** * @test * * @since Method available since Release 2.1.0 */ public function setsTheStateMachineObject() { $stateMachine1 = \Phake::mock('Stagehand\\FSM\\StateMachine\\StateMachineInterface'); $stateMachineBuilder = new StateMachineBuilder($stateMachine1); $stateMachine2 = $stateMachineBuilder->getStateMachine(); $this->assertThat($stateMachine2, $this->identicalTo($stateMachine1)); }
public function testBuild() { $builder = \Phake::mock('Symfony\\Component\\DependencyInjection\\ContainerBuilder'); $bundle = new ModeraMJRSecurityIntegrationBundle(); $bundle->build($builder); \Phake::verify($builder, \Phake::times(1))->addCompilerPass($this->isInstanceOf('Symfony\\Component\\DependencyInjection\\Compiler\\CompilerPassInterface')); }
public function createRedisClient(array $parameters = array()) { $mockedRedisClient = \Phake::mock('\\PSRedis\\Client'); \Phake::when($mockedRedisClient)->isMaster()->thenReturn(false); \Phake::when($mockedRedisClient)->getMaster(\Phake::anyParameters())->thenReturn($mockedRedisClient); return $mockedRedisClient; }
public function setUp() { $this->scraper = \Phake::mock('Moshas\\WebSite\\Scraper'); $this->definition = \Phake::mock('Moshas\\WebSite\\ScrapingDefinition'); $this->next = \Phake::mock('Moshas\\Pipe'); $this->target = new Start($this->scraper, $this->definition, $this->next); }
public function initialize($object) { $reflectionClass = new ReflectionClass($object); $reader = new Phake_Annotation_Reader($reflectionClass); if ($this->useDoctrineParser()) { $parser = new \Doctrine\Common\Annotations\PhpParser(); } $properties = $reader->getPropertiesWithAnnotation('Mock'); foreach ($properties as $property) { $annotations = $reader->getPropertyAnnotations($property); if ($annotations['Mock'] !== true) { $mockedClass = $annotations['Mock']; } else { $mockedClass = $annotations['var']; } if (isset($parser)) { // Ignore it if the class start with a backslash if (substr($mockedClass, 0, 1) !== '\\') { $useStatements = $parser->parseClass($reflectionClass); $key = strtolower($mockedClass); if (array_key_exists($key, $useStatements)) { $mockedClass = $useStatements[$key]; } } } $reflProp = new ReflectionProperty(get_class($object), $property); $reflProp->setAccessible(true); $reflProp->setValue($object, Phake::mock($mockedClass)); } }
public function setUp() { $this->connection = \Phake::mock('\\mysqli'); $this->statement = \Phake::mock('\\Hoimi\\Session\\StatementDummy'); $this->target = \Phake::partialMock('Hoimi\\Session\\DatabaseDriver', new Config()); $this->target->setConnection($this->connection); }
public function testPost() { $budgetaryItemRepoMock = \Phake::mock('myfinance\\repositories\\BudgetaryItemRepository'); $controller = new BudgetaryController($budgetaryItemRepoMock); $json = '{"description":"Autoausgaben"}'; $controller->post(json_decode($json)); \Phake::verify($budgetaryItemRepoMock)->create(\Phake::ignoreRemaining()); }
public function testPost() { $accountingEntryRepoMock = \Phake::mock('myfinance\\repositories\\AccountingEntryRepository'); $controller = new AccountingEntryController($accountingEntryRepoMock); $json = '{"amount":"12.15",description":"Reperatur bei Autohaus","date":"2015-09-03","account":"1","category","2"}'; $controller->post(json_decode($json)); \Phake::verify($accountingEntryRepoMock)->create(\Phake::ignoreRemaining()); }
public function testGetUser() { $dbMock = \Phake::mock('myfinance\\db\\DB'); $userMock = \Phake::mock('myfinance\\model\\User'); $context = new FinanceContext($dbMock, $userMock); $result = $context->getUser(); $this->assertEquals($userMock, $result); }