Skip to content

Commit 45c0508

Browse files
committed
Make test more deterministic
1 parent 79d9f13 commit 45c0508

File tree

2 files changed

+61
-8
lines changed

2 files changed

+61
-8
lines changed

test/unit/mongo/MongoTripodViewsTest.php

+60-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use \Tripod\Mongo\Composites\Views;
88
use \MongoDB\Client;
9+
use Tripod\ExtendedGraph;
910

1011
class MongoTripodViewsTest extends MongoTripodTestBase {
1112
/**
@@ -521,14 +522,15 @@ public function testGenerateViewWithTTL()
521522
$this->assertInstanceOf('\MongoDB\BSON\UTCDateTime', $actualView['_cts']);
522523
}
523524

524-
public function testGenerateViewWithNegativeTTL()
525+
public function testNonExpiringViewWithNegativeTTL()
525526
{
526-
/** @var \Tripod\Mongo\Composites\Views|PHPUnit_Framework_MockObject_MockObject $mockTripodViews */
527-
$mockTripodViews = $this->getMockBuilder('\Tripod\Mongo\Composites\Views')
528-
->setConstructorArgs($this->viewsConstParams)
529-
->getMock();
527+
$views = new \Tripod\Mongo\Composites\Views(
528+
$this->viewsConstParams[0],
529+
$this->viewsConstParams[1],
530+
$this->viewsConstParams[2]
531+
);
530532

531-
$view = $mockTripodViews->getViewForResource(
533+
$view = $views->getViewForResource(
532534
'http://talisaspire.com/events/1234',
533535
'v_event_no_expiration'
534536
);
@@ -575,9 +577,59 @@ public function testGenerateViewWithNegativeTTL()
575577
]
576578
]
577579
);
578-
$this->assertEquals($expectedView['_id'], $actualView['_id']);
579-
$this->assertEquals($expectedView['value'], $actualView['value']);
580+
$this->assertEquals(
581+
$expectedView['_id'],
582+
$actualView['_id'],
583+
'_id does not match expected',
584+
0.0,
585+
10,
586+
true
587+
);
588+
$this->assertContains(
589+
$expectedView['value'][_GRAPHS][0],
590+
$actualView['value'][_GRAPHS]
591+
);
592+
$this->assertContains(
593+
$expectedView['value'][_GRAPHS][1],
594+
$actualView['value'][_GRAPHS]
595+
);
596+
$this->assertCount(2, $actualView['value'][_GRAPHS]);
597+
$this->assertArrayNotHasKey(_EXPIRES, $actualView['value']);
598+
$this->assertArrayNotHasKey(_IMPACT_INDEX, $actualView['value']);
580599
$this->assertInstanceOf('\MongoDB\BSON\UTCDateTime', $actualView['_cts']);
600+
601+
// Fetch the joined resource and change it
602+
$graph = $this->tripod->describeResource('http://talisaspire.com/resources/1234');
603+
604+
$updatedGraph = new ExtendedGraph($graph->to_ntriples());
605+
$updatedGraph->replace_literal_triple(
606+
'http://talisaspire.com/resources/1234',
607+
'http://purl.org/dc/terms/title',
608+
'A real piece of work',
609+
'A literal treasure'
610+
);
611+
612+
// This should not affect the view at all
613+
$this->tripod->saveChanges($graph, $updatedGraph);
614+
615+
$view = $views->getViewForResource(
616+
'http://talisaspire.com/events/1234',
617+
'v_event_no_expiration'
618+
);
619+
620+
// get the view direct from mongo, it should the same as earlier
621+
$actualView2 = \Tripod\Mongo\Config::getInstance()
622+
->getCollectionForView('tripod_php_testing', 'v_event_no_expiration')
623+
->findOne(
624+
[
625+
'_id' => [
626+
'r' => 'http://talisaspire.com/events/1234',
627+
'c' => 'http://talisaspire.com/',
628+
'type' => 'v_event_no_expiration'
629+
]
630+
]
631+
);
632+
$this->assertEquals($actualView, $actualView2);
581633
}
582634

583635
/**

test/unit/mongo/data/config.json

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@
227227
"from": "CBD_testing",
228228
"type": "dctype:Event",
229229
"ttl": -1,
230+
"include": ["rdf:type", "dct:created", "dct:title", "dct:references"],
230231
"joins": {
231232
"dct:references" : {
232233
"include": ["dct:title", "dct:creator"]

0 commit comments

Comments
 (0)