Skip to content

Commit

Permalink
V1.8 (#353)
Browse files Browse the repository at this point in the history
* added missing migration methods

* fixed errors with undefined method

* set 2.3.3 as minimum req for driver

* use fire instead of dispatch

* fix tests

Co-authored-by: Abed Halawi <[email protected]>
  • Loading branch information
transistive and Mulkave authored Dec 16, 2021
1 parent c7aa2aa commit 324fd57
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 33 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"illuminate/support": "^8.0",
"illuminate/pagination": "^8.0",
"nesbot/carbon": "^2.0",
"laudis/neo4j-php-client": "^2.2"
"laudis/neo4j-php-client": "^2.3.3"
},
"require-dev": {
"mockery/mockery": "~1.3.0",
Expand Down
15 changes: 5 additions & 10 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public function getDriverName()
* @param string $query
* @param array $bindings
*
* @return CypherList
* @return SummarizedResult
*/
public function select($query, $bindings = array())
{
Expand All @@ -539,11 +539,7 @@ public function select($query, $bindings = array())
$query = $me->getCypherQuery($query, $bindings);

/** @var SummarizedResult $results */
$summary = $this->getClient()->run($query['statement'], $query['parameters']);
/** @var CypherList $results */
$results = $summary->getResult();

return $results;
return $this->getClient()->run($query['statement'], $query['parameters']);
});
}

Expand Down Expand Up @@ -631,8 +627,7 @@ public function statement($query, $bindings = array(), $rawResults = false)
$query = $me->getCypherQuery($query, $bindings);

/** @var SummarizedResult $run */
$run = $this->getClient()->run($query['statement'], $query['parameters']);
$results = $run->getResult();
$results = $this->getClient()->run($query['statement'], $query['parameters']);

return ($rawResults === true) ? $results : true;
});
Expand Down Expand Up @@ -1083,7 +1078,7 @@ protected function reconnectIfMissingConnection()
public function logQuery($query, $bindings, $time = null)
{
if (isset($this->events)) {
$this->events->fire('illuminate.query', [$query, $bindings, $time, $this->getName()]);
$this->events->dispatch('illuminate.query', [$query, $bindings, $time, $this->getName()]);
}

if ($this->loggingQueries) {
Expand Down Expand Up @@ -1111,7 +1106,7 @@ public function listen(Closure $callback)
protected function fireConnectionEvent($event)
{
if (isset($this->events)) {
$this->events->fire('connection.'.$this->getName().'.'.$event, $this);
$this->events->dispatch('connection.'.$this->getName().'.'.$event, $this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Vinelab\NeoEloquent\Eloquent;

use BadMethodCallException;
use DateTime;
use Exception;
use ArrayAccess;
use Carbon\Carbon;
use LogicException;
use JsonSerializable;
use BadMethodCallException;
use Vinelab\NeoEloquent\Eloquent\Builder as EloquentBuilder;
use Vinelab\NeoEloquent\Eloquent\Relations\BelongsTo;
use Vinelab\NeoEloquent\Eloquent\Relations\BelongsToMany;
Expand Down
2 changes: 1 addition & 1 deletion src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public function update(array $values)

$bindings = $this->getBindingsMergedWithValues($values, true);

$updated = $this->connection->update($cypher, $bindings)->getResult();
$updated = $this->connection->update($cypher, $bindings);

return ($updated) ? count(current($this->getRecordsByPlaceholders($updated))) : 0;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function getNodeById($id)
/** @var SummarizedResult $result */
$result = $client->run("MATCH (n) WHERE id(n)=$id RETURN n");

return $result->getResult()->first()->first()->getValue();
return $result->first()->first()->getValue();
}

/**
Expand Down
17 changes: 10 additions & 7 deletions tests/Vinelab/NeoEloquent/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Laudis\Neo4j\Contracts\ClientInterface;
use Laudis\Neo4j\Databags\SummarizedResult;
use Laudis\Neo4j\Types\CypherList;
use Laudis\Neo4j\Types\CypherMap;
use Mockery as M;

class ConnectionTest extends TestCase
Expand Down Expand Up @@ -116,7 +117,7 @@ public function testLogQueryFiresEventsIfSet()
$connection = $this->getMockConnection();
$connection->logQuery('foo', array(), time());
$connection->setEventDispatcher($events = M::mock('Illuminate\Contracts\Events\Dispatcher'));
$events->shouldReceive('fire')->once()->with('illuminate.query', array('foo', array(), null, null));
$events->shouldReceive('dispatch')->once()->with('illuminate.query', array('foo', array(), null, null));
$connection->logQuery('foo', array(), null);

self::assertTrue(true);
Expand Down Expand Up @@ -331,16 +332,17 @@ public function testAffectingStatement()

$this->assertInstanceOf(SummarizedResult::class, $results);

/** @var CypherMap $result */
foreach ($results as $result) {
$count = $result[0];
$count = $result->first()->getValue();
$this->assertEquals(1, $count);
}

// Try to find the updated one and make sure it was updated successfully
$query = 'MATCH (n:User) WHERE n.username = $username RETURN n';
$cypher = $c->getCypherQuery($query, array('username' => $this->user['username']));

$results = $this->client->run($cypher['statement'], $cypher['parameters'])->getResult();
$results = $this->client->run($cypher['statement'], $cypher['parameters']);

$this->assertInstanceOf(CypherList::class, $results);

Expand Down Expand Up @@ -370,8 +372,9 @@ public function testAffectingStatementOnNonExistingRecord()

$this->assertInstanceOf(SummarizedResult::class, $results);

/** @var CypherMap $result */
foreach ($results as $result) {
$count = $result[0];
$count = $result->first()->getValue();
$this->assertEquals(0, $count);
}
}
Expand Down Expand Up @@ -432,7 +435,7 @@ public function testBeganTransactionFiresEventsIfSet()
$connection = $this->getMockConnection(array('getName'));
$connection->expects($this->once())->method('getName')->will($this->returnValue('name'));
$connection->setEventDispatcher($events = M::mock('Illuminate\Contracts\Events\Dispatcher'));
$events->shouldReceive('fire')->once()->with('connection.name.beganTransaction', $connection);
$events->shouldReceive('dispatch')->once()->with('connection.name.beganTransaction', $connection);
$connection->beginTransaction();
}

Expand All @@ -441,7 +444,7 @@ public function testCommitedFiresEventsIfSet()
$connection = $this->getMockConnection(array('getName'));
$connection->expects($this->once())->method('getName')->will($this->returnValue('name'));
$connection->setEventDispatcher($events = M::mock('Illuminate\Contracts\Events\Dispatcher'));
$events->shouldReceive('fire')->once()->with('connection.name.committed', $connection);
$events->shouldReceive('dispatch')->once()->with('connection.name.committed', $connection);
$connection->commit();
}

Expand All @@ -450,7 +453,7 @@ public function testRollBackedFiresEventsIfSet()
$connection = $this->getMockConnection(array('getName'));
$connection->expects($this->once())->method('getName')->will($this->returnValue('name'));
$connection->setEventDispatcher($events = M::mock('Illuminate\Contracts\Events\Dispatcher'));
$events->shouldReceive('fire')->once()->with('connection.name.rollingBack', $connection);
$events->shouldReceive('dispatch')->once()->with('connection.name.rollingBack', $connection);
$connection->rollback();
}

Expand Down
13 changes: 1 addition & 12 deletions tests/Vinelab/NeoEloquent/Query/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,7 @@ public function testInsertingAndGettingId()
$this->neoClient->shouldReceive('run')
->once()
->with($query['statement'], $query['parameters'])
->andReturn(new SummarizedResult($result, new ResultSummary(
new SummaryCounters(),
new DatabaseInfo(''),
new CypherList(),
null,
null,
new Statement($query['statement'], $query['parameters']),
QueryTypeEnum::READ_WRITE(),
0,
0,
new ServerInfo(Uri::create(), ConnectionProtocol::BOLT_V40(), 'agent')
)));
->andReturn(new CypherList($result));

$this->assertEquals($id, $this->builder->insertGetId($values));
}
Expand Down

0 comments on commit 324fd57

Please sign in to comment.