Skip to content

Commit ecd9d3b

Browse files
author
Marc Aschmann
committed
Add initial tests
1 parent 3eeff80 commit ecd9d3b

File tree

7 files changed

+149
-41
lines changed

7 files changed

+149
-41
lines changed

Common/AbstractComponent.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

Flow/Builder.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
use Asm\PhpFloBundle\Common\BuilderInterface;
1414
use Asm\PhpFloBundle\Common\NetworkInterface;
1515
use Asm\PhpFloBundle\Common\RegistryInterface;
16-
use Doctrine\DBAL\Exception\InvalidArgumentException;
1716
use PhpFlo\Graph;
18-
use Symfony\Component\Finder\Finder;
1917

2018
/**
2119
* Class Builder
@@ -52,7 +50,7 @@ public function __construct(RegistryInterface $registry, $rootDir)
5250
*
5351
* @param string $fileName
5452
* @return NetworkInterface
55-
* @throws InvalidArgumentException
53+
* @throws \InvalidArgumentException
5654
*/
5755
public function fromFile($fileName)
5856
{
@@ -61,7 +59,7 @@ public function fromFile($fileName)
6159
if (file_exists($fileUri)) {
6260
$graph = file_get_contents($fileUri);
6361
} else {
64-
throw new InvalidArgumentException('Could not find file ' . $fileUri);
62+
throw new \InvalidArgumentException('Could not find file ' . $fileUri);
6563
}
6664

6765
return $this->fromString($graph);

Flow/Network.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class Network implements NetworkInterface
5656
* Network constructor.
5757
*
5858
* @param Graph $graph
59+
* @param RegistryInterface $registry
5960
*/
6061
public function __construct(Graph $graph, RegistryInterface $registry)
6162
{
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/*
3+
* This file is part of the asm/phpflo-bundle package.
4+
*
5+
* (c) Marc Aschmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Tests\Flow;
12+
13+
14+
use Asm\PhpFloBundle\Flow\ComponentRegistry;
15+
use PhpFlo\ComponentInterface;
16+
17+
/**
18+
* Class ComponentRegistryTest
19+
*
20+
* @package Tests\Flow
21+
* @author Marc Aschmann <[email protected]>
22+
*/
23+
class ComponentRegistryTest extends \PHPUnit_Framework_TestCase
24+
{
25+
public function testGetReference()
26+
{
27+
$componentMock = $this->createMock('\PhpFlo\ComponentInterface');
28+
$registry = $this->createRegistry();
29+
$registry->addReference($componentMock, 'component_1');
30+
31+
$component = $registry->getReference('component_1');
32+
$this->assertInstanceOf('\PhpFlo\ComponentInterface', $component, 'addReference failed');
33+
}
34+
35+
public function testGetReferences()
36+
{
37+
$componentMock = $this->createMock('\PhpFlo\ComponentInterface');
38+
$registry = $this->createRegistry();
39+
$registry
40+
->addReference($componentMock, 'component_1')
41+
->addReference($componentMock, 'component_2');
42+
43+
$references = $registry->getReferences();
44+
45+
$this->assertTrue(is_array($references));
46+
$this->assertArrayHasKey('component_1', $references, 'registry key for component_1 not found');
47+
$this->assertArrayHasKey('component_2', $references, 'registry key for component_2 not found');
48+
}
49+
50+
public function testRemoveReference()
51+
{
52+
$componentMock = $this->createMock('\PhpFlo\ComponentInterface');
53+
$registry = $this->createRegistry();
54+
$registry->addReference($componentMock, 'component_1');
55+
$component = $registry->getReference('component_1');
56+
$this->assertInstanceOf('\PhpFlo\ComponentInterface', $component, 'addReference failed');
57+
$registry->removeReference('component_1');
58+
$result = $registry->getReference('component_1');
59+
$this->assertFalse($result, 'reference was not removed');
60+
}
61+
62+
private function createRegistry()
63+
{
64+
return new ComponentRegistry();
65+
}
66+
}

Tests/Flow/NetworkTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/*
3+
* This file is part of the asm/phpflo-bundle package.
4+
*
5+
* (c) Marc Aschmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace Tests\Flow;
12+
13+
use Asm\PhpFloBundle\Flow\Network;
14+
use PhpFlo\Graph;
15+
16+
/**
17+
* Class NetworkTest
18+
*
19+
* @package Tests\Flow
20+
* @author Marc Aschmann <[email protected]>
21+
*/
22+
class NetworkTest extends \PHPUnit_Framework_TestCase
23+
{
24+
public function testCreate()
25+
{
26+
// no interface for mocking available, constructor needs argument
27+
$graph = new Graph('test');//$this->getMockBuilder('\PhpFlo\Graph')->getMock();
28+
$registry = $this->getMockBuilder('\Asm\PhpFloBundle\Common\RegistryInterface')->getMock();
29+
30+
$network = Network::create($graph, $registry);
31+
32+
$this->assertInstanceOf('\Asm\PhpFloBundle\Flow\Network', $network);
33+
}
34+
35+
private function createNetwork()
36+
{
37+
$graph = $graph = new Graph('test');
38+
$registry = $this->getMockBuilder('\Asm\PhpFloBundle\Common\RegistryInterface')->getMock();
39+
40+
$network = new Network($graph, $registry);
41+
}
42+
}

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"phpflo/phpflo": "dev-master",
99
"asm/php-utilities": "^2.0"
1010
},
11+
"require-dev": {
12+
"phpunit/phpunit": "^5.4"
13+
},
1114
"license": "MIT",
1215
"authors": [
1316
{

phpunit.xml.dist

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
bootstrap="./vendor/autoload.php"
13+
>
14+
<php>
15+
<server name="KERNEL_DIR" value="Tests/App" />
16+
</php>
17+
<testsuites>
18+
<testsuite name="PhpFloBundle testsuite">
19+
<directory suffix="Test.php">./Tests</directory>
20+
</testsuite>
21+
</testsuites>
22+
23+
<filter>
24+
<whitelist>
25+
<directory>./</directory>
26+
<exclude>
27+
<directory>./Common</directory>
28+
<directory>./DependencyInjection</directory>
29+
<directory>./Resources</directory>
30+
<directory>./Tests</directory>
31+
<directory>./vendor</directory>
32+
</exclude>
33+
</whitelist>
34+
</filter>
35+
</phpunit>

0 commit comments

Comments
 (0)