Skip to content

Commit

Permalink
Add initial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Aschmann committed Jun 12, 2016
1 parent 3eeff80 commit ecd9d3b
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 41 deletions.
37 changes: 0 additions & 37 deletions Common/AbstractComponent.php

This file was deleted.

6 changes: 2 additions & 4 deletions Flow/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
use Asm\PhpFloBundle\Common\BuilderInterface;
use Asm\PhpFloBundle\Common\NetworkInterface;
use Asm\PhpFloBundle\Common\RegistryInterface;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use PhpFlo\Graph;
use Symfony\Component\Finder\Finder;

/**
* Class Builder
Expand Down Expand Up @@ -52,7 +50,7 @@ public function __construct(RegistryInterface $registry, $rootDir)
*
* @param string $fileName
* @return NetworkInterface
* @throws InvalidArgumentException
* @throws \InvalidArgumentException
*/
public function fromFile($fileName)
{
Expand All @@ -61,7 +59,7 @@ public function fromFile($fileName)
if (file_exists($fileUri)) {
$graph = file_get_contents($fileUri);
} else {
throw new InvalidArgumentException('Could not find file ' . $fileUri);
throw new \InvalidArgumentException('Could not find file ' . $fileUri);
}

return $this->fromString($graph);
Expand Down
1 change: 1 addition & 0 deletions Flow/Network.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Network implements NetworkInterface
* Network constructor.
*
* @param Graph $graph
* @param RegistryInterface $registry
*/
public function __construct(Graph $graph, RegistryInterface $registry)
{
Expand Down
66 changes: 66 additions & 0 deletions Tests/Flow/ComponentRegistryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/*
* This file is part of the asm/phpflo-bundle package.
*
* (c) Marc Aschmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Tests\Flow;


use Asm\PhpFloBundle\Flow\ComponentRegistry;
use PhpFlo\ComponentInterface;

/**
* Class ComponentRegistryTest
*
* @package Tests\Flow
* @author Marc Aschmann <[email protected]>
*/
class ComponentRegistryTest extends \PHPUnit_Framework_TestCase
{
public function testGetReference()
{
$componentMock = $this->createMock('\PhpFlo\ComponentInterface');
$registry = $this->createRegistry();
$registry->addReference($componentMock, 'component_1');

$component = $registry->getReference('component_1');
$this->assertInstanceOf('\PhpFlo\ComponentInterface', $component, 'addReference failed');
}

public function testGetReferences()
{
$componentMock = $this->createMock('\PhpFlo\ComponentInterface');
$registry = $this->createRegistry();
$registry
->addReference($componentMock, 'component_1')
->addReference($componentMock, 'component_2');

$references = $registry->getReferences();

$this->assertTrue(is_array($references));
$this->assertArrayHasKey('component_1', $references, 'registry key for component_1 not found');
$this->assertArrayHasKey('component_2', $references, 'registry key for component_2 not found');
}

public function testRemoveReference()
{
$componentMock = $this->createMock('\PhpFlo\ComponentInterface');
$registry = $this->createRegistry();
$registry->addReference($componentMock, 'component_1');
$component = $registry->getReference('component_1');
$this->assertInstanceOf('\PhpFlo\ComponentInterface', $component, 'addReference failed');
$registry->removeReference('component_1');
$result = $registry->getReference('component_1');
$this->assertFalse($result, 'reference was not removed');
}

private function createRegistry()
{
return new ComponentRegistry();
}
}
42 changes: 42 additions & 0 deletions Tests/Flow/NetworkTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/*
* This file is part of the asm/phpflo-bundle package.
*
* (c) Marc Aschmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Tests\Flow;

use Asm\PhpFloBundle\Flow\Network;
use PhpFlo\Graph;

/**
* Class NetworkTest
*
* @package Tests\Flow
* @author Marc Aschmann <[email protected]>
*/
class NetworkTest extends \PHPUnit_Framework_TestCase
{
public function testCreate()
{
// no interface for mocking available, constructor needs argument
$graph = new Graph('test');//$this->getMockBuilder('\PhpFlo\Graph')->getMock();
$registry = $this->getMockBuilder('\Asm\PhpFloBundle\Common\RegistryInterface')->getMock();

$network = Network::create($graph, $registry);

$this->assertInstanceOf('\Asm\PhpFloBundle\Flow\Network', $network);
}

private function createNetwork()
{
$graph = $graph = new Graph('test');
$registry = $this->getMockBuilder('\Asm\PhpFloBundle\Common\RegistryInterface')->getMock();

$network = new Network($graph, $registry);
}
}
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"phpflo/phpflo": "dev-master",
"asm/php-utilities": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^5.4"
},
"license": "MIT",
"authors": [
{
Expand Down
35 changes: 35 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./vendor/autoload.php"
>
<php>
<server name="KERNEL_DIR" value="Tests/App" />
</php>
<testsuites>
<testsuite name="PhpFloBundle testsuite">
<directory suffix="Test.php">./Tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Common</directory>
<directory>./DependencyInjection</directory>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

0 comments on commit ecd9d3b

Please sign in to comment.