expectException(common_Exception::class); $this->expectExceptionMessage('Not implemented'); $prophet = new Prophet(); $persistence = $prophet->prophesize('\common_persistence_SqlPersistence'); $model = $prophet->prophesize('\core_kernel_persistence_smoothsql_SmoothModel'); $model->getPersistence()->willReturn($persistence->reveal()); $rdf = new core_kernel_persistence_smoothsql_SmoothRdf($model->reveal()); $rdf->get(null, null); } /** * @author Lionel Lecaque, lionel@taotesting.com */ public function testSearch() { $this->expectException(common_Exception::class); $this->expectExceptionMessage('Not implemented'); $prophet = new Prophet(); $persistence = $prophet->prophesize('\common_persistence_SqlPersistence'); $model = $prophet->prophesize('\core_kernel_persistence_smoothsql_SmoothModel'); $model->getPersistence()->willReturn($persistence->reveal()); $rdf = new core_kernel_persistence_smoothsql_SmoothRdf($model->reveal()); $rdf->search(null, null); } /** * * @author Lionel Lecaque, lionel@taotesting.com */ public function testAdd() { $platform = $this->prophesize('\common_persistence_sql_Platform'); $platform->getNowExpression()->willReturn('now'); $persistence = $this->prophesize('\common_persistence_SqlPersistence'); $persistence->getPlatForm()->willReturn($platform->reveal()); $query = "INSERT INTO statements ( modelId, subject, predicate, object, l_language, epoch, author) VALUES ( ? , ? , ? , ? , ? , ?, ?);"; $triple = new \core_kernel_classes_Triple(); $triple->modelid = 22; $triple->subject = 'subjectUri'; $triple->predicate = 'predicateUri'; $triple->object = 'objectUri'; $persistence->exec( $query, [ 22, 'subjectUri', 'predicateUri', 'objectUri', '', 'now', '' ], $this->getExpectedTripleParameterTypes() )->shouldBeCalled()->willReturn(true); $model = $this->prophesize('\core_kernel_persistence_smoothsql_SmoothModel'); $model->getPersistence()->willReturn($persistence->reveal()); $rdf = new core_kernel_persistence_smoothsql_SmoothRdf($model->reveal()); $this->assertTrue($rdf->add($triple)); } /** * * @author Lionel Lecaque, lionel@taotesting.com */ public function testAddWithAuthor() { $platform = $this->prophesize('\common_persistence_sql_Platform'); $platform->getNowExpression()->willReturn('now'); $persistence = $this->prophesize('\common_persistence_SqlPersistence'); $persistence->getPlatForm()->willReturn($platform->reveal()); $query = "INSERT INTO statements ( modelId, subject, predicate, object, l_language, epoch, author) VALUES ( ? , ? , ? , ? , ? , ?, ?);"; $triple = new \core_kernel_classes_Triple(); $triple->modelid = 22; $triple->subject = 'subjectUri'; $triple->predicate = 'predicateUri'; $triple->object = 'objectUri'; $triple->author = 'JohnDoe'; $persistence->exec( $query, [ 22, 'subjectUri', 'predicateUri', 'objectUri', '', 'now', 'JohnDoe' ], $this->getExpectedTripleParameterTypes() )->shouldBeCalled()->willReturn(true); $model = $this->prophesize('\core_kernel_persistence_smoothsql_SmoothModel'); $model->getPersistence()->willReturn($persistence->reveal()); $rdf = new core_kernel_persistence_smoothsql_SmoothRdf($model->reveal()); $this->assertTrue($rdf->add($triple)); } /** * * @author Lionel Lecaque, lionel@taotesting.com */ public function testRemove() { $prophet = new Prophet(); $persistence = $prophet->prophesize('\common_persistence_SqlPersistence'); $query = "DELETE FROM statements WHERE subject = ? AND predicate = ? AND object = ? AND l_language = ?;"; $triple = new \core_kernel_classes_Triple(); $triple->modelid = 22; $triple->subject = 'subjectUri'; $triple->predicate = 'predicateUri'; $triple->object = 'objectUri'; $persistence->exec($query, [ 'subjectUri', 'predicateUri', 'objectUri', '' ])->shouldBeCalled()->willReturn(true); $model = $prophet->prophesize('\core_kernel_persistence_smoothsql_SmoothModel'); $model->getPersistence()->willReturn($persistence->reveal()); $rdf = new core_kernel_persistence_smoothsql_SmoothRdf($model->reveal()); $this->assertTrue($rdf->remove($triple)); } public function testAddTripleCollection() { $platform = $this->prophesize('\common_persistence_sql_Platform'); $platform->getNowExpression()->willReturn('now'); $persistence = $this->prophesize('\common_persistence_SqlPersistence'); $persistence->getPlatForm()->willReturn($platform->reveal()); $table = 'statements'; $triple1 = new \core_kernel_classes_Triple(); $triple1->modelid = 11; $triple1->subject = 'subjectUri1'; $triple1->predicate = 'predicateUri1'; $triple1->object = 'objectUri1'; $triple1->author = ''; $triple2 = new \core_kernel_classes_Triple(); $triple2->modelid = 22; $triple2->subject = 'subjectUri2'; $triple2->predicate = 'predicateUri2'; $triple2->object = 'objectUri2'; $triple2->author = 'JohnDoe2'; $triples = [$triple1, $triple2]; $types = $this->getExpectedTripleParameterTypes(); array_push($types, ...$types); $expectedValue = [ [ 'modelid' => 11, 'subject' => 'subjectUri1', 'predicate' => 'predicateUri1', 'object' => 'objectUri1', 'l_language' => '', 'author' => '', 'epoch' => 'now', ], [ 'modelid' => 22, 'subject' => 'subjectUri2', 'predicate' => 'predicateUri2', 'object' => 'objectUri2', 'l_language' => '', 'author' => 'JohnDoe2', 'epoch' => 'now', ] ]; $persistence->insertMultiple( Argument::exact($table), Argument::exact($expectedValue), Argument::exact($types) )->shouldBeCalled(); $model = $this->prophesize('\core_kernel_persistence_smoothsql_SmoothModel'); $model->getPersistence()->willReturn($persistence->reveal()); $rdf = new core_kernel_persistence_smoothsql_SmoothRdf($model->reveal()); $rdf->addTripleCollection($triples); } protected function getExpectedTripleParameterTypes() { return [ ParameterType::INTEGER, ParameterType::STRING, ParameterType::STRING, ParameterType::STRING, ParameterType::STRING, ParameterType::STRING, ParameterType::STRING, ]; } }