Skip to content

Commit 0abea75

Browse files
committed
Added tets
1 parent 3d782d6 commit 0abea75

File tree

11 files changed

+267
-1
lines changed

11 files changed

+267
-1
lines changed

Collector/Twig/Neo4jResultExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private function doGetType($object, $recursive):string
5454
$ret[] = $this->doGetType($o, false);
5555
}
5656

57-
return sprintf('[%s]', implode(',', $ret));
57+
return sprintf('[%s]', implode(', ', $ret));
5858
}
5959

6060
return is_object($object) ? get_class($object) : gettype($object);

Tests/Functional/BaseTestCase.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace GraphAware\Neo4jBundle\Tests\Functional;
4+
5+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6+
7+
class BaseTestCase extends WebTestCase
8+
{
9+
protected static function getKernelClass()
10+
{
11+
require_once __DIR__.'/app/AppKernel.php';
12+
13+
return 'GraphAware\Neo4jBundle\Tests\Functional\app\AppKernel';
14+
}
15+
16+
protected static function createKernel(array $options = [])
17+
{
18+
$class = self::getKernelClass();
19+
20+
return new $class(
21+
isset($options['config']) ? $options['config'] : 'default.yml'
22+
);
23+
}
24+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace GraphAware\Neo4jBundle\Tests\Functional;
4+
5+
use GraphAware\Neo4j\Client\ClientInterface;
6+
use GraphAware\Neo4j\Client\Connection\Connection;
7+
use GraphAware\Neo4j\OGM\EntityManager;
8+
9+
class BundleInitializationTest extends BaseTestCase
10+
{
11+
public function testRegisterBundle()
12+
{
13+
static::bootKernel();
14+
$container = static::$kernel->getContainer();
15+
$this->assertTrue($container->has('neo4j.connection'));
16+
$client = $container->get('neo4j.connection');
17+
$this->assertInstanceOf(Connection::class, $client);
18+
19+
$this->assertTrue($container->has('neo4j.client'));
20+
$client = $container->get('neo4j.client');
21+
$this->assertInstanceOf(ClientInterface::class, $client);
22+
23+
$this->assertTrue($container->has('neo4j.entity_manager'));
24+
$client = $container->get('neo4j.entity_manager');
25+
$this->assertInstanceOf(EntityManager::class, $client);
26+
}
27+
}

Tests/Functional/app/AppKernel.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace GraphAware\Neo4jBundle\Tests\Functional\app;
4+
5+
use GraphAware\Neo4jBundle\GraphAwareNeo4jBundle;
6+
use Symfony\Component\Config\Loader\LoaderInterface;
7+
use Symfony\Component\Filesystem\Filesystem;
8+
use Symfony\Component\HttpKernel\Kernel;
9+
10+
class AppKernel extends Kernel
11+
{
12+
private $config;
13+
14+
public function __construct($config)
15+
{
16+
parent::__construct('test', true);
17+
18+
$fs = new Filesystem();
19+
20+
if (!$fs->isAbsolutePath($config)) {
21+
$config = __DIR__.'/config/'.$config;
22+
}
23+
24+
if (!file_exists($config)) {
25+
throw new \RuntimeException(sprintf('The config file "%s" does not exist', $config));
26+
}
27+
28+
$this->config = $config;
29+
}
30+
31+
public function registerBundles()
32+
{
33+
return [
34+
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
35+
new GraphAwareNeo4jBundle(),
36+
];
37+
}
38+
39+
public function registerContainerConfiguration(LoaderInterface $loader)
40+
{
41+
$loader->load($this->config);
42+
}
43+
44+
public function getCacheDir()
45+
{
46+
return sys_get_temp_dir().'/GraphAwareNeo4jBundle';
47+
}
48+
49+
public function serialize()
50+
{
51+
return $this->config;
52+
}
53+
54+
public function unserialize($config)
55+
{
56+
$this->__construct($config);
57+
}
58+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
imports:
2+
- { resource: framework.yml }
3+
- { resource: services.yml }
4+
5+
graph_aware_neo4j:
6+
connections:
7+
default: ~
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
framework:
2+
secret: test
3+
test: ~
4+
session:
5+
storage_id: session.storage.mock_file
6+
form: false
7+
csrf_protection: false
8+
validation:
9+
enabled: false
10+
router:
11+
resource: "%kernel.root_dir%/config/routing.yml"
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
services:
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace GraphAware\Neo4jBundle\Tests\Unit\Collector;
4+
5+
use GraphAware\Bolt\Result\Result;
6+
use GraphAware\Common\Cypher\Statement;
7+
use GraphAware\Neo4j\Client\Exception\Neo4jException;
8+
use GraphAware\Neo4jBundle\Collector\DebugLogger;
9+
10+
class DebugLoggerTest extends \PHPUnit_Framework_TestCase
11+
{
12+
public function testCounter()
13+
{
14+
$o = new DebugLogger();
15+
$statement = Statement::create('foo');
16+
$o->addStatement($statement);
17+
$o->addResult(new Result($statement));
18+
19+
$o->addStatement($statement);
20+
$o->addException(new Neo4jException());
21+
22+
$statements = $o->getStatements();
23+
$results = $o->getResults();
24+
$exceptions = $o->getExceptions();
25+
26+
$this->assertTrue(isset($statements[1]));
27+
$this->assertTrue(isset($results[1]));
28+
$this->assertFalse(isset($exceptions[1]));
29+
30+
$this->assertTrue(isset($statements[2]));
31+
$this->assertFalse(isset($results[2]));
32+
$this->assertTrue(isset($exceptions[2]));
33+
34+
}
35+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace GraphAware\Neo4jBundle\Tests\Unit\Collector\Twig;
4+
5+
use GraphAware\Neo4j\Client\Formatter\Type\Node;
6+
use GraphAware\Neo4jBundle\Collector\Twig\Neo4jResultExtension;
7+
8+
/**
9+
* @author Tobias Nyholm <[email protected]>
10+
*/
11+
class Neo4jResultExtensionTest extends \PHPUnit_Framework_TestCase
12+
{
13+
public function testEmptyArray()
14+
{
15+
$o = new Neo4jResultExtension();
16+
$result = $o->getType(array());
17+
18+
$this->assertEquals('Empty array', $result);
19+
}
20+
21+
public function testObject()
22+
{
23+
$o = new Neo4jResultExtension();
24+
$result = $o->getType($o);
25+
26+
$this->assertEquals(Neo4jResultExtension::class, $result);
27+
}
28+
29+
public function testScalar()
30+
{
31+
$o = new Neo4jResultExtension();
32+
$result = $o->getType(3);
33+
34+
$this->assertEquals('integer', $result);
35+
}
36+
37+
public function testScalarArray()
38+
{
39+
$o = new Neo4jResultExtension();
40+
$result = $o->getType([3, 6.3]);
41+
42+
$this->assertEquals('[integer, double]', $result);
43+
}
44+
public function testArrayArray()
45+
{
46+
$o = new Neo4jResultExtension();
47+
$result = $o->getType([[]]);
48+
49+
$this->assertEquals('[array]', $result);
50+
}
51+
52+
public function testNote()
53+
{
54+
$o = new Neo4jResultExtension();
55+
$result = $o->getType(new Node('abc', ['Label'], []));
56+
57+
$this->assertEquals('abc: Label', $result);
58+
}
59+
}

0 commit comments

Comments
 (0)