/**
  * Before a test method is run, a template method called setUp() is invoked.
  */
 public function setUp()
 {
     $this->esRatesResult = [];
     foreach ($this->ratesFixture as $currency => $rate) {
         $this->esRatesBackup[0]['rates'][] = ['name' => $currency, 'value' => $rate];
     }
     $searchMock = $this->getMock('ONGR\\ElasticsearchBundle\\DSL\\Search');
     $searchMock->expects($this->any())->method('addSort')->will($this->returnSelf());
     $this->repositoryMock = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\ORM\\Repository')->disableOriginalConstructor()->setMethods(['createSearch', 'execute', 'createDocument'])->getMock();
     $this->repositoryMock->expects($this->any())->method('createSearch')->willReturn($searchMock);
     $this->repositoryMock->expects($this->any())->method('createDocument')->willReturn(new CurrencyDocument());
     $this->esManagerMock = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\ORM\\Manager')->setMethods(['getRepository', 'persist', 'commit'])->disableOriginalConstructor()->getMock();
     $this->esManagerMock->expects($this->any())->method('getRepository')->willReturn($this->repositoryMock);
     $this->esManagerMock->expects($this->any())->method('createSearch')->willReturn($searchMock);
 }
예제 #2
0
 /**
  * Test for get().
  *
  * @param string $key
  * @param string $value
  * @param bool   $exception
  *
  * @dataProvider getDataSetForSet
  */
 public function testGet($key, $value, $exception)
 {
     if ($exception) {
         $this->repositoryMock->expects($this->once())->method('find')->will($this->returnValue(null));
     } else {
         $pair = new Pair();
         $pair->setId($key);
         $pair->setValue($value);
         $this->repositoryMock->expects($this->once())->method('find')->willReturn($pair);
     }
     $this->ormManagerMock->expects($this->once())->method('getRepository')->willReturn($this->repositoryMock);
     $pairStorage = $this->getPairStorage($this->ormManagerMock);
     $this->assertEquals($exception ? null : $value, $pairStorage->get($key));
 }
 /**
  * Check if ignored version skipping works as expected.
  *
  * @param string $version
  * @param array  $ignoredVersions
  * @param bool   $shouldSkip
  * @param string $expectedMessage
  *
  * @dataProvider getIgnoreVersionData()
  */
 public function testIgnoreVersion($version, $ignoredVersions, $shouldSkip, $expectedMessage = '')
 {
     $actualMessage = '';
     $skipped = false;
     $this->dummyBase = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\Tests\\Unit\\Test\\ElasticsearchTestCaseDummy')->setMethods(['getIgnoredVersions', 'getContainer'])->disableOriginalConstructor()->getMock();
     $this->dummyBase->expects($this->any())->method('getContainer')->will($this->returnValue($this->containerMock));
     $this->dummyBase->expects($this->once())->method('getIgnoredVersions')->willReturn($ignoredVersions);
     $this->containerMock->expects($this->once())->method('has')->with('es.manager.default')->will($this->returnValue(true));
     $this->containerMock->expects($this->once())->method('get')->with('es.manager.default')->will($this->returnValue($this->managerMock));
     $this->managerMock->expects($this->once())->method('getConnection')->willReturn($this->connectionMock);
     $this->connectionMock->expects($shouldSkip ? $this->never() : $this->once())->method('dropAndCreateIndex');
     $this->connectionMock->expects($this->once())->method('getVersionNumber')->willReturn($version);
     $reflection = new \ReflectionMethod($this->dummyBase, 'setUp');
     $reflection->setAccessible(true);
     try {
         $reflection->invokeArgs($this->dummyBase, []);
     } catch (\PHPUnit_Framework_SkippedTestError $ex) {
         $actualMessage = $ex->getMessage();
         $skipped = true;
     }
     $this->assertEquals($shouldSkip, $skipped);
     $this->assertEquals($actualMessage, $expectedMessage);
 }
 /**
  * Setup mock for test.
  */
 public function setUp()
 {
     $this->manager = $this->getMockBuilder('ONGR\\ElasticsearchBundle\\ORM\\Manager')->disableOriginalConstructor()->setMethods(['getRepository'])->getMock();
     $this->manager->expects($this->any())->method('getRepository')->willReturnSelf();
 }