protected function setUp() { $this->dodajPracownikaCommand = M::mock(DodajPracownikaCommand::class); $this->commandBus = M::mock(MessageBus::class); $this->pracownikRepository = M::mock(IPracownikRepository::class); $this->container = M::mock('Symfony\\Component\\DependencyInjection\\ContainerInterface'); $this->token_storage = M::mock(TokenStorageInterface::class); $this->token = M::mock(); $this->unitOfWork = M::mock(UnitOfWork::class); $this->request = new Request(); $this->user = M::mock(User::class); $this->user_zalogowany = M::mock(User::class); $this->pracownik = M::mock(Pracownik::class); $this->controller = new PracownikController($this->dodajPracownikaCommand, $this->commandBus, $this->pracownikRepository); $this->controller->setContainer($this->container); $this->controller->setUnitOfWork($this->unitOfWork); $this->request->headers = M::Mock(HeaderBag::class); $this->request->headers->shouldReceive('get')->with('referer')->once()->andReturn('http://localhost'); $this->unitOfWork->shouldReceive('commit')->once()->andReturn(); $this->container->shouldReceive('has')->with('security.token_storage')->once()->andReturn(true); $this->token->shouldReceive('getUser')->once()->andReturn($this->user_zalogowany); $this->token_storage->shouldReceive('getToken')->once()->andReturn($this->token); $this->container->shouldReceive('get')->with('security.token_storage')->once()->andReturn($this->token_storage); $form_factory = M::Mock(FormFactoryInterface::class); $this->form = M::Mock(Form::class); $this->form->shouldReceive('handleRequest')->once()->andReturn(true); $this->form->shouldReceive('createView')->once()->andReturn('stworzyła się jakaś forma'); $this->commandBus->shouldReceive('handle')->once()->andReturn(); $form_factory->shouldReceive('create')->once()->andReturn($this->form); $this->container->shouldReceive('get')->with('form.factory')->once()->andReturn($form_factory); $this->pracownikRepository->shouldReceive('findAllByUser')->once()->andReturn('Jakaś organizacja'); $this->pracownik->shouldReceive('getUser')->once()->andReturn($this->user); $this->pracownik->shouldReceive('setDel')->once()->andReturn(); }
public function setUp() { parent::setUp(); $this->mImage = M::mock('Agency\\Contracts\\ImageInterface'); $this->mHelper = M::Mock('Agency\\Contracts\\HelperInterface'); $this->images = new ImageRepository($this->mImage, $this->mHelper); $this->mHelper->shouldReceive('getUniqueId')->andReturn('12345'); }
public function testCanGenerateControllerUsingCustomTemplate() { $file = m::mock('Illuminate\\Filesystem\\Filesystem')->makePartial(); $cache = m::Mock('Way\\Generators\\Cache'); $file->shouldReceive('put')->once()->with(app_path() . '/controllers/FoosController.php', file_get_contents(__DIR__ . '/stubs/scaffold/controller.txt')); $generator = new ControllerGenerator($file, $cache); $generator->make(app_path() . '/controllers/FoosController.php', static::$templatesDir . '/scaffold/controller.txt'); }
public function testCanGenerateModelUsingCustomTemplateAndFields() { $file = m::mock('Illuminate\\Filesystem\\Filesystem')->makePartial(); $cache = m::Mock('Way\\Generators\\Cache'); $cache->shouldReceive('getFields')->once()->andReturn(['title' => 'string', 'age' => 'integer']); $file->shouldReceive('put')->once()->with(app_path() . '/models/Foo.php', file_get_contents(__DIR__ . '/stubs/scaffold/model.txt')); $generator = new ModelGenerator($file, $cache); $generator->make(app_path() . '/models/Foo.php', static::$templatesDir . '/scaffold/model.txt'); }
protected function mockAuthorityService() { $authService = \Mockery::Mock('TransformCore\\PHE\\LocalHealthAuthorityBundle\\Service\\AuthorityService'); $authService->shouldReceive('get')->with('transformcore.phe.lha.authority')->andReturnSelf(); $authService->shouldReceive('populateAddressDetailsFromPostCode')->andReturn($this->createQuestionnaire()); $authService->shouldReceive('findByPostCode')->withAnyArgs()->once()->andReturn(array((new Authority())->setCountry('United Kingdom')->setDistrictCouncil(new DistrictCouncil('AA', 'AA BB CC'))->setCounty(new County('AA', 'AA BB CC')))); $authService->shouldReceive('findByPostCode')->withAnyArgs()->andReturnNull(); return $authService; }
/** *@dataProvider classifyProvider */ public function testClassify($string, $probs, $expect) { $resultOb = m::Mock('\\BayesPHP\\Sample\\Result'); $resultOb->shouldReceive('getWordProbability')->times(5)->andReturn($probs[0], $probs[1], $probs[2], $probs[3], $probs[4]); $stemer = m::Mock('\\BayesPHP\\Stemer'); $stemer->shouldReceive('process')->once()->andReturn($string); $classifier = new Classifier($resultOb, $stemer); $classifierResult = $classifier->classify($string); $this->assertEquals($classifierResult->getProbabilities(), $expect); }
/** * @runInSeparateProcess */ public function testGetQRCodeUrlWithTitle() { $mock = m::Mock('alias:Fuel\\Core\\Config'); $mock->shouldReceive('load')->andReturn(array('title' => 'TheMock')); $secret = \G2FA\G2FA::createSecret(); $otpauth = urlencode('otpauth://totp/bar?secret=' . $secret . '&issuer=' . urlencode('TheMock')); $expect = "https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl=" . $otpauth; $actual = \G2FA\G2FA::getQRCodeUrl('bar', $secret); $this->assertEquals($expect, $actual); }
public function testGetDoesNotThrowExceptionIfHttpFailsAndThrowHttpExceptionsIsFalse() { $cache = Mockery::mock('\\Imdb\\Cache', ['get' => null, 'set' => true]); $request = Mockery::mock(['sendRequest' => false]); $config = new Config(); $config->throwHttpExceptions = false; $pages = Mockery::Mock('\\Imdb\\Pages[buildRequest]', [$config, $cache, new Logger()]); $pages->shouldAllowMockingProtectedMethods(); $pages->shouldReceive('buildRequest')->once()->andReturn($request); $pages->get('test'); }
public function testPutDistrictCouncilActionReturns404() { $container = $this->mockContainer(); $container->shouldReceive('saveWebsite')->withAnyArgs()->andReturn(new DistrictCouncil('', '')); $this->instance->setContainer($container); $pf = \Mockery::Mock('FOS\\RestBundle\\Request\\ParamFetcher')->shouldIgnoreMissing(); $result = $this->instance->putDistrictCouncilAction(PHP_INT_MAX, $pf); $this->assertInstanceOf(View::class, $result); $this->assertNotNull($result->getData()); $this->assertInstanceOf(DistrictCouncil::class, $result->getData()); $this->assertNull($result->getData()->getId()); $this->assertEquals(404, $result->getStatusCode()); }
public function testAsHtml() { // Mock Resource $now = new DateTime(); $content = 'this is the content'; $mockResource = m::Mock('Fideloper\\ResourceCache\\Resource\\Eloquent\\Resource'); $mockResource->shouldReceive('getEtag')->once()->andReturn(md5('example1')); $mockResource->shouldReceive('getLastUpdated')->once()->andReturn($now); $synResp = new SymfonyResponse(); $htmlResponse = $synResp->asHtml($mockResource, $content, 200); // General health $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $htmlResponse, 'Response is of type Response'); $this->assertEquals(200, $htmlResponse->getStatusCode(), 'Status code set to what we expected'); $this->assertEquals($content, $htmlResponse->getContent(), 'Response content is as set'); // ETag $this->assertEquals('"' . md5('example1') . '"', $htmlResponse->getEtag(), 'ETag set as expected'); // Last-Modified $this->assertEquals($now->getTimestamp(), $htmlResponse->getLastModified()->getTimestamp(), 'Last Modified date set as expected'); }
/** * Test that the service provider can register an instance of fixture * with the application container. * * @test * @return void */ public function it_should_be_able_to_register_an_instance_of_fixture_with_the_container() { App::bind('db', function ($app) { $mockedDB = m::mock('Illuminate\\Database\\DatabaseManager'); $mockedConnection = m::mock('Illuminate\\Database\\Connection'); $pdo = new PDO('sqlite::memory:'); $mockedDB->shouldReceive('connection')->once()->andReturn($mockedConnection); $mockedConnection->shouldReceive('getPdo')->once()->andReturn($pdo); return $mockedDB; }); App::bind('Str', function ($app) { return m::mock('Illuminate\\Support\\Str'); }); App::bind('config', function ($app) { $mockedConfig = m::Mock('Illuminate\\Config\\Repository'); $mockedConfig->shouldReceive('get')->once()->with('fixture-l4::config'); return $mockedConfig; }); $instance = Fixture::getFacadeRoot(); $this->assertInstanceOf('Codesleeve\\Fixture\\Fixture', $instance); }
private function setUpEventDispatcher() { $dispatcher = \Mockery::Mock('Aol\\Atc\\EventDispatcher'); return $dispatcher; }
/** * 复杂查询未命中缓存 */ public function testRawAwfulGet() { // 模拟数据库返回结果 $this->conn->shouldReceive('select')->with('select count(*) from "user" where "id" = ?', [1], true)->andReturn([(object) ["count(*)" => 1]]); // 模拟未命中缓存 $this->cache->shouldReceive('get')->with(['122a32ae3f8656ba95b87700de71506c'])->andReturn([]); // 模拟缓存查询结果 $this->cache->shouldReceive('set')->with(['122a32ae3f8656ba95b87700de71506c' => [(object) ["count(*)" => 1]]]); $dispatcher = M::Mock(Dispatcher::class); $dispatcher->shouldReceive('fire')->with('angejia.pea.get', ['table' => 'user', 'db' => 'angejia']); $dispatcher->shouldReceive('fire')->with('angejia.pea.miss.awful', ['table' => 'user', 'db' => 'angejia']); $this->app->instance(Dispatcher::class, $dispatcher); $data = User::where('id', 1)->select(new Expression('count(*)'))->get(); $this->assertEquals(1, $data[0]['count(*)']); }
public function testDeciderScanWithTwoEventAndNoAgentShouldMakeADecision() { $this->setUpTables(); $this->setUpRepo(); $dbManager = M::mock(DbManager::classname()); $agentDao = M::mock(AgentDao::classname()); $clearingDao = M::mock(ClearingDao::classname()); $uploadDao = M::mock(UploadDao::classname()); $highlightDao = M::mock(HighlightDao::classname()); $decisionProcessor = M::mock(ClearingDecisionProcessor::classname()); $agentLicenseEventProcessor = M::mock(AgentLicenseEventProcessor::classname()); $uploadId = 13243; /*mock for Agent class **/ $agentDao->shouldReceive('arsTableExists')->andReturn(true); $agentDao->shouldReceive('getCurrentAgentId')->andReturn($agentId = 24); $agentDao->shouldReceive('writeArsRecord')->with(anything(), $agentId, $uploadId)->andReturn($arsId = 2); $agentDao->shouldReceive('writeArsRecord')->with(anything(), $agentId, $uploadId, $arsId, true)->andReturn(0); $jobId = 42; $groupId = 6; $userId = 2; $itemIds = array(4343, 43); $bounds0 = M::mock(ItemTreeBounds::classname()); $bounds0->shouldReceive('getItemId')->andReturn($itemIds[0]); $bounds0->shouldReceive('containsFiles')->andReturn(false); $bounds1 = M::mock(ItemTreeBounds::classname()); $bounds1->shouldReceive('getItemId')->andReturn($itemIds[1]); $bounds1->shouldReceive('containsFiles')->andReturn(false); $bounds = array($bounds0, $bounds1); $uploadDao->shouldReceive('getItemTreeBounds')->with($itemIds[0])->andReturn($bounds[0]); $uploadDao->shouldReceive('getItemTreeBounds')->with($itemIds[1])->andReturn($bounds[1]); $clearingDao->shouldReceive('getEventIdsOfJob')->with($jobId)->andReturn(array($itemIds[0] => array(), $itemIds[1] => array())); $dbManager->shouldReceive('begin')->times(count($itemIds)); $dbManager->shouldReceive('commit')->times(count($itemIds)); /* dummy expectations needed for unmockable LicenseMap constructor */ $dbManager->shouldReceive('prepare'); $res = M::Mock(DbManager::classname()); $dbManager->shouldReceive('execute')->andReturn($res); $row1 = array('rf_fk' => 2334, 'parent_fk' => 1); $row2 = array('rf_fk' => 2333, 'parent_fk' => 1); $dbManager->shouldReceive('fetchArray')->with($res)->andReturn($row1, $row2, false); $dbManager->shouldReceive('freeResult')->with($res); /* /expectations for LicenseMap */ $decisionProcessor->shouldReceive('hasUnhandledScannerDetectedLicenses')->with($bounds0, $groupId, array(), anything())->andReturn(true); $clearingDao->shouldReceive('markDecisionAsWip')->with($itemIds[0], $userId, $groupId); $decisionProcessor->shouldReceive('hasUnhandledScannerDetectedLicenses')->with($bounds1, $groupId, array(), anything())->andReturn(false); $decisionProcessor->shouldReceive('makeDecisionFromLastEvents')->with($bounds1, $userId, $groupId, DecisionTypes::IDENTIFIED, false, array()); $runner = new SchedulerTestRunnerMock($dbManager, $agentDao, $clearingDao, $uploadDao, $highlightDao, $decisionProcessor, $agentLicenseEventProcessor); list($success, $output, $retCode) = $runner->run($uploadId, $userId, $groupId, $jobId, $args = ""); $this->assertTrue($success, 'cannot run decider'); $this->assertEquals($retCode, 0, 'decider failed: ' . $output); assertThat($this->getHeartCount($output), equalTo(count($itemIds))); $this->rmRepo(); }
public function testWasNotModifiedIsNotUnmodified() { // Mock Request $mockRequest = m::mock('Symfony\\Component\\HttpFoundation\\Request'); $mockRequest->shouldReceive('retrieveItem')->with('headers', 'if-match')->andReturn(false); $mockRequest->shouldReceive('retrieveItem')->with('headers', 'if-unmodified-since')->andReturn('1 March 2013'); // Mock Resource $mockResource = m::Mock('Fideloper\\ResourceCache\\Resource\\Eloquent\\Resource'); $mockResource->shouldReceive('getLastUpdated')->once()->andReturn(new DateTime('@' . strtotime('3 March 2013'))); $symReq = new SymfonyRequest($mockRequest); $this->assertFalse($symReq->wasNotModified($mockResource), 'Was modified after March 1, on March 3, and so "was unmodified" returns false'); }