Completed
Push — master ( 0d45ed...ea3502 )
by Nicolas
02:38
created

tests/ExampleTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Elastica\Test;
4
5
use Elastica\Document;
6
use Elastica\Test\Base as BaseTest;
7
8
/**
9
 * Tests the example code.
10
 *
11
 * @internal
12
 */
13
class ExampleTest extends BaseTest
14
{
15
    /**
16
     * @group functional
17
     */
18
    public function testBasicGettingStarted(): void
19
    {
20
        $client = $this->_getClient();
21
        $index = $client->getIndex('ruflin');
22
23
        $id = 2;
24
        $data = ['firstname' => 'Nicolas', 'lastname' => 'Ruflin'];
25
        $doc = new Document($id, $data);
26
27
        $index->addDocument($doc);
28
    }
29
30
    /**
31
     * @group functional
32
     */
33
    public function testExample(): void
34
    {
35
        // Creates a new index 'xodoa' and a type 'user' inside this index
36
        $client = $this->_getClient();
37
        $index = $client->getIndex('elastica_test');
38
        $index->create([], true);
39
40
        // Adds 1 document to the index
41
        $index->addDocument(new Document(1, ['username' => 'hans', 'test' => ['2', '3', '5']]));
42
43
        // Adds a list of documents with _bulk upload to the index
44
        $index->addDocuments([
45
            new Document(2, ['username' => 'john', 'test' => ['1', '3', '6']]),
46
            new Document(3, ['username' => 'rolf', 'test' => ['2', '3', '7']]),
47
        ]);
48
49
        // Refresh index
50
        $index->refresh();
51
52
        $resultSet = $index->search('rolf');
0 ignored issues
show
$resultSet is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
53
    }
54
}
55