/**
  * 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);
 }
Exemplo n.º 2
0
 /**
  * Tests Connection#setIndexName method.
  */
 public function testSetIndexName()
 {
     $connection = new Connection($this->getClient(), ['index' => 'foo']);
     $this->assertEquals('foo', $connection->getIndexName(), 'Index name should not be changed.');
     $connection->setIndexName('bar');
     $this->assertEquals('bar', $connection->getIndexName(), 'Index name should be changed');
 }
Exemplo n.º 3
0
 /**
  * Updates elasticsearch client mapping.
  *
  * @param array $types Specific types to update.
  *
  * @return int
  */
 public function updateTypes(array $types = [])
 {
     $this->isReadOnly('Update types');
     if (!$this->getMapping($types)) {
         return -1;
     }
     $tempSettings = $this->settings;
     $tempSettings['index'] = uniqid('mapping_check_');
     $mappingCheckConnection = new Connection($this->getClient(), $tempSettings);
     $mappingCheckConnection->createIndex();
     $mappingCheckConnection->createTypes($types);
     $newMapping = $mappingCheckConnection->getMappingFromIndex($types);
     $oldMapping = $this->getMappingFromIndex($types);
     $mappingCheckConnection->dropIndex();
     $tool = new MappingTool();
     $updated = (int) $tool->checkMapping($oldMapping, $newMapping);
     if ($updated) {
         $this->unloadMappingArray($tool->getRemovedTypes());
         $this->loadMappingArray($tool->getUpdatedTypes());
     }
     return $updated;
 }
 /**
  * Ignores version specified.
  *
  * @param Connection $connection
  */
 protected function ignoreVersions(Connection $connection)
 {
     $currentVersion = $connection->getVersionNumber();
     $ignore = null;
     foreach ($this->getIgnoredVersions() as $ignoredVersion) {
         if (version_compare($currentVersion, $ignoredVersion[0], $ignoredVersion[1]) === true) {
             $ignore = true;
             if (isset($ignoredVersion[2])) {
                 if ($ignoredVersion[2] === $this->getName()) {
                     break;
                 }
                 $ignore = false;
             }
         }
     }
     if ($ignore === true) {
         $this->markTestSkipped("Elasticsearch version {$currentVersion} not supported by this test.");
     }
 }