Skip to content

Commit

Permalink
Fixed tests for PHP 7.2 and 7.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
parpalak committed Jun 1, 2019
1 parent a3b0945 commit c47c759
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 80 deletions.
12 changes: 6 additions & 6 deletions src/S2/Rose/Storage/File/SingleFileArrayStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,21 @@ public function save()
}
}
file_put_contents($this->filename, $buffer . '}' . "\n", FILE_APPEND);
$this->fulltextProxy->setFulltextIndex(null);
$this->fulltextProxy->setFulltextIndex([]);

file_put_contents($this->filename, ' //' . serialize($this->excludedWords) . "\n", FILE_APPEND);
$this->excludedWords = null;
$this->excludedWords = [];

file_put_contents($this->filename, ' //' . serialize($this->indexSingleKeywords) . "\n", FILE_APPEND);
$this->indexSingleKeywords = null;
$this->indexSingleKeywords = [];

file_put_contents($this->filename, ' //' . serialize($this->indexBaseKeywords) . "\n", FILE_APPEND);
$this->indexBaseKeywords = null;
$this->indexBaseKeywords = [];

file_put_contents($this->filename, ' //' . serialize($this->indexMultiKeywords) . "\n", FILE_APPEND);
$this->indexMultiKeywords = null;
$this->indexMultiKeywords = [];

file_put_contents($this->filename, ' //' . serialize($this->toc) . "\n", FILE_APPEND);
$this->toc = null;
$this->toc = [];
}
}
46 changes: 15 additions & 31 deletions tests/unit/Rose/Entity/ResultSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Codeception\Test\Unit;
use S2\Rose\Entity\ResultSet;
use S2\Rose\Entity\Snippet;
use S2\Rose\Exception\ImmutableException;
use S2\Rose\Exception\RuntimeException;
use S2\Rose\Exception\UnknownIdException;

/**
* Class ResultTest
Expand Down Expand Up @@ -39,20 +42,16 @@ public function testLimit()
$this->assertEquals(33, $data['id_23']);
}

/**
* @expectedException \S2\Rose\Exception\UnknownIdException
*/
public function testSetRelevanceInvalidExternalId()
{
$this->expectException(UnknownIdException::class);
$result = $this->prepareResult(new ResultSet());
$result->setRelevanceRatio('not_found', 2);
}

/**
* @expectedException \S2\Rose\Exception\RuntimeException
*/
public function testSetRelevanceInvalidRatio()
{
$this->expectException(RuntimeException::class);
$result = $this->prepareResult(new ResultSet());
$result->setRelevanceRatio('id_10', ['not a number']);
}
Expand All @@ -76,12 +75,11 @@ public function testSetRelevance()
$this->assertEquals((10 + 29) * 1.1, $data['id_29']);
}

/**
* @expectedException \S2\Rose\Exception\ImmutableException
* @expectedExceptionMessage One cannot set relevance ratios after sorting the result set.
*/
public function testNoSetRelevanceAfterSorting()
{
$this->expectException(ImmutableException::class);
$this->expectExceptionMessage('One cannot set relevance ratios after sorting the result set.');

$result = $this->prepareResult(new ResultSet(2));
$this->assertContains('id_10', $result->getFoundExternalIds());

Expand All @@ -100,65 +98,51 @@ public function testEmpty()
$this->assertCount(0, $data);
}

/**
* @expectedException \S2\Rose\Exception\ImmutableException
*/
public function testNotFrozenGetItems()
{
$this->expectException(ImmutableException::class);
$resultSet = new ResultSet();
$resultSet->getItems();
}

/**
* @expectedException \S2\Rose\Exception\UnknownIdException
*/
public function testNotFrozenAttachSnippet()
{
$this->expectException(UnknownIdException::class);
$resultSet = new ResultSet();
$resultSet->attachSnippet('not found', new Snippet('', '', '<i>%s</i>'));
}

/**
* @expectedException \S2\Rose\Exception\ImmutableException
*/
public function testNotFrozenGetFoundExternalIds()
{
$this->expectException(ImmutableException::class);
$resultSet = new ResultSet();
$resultSet->getFoundExternalIds();
}

/**
* @expectedException \S2\Rose\Exception\ImmutableException
*/
public function testNotFrozenSetRelevanceRatio()
{
$this->expectException(ImmutableException::class);
$resultSet = new ResultSet();
$resultSet->setRelevanceRatio('not found', 2);
}

/**
* @expectedException \S2\Rose\Exception\ImmutableException
*/
public function testNotFrozenGetFoundWordsByExternalId()
{
$this->expectException(ImmutableException::class);
$resultSet = new ResultSet();
$resultSet->getFoundWordPositionsByExternalId();
}

/**
* @expectedException \S2\Rose\Exception\ImmutableException
*/
public function testNotFrozenGetSortedExternalIds()
{
$this->expectException(ImmutableException::class);
$resultSet = new ResultSet();
$resultSet->getSortedExternalIds();
}

/**
* @expectedException \S2\Rose\Exception\ImmutableException
*/
public function testNotFrozenGetSortedRelevanceByExternalId()
{
$this->expectException(ImmutableException::class);
$resultSet = new ResultSet();
$resultSet->getSortedRelevanceByExternalId();
}
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/Rose/Entity/SnippetLineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use Codeception\Test\Unit;
use S2\Rose\Entity\SnippetLine;
use S2\Rose\Exception\RuntimeException;

/**
* Class SnippetLineTest
Expand Down Expand Up @@ -49,11 +50,9 @@ public function testHtmlEntities()
$this->assertEquals('This string contains several entities like &ndash;, &amp;, &mdash; &#160;. Do not touch <i>160</i> and <i>dash</i>.', $snippetLine->getHighlighted('<i>%s</i>'));
}

/**
* @expectedException \S2\Rose\Exception\RuntimeException
*/
public function testCreateHighlightedFail()
{
$this->expectException(RuntimeException::class);
$snippetLine = new SnippetLine(
'Testing string to highlight some test values, Test is case-sensitive.',
['test', 'is'],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Rose/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function testFeatures(
// Query 6
$resultSet6 = $finder->find(new Query('учитель не должен'));
$this->assertCount(1, $resultSet6->getItems());
$this->assertEquals(47, $resultSet6->getItems()['id_3']->getRelevance(), '', 100);
$this->assertEquals(63.5, $resultSet6->getItems()['id_3']->getRelevance());

// Query 7: Test empty queries
$resultSet7 = $finder->find(new Query(''));
Expand Down
56 changes: 17 additions & 39 deletions tests/unit/Rose/Storage/PdoStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

use Codeception\Test\Unit;
use S2\Rose\Entity\TocEntry;
use S2\Rose\Exception\UnknownIdException;
use S2\Rose\Storage\Database\PdoStorage;
use S2\Rose\Storage\Exception\EmptyIndexException;

/**
* Class PdoStorageTest
Expand Down Expand Up @@ -178,11 +180,10 @@ public function testTransactions()
$storage->commitTransaction();
}

/**
* @expectedException \S2\Rose\Storage\Exception\EmptyIndexException
*/
public function testBrokenDb()
{
$this->expectException(EmptyIndexException::class);

$storage = new PdoStorage($this->pdo, 'test_');
$storage->erase();

Expand All @@ -196,111 +197,88 @@ public function testBrokenDb()
$storage->removeFromIndex('id_1');
}

/**
* @expectedException \S2\Rose\Storage\Exception\EmptyIndexException
*/
public function testNonExistentDbAddToToc()
{
$this->expectException(EmptyIndexException::class);

$storage = new PdoStorage($this->pdo, 'non_existent_');
$tocEntry1 = new TocEntry('test title', 'descr', new \DateTime('2014-05-28'), '', '123456789');
$storage->addItemToToc($tocEntry1, 'id_1');
}

/**
* @expectedException \S2\Rose\Exception\UnknownIdException
*/
public function testNonExistentDbAddToFulltext()
{
$this->expectException(UnknownIdException::class);
$storage = new PdoStorage($this->pdo, 'non_existent_');
$storage->addToFulltext(['word'], 'id_1');
}

/**
* @expectedException \S2\Rose\Exception\UnknownIdException
*/
public function testNonExistentDbAddToSingleKeywordIndex()
{
$this->expectException(UnknownIdException::class);
$storage = new PdoStorage($this->pdo, 'non_existent_');
$storage->addToSingleKeywordIndex('keyword', 'id_1', 1);
}

/**
* @expectedException \S2\Rose\Exception\UnknownIdException
*/
public function testNonExistentDbAddToMultipleKeywordIndex()
{
$this->expectException(UnknownIdException::class);
$storage = new PdoStorage($this->pdo, 'non_existent_');
$storage->addToMultipleKeywordIndex('multi keyword', 'id_1', 1);
}

/**
* @expectedException \S2\Rose\Storage\Exception\EmptyIndexException
*/
public function testNonExistentDbGetTocByExternalIds()
{
$this->expectException(EmptyIndexException::class);
$storage = new PdoStorage($this->pdo, 'non_existent_');
$storage->getTocByExternalIds(['id_1'])['id_1'];
}

/**
* @expectedException \S2\Rose\Storage\Exception\EmptyIndexException
*/
public function testNonExistentDbFindTocByTitle()
{
$this->expectException(EmptyIndexException::class);
$storage = new PdoStorage($this->pdo, 'non_existent_');
$storage->findTocByTitle('title');
}

/**
* @expectedException \S2\Rose\Storage\Exception\EmptyIndexException
*/
public function testNonExistentDbGetTocSize()
{
$this->expectException(EmptyIndexException::class);
$storage = new PdoStorage($this->pdo, 'non_existent_');
$storage->getTocSize();
}

/**
* @expectedException \S2\Rose\Storage\Exception\EmptyIndexException
*/
public function testNonExistentDbFillFulltextResultForWords()
{
$this->expectException(EmptyIndexException::class);
$storage = new PdoStorage($this->pdo, 'non_existent_');
$storage->fulltextResultByWords(['word']);
}

/**
* @expectedException \S2\Rose\Storage\Exception\EmptyIndexException
*/
public function testNonExistentDbGetSingleKeywordIndexByString()
{
$this->expectException(EmptyIndexException::class);
$storage = new PdoStorage($this->pdo, 'non_existent_');
$storage->getSingleKeywordIndexByWords(['keyword']);
}

/**
* @expectedException \S2\Rose\Storage\Exception\EmptyIndexException
*/
public function testNonExistentDbGetMultipleKeywordIndexByString()
{
$this->expectException(EmptyIndexException::class);
$storage = new PdoStorage($this->pdo, 'non_existent_');
$storage->getMultipleKeywordIndexByString('multi keyword');
}

/**
* @expectedException \S2\Rose\Storage\Exception\EmptyIndexException
*/
public function testNonExistentDbRemoveFromToc()
{
$this->expectException(EmptyIndexException::class);
$storage = new PdoStorage($this->pdo, 'non_existent_');
$storage->removeFromToc('id_1');
}

/**
* @expectedException \S2\Rose\Storage\Exception\EmptyIndexException
*/
public function testNonExistentDbRemoveFromIndex()
{
$this->expectException(EmptyIndexException::class);
$storage = new PdoStorage($this->pdo, 'non_existent_');
$storage->removeFromIndex('id_1');
}
Expand Down

0 comments on commit c47c759

Please sign in to comment.