UpsertTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 14
c 3
b 0
f 1
dl 0
loc 26
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testUpsert() 0 14 1
A testUpsertEmptyTuple() 0 8 1
1
<?php
2
3
/**
4
 * This file is part of the tarantool/client package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Tarantool\Client\Tests\Integration\Requests;
15
16
use Tarantool\Client\Exception\RequestFailed;
17
use Tarantool\Client\Schema\Criteria;
18
use Tarantool\Client\Schema\Operations;
19
use Tarantool\Client\Tests\Integration\TestCase;
20
21
/**
22
 * @lua space = create_space('request_upsert')
23
 * @lua space:create_index('primary', {type = 'hash', parts = {1, 'unsigned'}})
24
 */
25
final class UpsertTest extends TestCase
26
{
27
    public function testUpsert() : void
28
    {
29
        $space = $this->client->getSpace('request_upsert');
0 ignored issues
show
Bug introduced by
The method getSpace() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        /** @scrutinizer ignore-call */ 
30
        $space = $this->client->getSpace('request_upsert');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
31
        $key = 10;
32
        $values = [$key, 'upserted'];
33
        $operations = Operations::splice(1, 0, 1, 'U');
34
        $updatedValues = [$key, 'Upserted'];
35
36
        $space->upsert($values, $operations);
37
        self::assertSame([$values], $space->select(Criteria::key([$key])));
38
39
        $space->upsert($values, $operations);
40
        self::assertSame([$updatedValues], $space->select(Criteria::key([$key])));
41
    }
42
43
    public function testUpsertEmptyTuple() : void
44
    {
45
        $space = $this->client->getSpace('request_upsert');
46
47
        $this->expectException(RequestFailed::class);
48
        $this->expectExceptionCode(39); // ER_FIELD_MISSING
49
50
        $space->upsert([], Operations::set(1, 'Foo'));
51
    }
52
}
53