Skip to content

Commit

Permalink
something
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosh committed Sep 29, 2016
1 parent 395d7d0 commit 7209301
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 29 deletions.
5 changes: 5 additions & 0 deletions howto
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- go to /releases/orientdb-community-2.0-M3/bin
- ./server.sh to start the server
- ./console.sh to start the console
- connet remote:localhost/mydb root password
- http://localhost:2480
18 changes: 18 additions & 0 deletions launcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use PhpOrient\PhpOrient;
use Marcosh\EventGraph\EventGraph;

require __DIR__.'/vendor/autoload.php';

$config = [
'hostname' => 'localhost',
'port' => 2424,
'username' => 'root',
'password' => 'password'
];
$client = new PhpOrient();
$client->configure($config);
$eventGraph = new EventGraph($client, 'mydb');

var_dump($eventGraph->getTagHistory('tag'));
2 changes: 1 addition & 1 deletion src/Event.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Marcosh\EventGraph;
namespace Marcosh\Eventgraph;

use PhpOrient\Protocols\Binary\Data\Record;

Expand Down
10 changes: 8 additions & 2 deletions src/EventGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct($client, $databaseName)
$client->dbOpen($databaseName);

$this->events = new Events($client);
$this->tags = new Tags($client);
$this->tags = new Tags($client, $this->events);
}

/**
Expand Down Expand Up @@ -88,6 +88,12 @@ public function saveEvent(Event $event)
*/
public function getTagHistory($tagName)
{
return $this->tags->getTagHistory($tagName);
$records = $this->tags->getTagHistory($tagName);

$events = $this->events;

return array_map(function ($record) use ($events) {
return $events->createFromRecord($record);
}, $records);
}
}
2 changes: 1 addition & 1 deletion src/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function saveEvent(Event $event)
* @param object record coming from the database
* @return Event
*/
private function createFromRecord(Record $record)
public function createFromRecord(Record $record)
{
$event = new Event();
$event->setRecord($record);
Expand Down
4 changes: 2 additions & 2 deletions src/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ public function saveTag($tag)

/**
* @param string
* @return array of Events
* @return array of Records
*/
public function getTagHistory($tagName)
{
$query = 'select expand(history) from Tag where name = "%tagName%"';
$data = ['%tagName%' => $tagName];
$events = $this->database->query(strtr($query, $data));

//TODO: hidrate events to Events
return $events;
}
}
76 changes: 53 additions & 23 deletions test/EventGraphTest.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,60 @@
<?php

/*namespace Marcosh\EventGraph;
namespace Marcosh\EventGraph;

use Marcosh\EventGraph\EventGraph;

class EventGraphTest extends \PHPUnit_Framework_TestCase
{
// private $client;
// private $eventGraph;
// public function setUp()
// {
// $this->client = \Mockery::mock();
// $this->client->shouldReceive('dbOpen');
// $this->eventGraph = new EventGraph($this->client, 'dbName');
// }
// public function tearDown()
// {
// \Mockery::close();
// }
// public function testCreateTag()
// {
// $tag = new Tag();
// $tag->setName('tag');
// $this->assertEquals($tag, $this->eventGraph->createTag('tag'));
// }
}*/
private $client;
private $eventGraph;

public function setUp()
{
$this->client = \Mockery::mock();
$this->client->shouldReceive('dbOpen');
$this->eventGraph = new EventGraph($this->client, 'dbName');
}

public function tearDown()
{
\Mockery::close();
}

public function testCreateTagAndPersist()
{

}

public function testCreateTagWithoutPersisting()
{
$tag = $this->eventGraph->createTag('tag', false);

$this->assertEquals('Tag', $tag->getRecord()->getOClass());
}

public function testSaveTag()
{

}

public function testGetTag()
{

}

public function testCreateEvent()
{

}

public function testSaveEvent()
{

}

public function testGetTagHistory()
{

}
}
12 changes: 12 additions & 0 deletions test/TagsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ class TagsTest extends \PHPUnit_Framework_TestCase
{
private $sut;

private $events;

private $database;

public function setUp()
{
$this->database = \Mockery::mock();
$this->sut = new Tags($this->database);
$this->events = new Events($this->database);
}

public function tearDown()
Expand Down Expand Up @@ -107,4 +110,13 @@ public function testSaveTagWithoutHistory()

$this->sut->saveTag($tag);
}

public function testGetTagHistory()
{
$tag = $this->sut->createTag('tag');
$event1 = $this->events->createEvent('event1', $tag);
$event2 = $this->events->createEvent('event2', $tag);

$this->database->shouldReceive('select expand(history) from Tag where name = "tag"');
}
}

0 comments on commit 7209301

Please sign in to comment.