Passed
Push — extract-store ( 70fc7f...d338ce )
by Konrad
04:40
created

testInsertSaftRegressionTest1()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 15
rs 9.9666
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the sweetrdf/InMemoryStoreSqlite package and licensed under
5
 * the terms of the GPL-3 license.
6
 *
7
 * (c) Konrad Abicht <[email protected]>
8
 * (c) Benjamin Nowack
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Tests\Integration\Store;
15
16
use sweetrdf\InMemoryStoreSqlite\Log\LoggerPool;
17
use sweetrdf\InMemoryStoreSqlite\PDOSQLiteAdapter;
18
use sweetrdf\InMemoryStoreSqlite\Store\InMemoryStoreSqlite;
19
use Tests\TestCase;
20
21
class InMemoryStoreSqliteTest extends TestCase
22
{
23
    protected function setUp(): void
24
    {
25
        parent::setUp();
26
27
        $this->subjectUnderTest = new InMemoryStoreSqlite(new PDOSQLiteAdapter(), new LoggerPool());
28
    }
29
30
    /*
31
     * Tests for createInstance
32
     */
33
34
    public function testCreateInstance()
35
    {
36
        $this->assertEquals(
37
            InMemoryStoreSqlite::createInstance(),
38
            new InMemoryStoreSqlite(new PDOSQLiteAdapter(), new LoggerPool())
39
        );
40
    }
41
42
    /*
43
     * Tests for delete
44
     */
45
46
    public function testDelete()
47
    {
48
        // test data
49
        $this->subjectUnderTest->query('INSERT INTO <http://example.com/> {
50
            <http://s> <http://p1> "baz" .
51
            <http://s> <http://xmlns.com/foaf/0.1/name> "label1" .
52
        }');
53
54
        $res = $this->subjectUnderTest->query('SELECT * WHERE {?s ?p ?o.}');
55
        $this->assertEquals(2, \count($res['result']['rows']));
56
57
        // remove graph
58
        $this->subjectUnderTest->delete(false, 'http://example.com/');
59
60
        $res = $this->subjectUnderTest->query('SELECT * WHERE {?s ?p ?o.}');
61
        $this->assertEquals(0, \count($res['result']['rows']));
62
    }
63
64
    /*
65
     * Tests for getDBVersion
66
     */
67
68
    /**
69
     * just check pattern
70
     */
71
    public function testGetDBVersion()
72
    {
73
        $pattern = '/[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}/';
74
        $result = preg_match($pattern, $this->subjectUnderTest->getDBVersion(), $match);
75
        $this->assertEquals(1, $result);
76
    }
77
78
    /**
79
     * https://github.com/SaftIng/Saft/tree/master/src/Saft/Addition/ARC2
80
     *
81
     * @group linux
82
     */
83
    public function testInsertSaftRegressionTest1()
84
    {
85
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://example.com/> WHERE { ?s ?p ?o. } ');
86
        $this->assertEquals(0, \count($res['result']['rows']));
87
88
        $this->subjectUnderTest->insert(
89
            file_get_contents($this->rootPath.'/data/nt/saft-arc2-addition-regression1.nt'),
90
            'http://example.com/'
91
        );
92
93
        $res1 = $this->subjectUnderTest->query('SELECT * FROM <http://example.com/> WHERE { ?s ?p ?o. } ');
94
        $this->assertEquals(442, \count($res1['result']['rows']));
95
96
        $res2 = $this->subjectUnderTest->query('SELECT * WHERE { ?s ?p ?o. } ');
97
        $this->assertEquals(442, \count($res2['result']['rows']));
98
    }
99
100
    /**
101
     * This test checks gathering of freshly created resources.
102
     */
103
    public function testInsertSaftRegressionTest2()
104
    {
105
        $res = $this->subjectUnderTest->query('INSERT INTO <http://localhost/Saft/TestGraph/> {<http://foo/1> <http://foo/2> <http://foo/3> . }');
0 ignored issues
show
Unused Code introduced by
The assignment to $res is dead and can be removed.
Loading history...
106
107
        $res1 = $this->subjectUnderTest->query('SELECT * FROM <http://localhost/Saft/TestGraph/> WHERE {?s ?p ?o.}');
108
        $this->assertEquals(1, \count($res1['result']['rows']));
109
110
        $res2 = $this->subjectUnderTest->query('SELECT * WHERE {?s ?p ?o.}');
111
        $this->assertEquals(1, \count($res2['result']['rows']));
112
113
        $res2 = $this->subjectUnderTest->query('SELECT ?s ?p ?o WHERE {?s ?p ?o.}');
114
        $this->assertEquals(1, \count($res2['result']['rows']));
115
    }
116
117
    /**
118
     * This test checks side effects of update operations on different graphs.
119
     *
120
     * We add 1 triple to 1 and another to another graph.
121
     * Afterwards first graph is removed.
122
     * In the end second graph still should contain its triples.
123
     */
124
    public function testInsertSaftRegressionTest3()
125
    {
126
        $this->subjectUnderTest->query(
127
            'INSERT INTO <http://localhost/Saft/TestGraph/> {<http://localhost/Saft/TestGraph/> <http://localhost/Saft/TestGraph/> <http://localhost/Saft/TestGraph/> . }'
128
        );
129
        $this->subjectUnderTest->query(
130
            'INSERT INTO <http://second-graph/> {<http://second-graph/0> <http://second-graph/1> <http://second-graph/2> . }'
131
        );
132
        $this->subjectUnderTest->query(
133
            'DELETE FROM <http://localhost/Saft/TestGraph/>'
134
        );
135
136
        $res = $this->subjectUnderTest->query('SELECT * FROM <http://second-graph/> WHERE {?s ?p ?o.}');
137
        $this->assertEquals(1, \count($res['result']['rows']));
138
    }
139
}
140