Skip to content

Commit

Permalink
Fix namespaces, adjust tests to independent of concrete components
Browse files Browse the repository at this point in the history
  • Loading branch information
maschmann committed Apr 14, 2017
1 parent 1f939a3 commit bbb5d2f
Show file tree
Hide file tree
Showing 23 changed files with 88 additions and 116 deletions.
24 changes: 9 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
Expand All @@ -10,28 +10,22 @@
>

<php>
<ini name="error_reporting" value="-1" />
<ini name="intl.default_locale" value="en" />
<ini name="intl.error_level" value="0" />
<ini name="memory_limit" value="-1" />
</php>

<testsuites>
<testsuites>
<testsuite name="PhpFlo Test Suite">
<directory>./src/PhpFlo/*/Tests/</directory>
<directory>./src/PhpFlo/*/*/Tests/</directory>
</testsuite>
</testsuites>
<testsuite name="PhpFlo Test Suite">
<directory>src/PhpFlo/*/Tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/PhpFlo/</directory>
<directory>src/PhpFlo/*</directory>
<exclude>
<directory>./src/PhpFlo/*/Tests</directory>
<directory>./src/PhpFlo/*/*/Tests</directory>
<directory>./src/PhpFlo/*/vendor</directory>
<directory>./src/PhpFlo/*/bin</directory>
<directory>src/PhpFlo/*/Tests</directory>
<directory>src/PhpFlo/*/Test</directory>
<directory>src/PhpFlo/*/vendor</directory>
<directory>src/PhpFlo/*/bin</directory>
</exclude>
</whitelist>
</filter>
Expand Down
2 changes: 1 addition & 1 deletion src/PhpFlo/Common/ComponentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
declare(strict_types=1);
namespace PhpFlo\Common;

use PhpFlo\Interaction\PortRegistry;
use PhpFlo\Core\Interaction\PortRegistry;

/**
* Interface ComponentInterface
Expand Down
2 changes: 1 addition & 1 deletion src/PhpFlo/Common/NetworkInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
declare(strict_types=1);
namespace PhpFlo\Common;

use PhpFlo\Graph;
use PhpFlo\Core\Graph;

/**
* Interface NetworkInterface
Expand Down
31 changes: 0 additions & 31 deletions src/PhpFlo/Common/phpunit.xml.dist

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace PhpFlo\Common;
namespace PhpFlo\Core;

use PhpFlo\Common\NetworkInterface;

/**
* Class AbstractNetworkDecorator
*
* @package PhpFlo\Common
* @package PhpFlo\Core
* @author Marc Aschmann <maschmann@gmail.com>
*/
abstract class AbstractNetworkDecorator implements NetworkInterface
Expand Down
1 change: 0 additions & 1 deletion src/PhpFlo/Core/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace PhpFlo\Core;

use PhpFlo\Common\ComponentInterface;
use PhpFlo\Common\ComponentTrait;

/**
* Class Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace PhpFlo\Common;
namespace PhpFlo\Core;

use PhpFlo\Interaction\PortRegistry;
use PhpFlo\Common\ComponentInterface;
use PhpFlo\Core\Interaction\PortRegistry;

/**
* Class ComponentTrait
*
* @package PhpFlo\Common
* @package PhpFlo\Core
* @author Marc Aschmann <maschmann@gmail.com>
*/
trait ComponentTrait
Expand Down Expand Up @@ -70,7 +71,7 @@ public function outPorts() : PortRegistry
/**
* @return ComponentInterface
*/
public function shutdown()
public function shutdown() : ComponentInterface
{
foreach ($this->inPorts()->get() as $port) {
$port->emit('shutdown', [$port]);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpFlo/Core/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use PhpFlo\Common\NetworkInterface as Net;
use PhpFlo\Common\Exception\InvalidDefinitionException;
use PhpFlo\Fbp\FbpParser;
use PhpFlo\Loader\Loader;
use PhpFlo\Fbp\Loader\Loader;

/**
* Analyzes and creates definitions from flow graph file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace PhpFlo\Common;
namespace PhpFlo\Core;

use PhpFlo\Common\Exception\FlowException;
use PhpFlo\Common\Exception\InvalidTypeException;
use PhpFlo\Common\NetworkInterface as Net;
use PhpFlo\Common\SocketInterface;

/**
* Class HookableNetworkTrait
*
* @package PhpFlo\Common
* @package PhpFlo\Core
* @author Marc Aschmann <maschmann@gmail.com>
*/
trait HookableNetworkTrait
Expand Down
1 change: 0 additions & 1 deletion src/PhpFlo/Core/Network.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace PhpFlo\Core;

use PhpFlo\Common\ComponentBuilderInterface;
use PhpFlo\Common\HookableNetworkTrait;
use PhpFlo\Common\NetworkInterface;
use PhpFlo\Common\SocketInterface;
use PhpFlo\Common\Exception\FlowException;
Expand Down
2 changes: 2 additions & 0 deletions src/PhpFlo/Core/Test/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
namespace PhpFlo\Core\Test;

use PhpFlo\Common\Test\TestUtilityTrait;

/**
* Class TestCase
*
Expand Down
39 changes: 0 additions & 39 deletions src/PhpFlo/Core/Tests/Builder/ComponentDiFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,43 +52,4 @@ public function testInvalidComponent()

$diFinder->build('SomeInvalidComponent');
}

/**
* Will create a stub with several methods and defined return values.
* definition:
* [
* 'myMethod' => 'somevalue',
* 'myOtherMethod' => $callback,
* 'anotherMethod' => function ($x) use ($y) {},
* ]
*
* @param string $class
* @param array $methods
* @param string $className classname for mock object
* @return \PHPUnit_Framework_MockObject_MockObject
*/
private function stub($class, array $methods = [], $className = '')
{
$builder = $this->getMockBuilder($class)
->disableOriginalConstructor();

if (!empty($methods)) {
$builder->setMethods(array_keys($methods));
}

if ('' !== $className) {
$builder->setMockClassName($className);
}

$stub = $builder->getMock();
foreach ($methods as $method => $value) {
if (is_callable($value)) {
$stub->expects($this->any())->method($method)->willReturnCallback($value);
} else {
$stub->expects($this->any())->method($method)->willReturn($value);
}
}

return $stub;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace PhpFlo\Common\Tests;
namespace PhpFlo\Core\Tests;

use PhpFlo\Common\ComponentTrait;
use PhpFlo\Core\ComponentTrait;
use PhpFlo\Common\Test\TestUtilityTrait;
use PhpFlo\Interaction\PortRegistry;
use PhpFlo\Core\Interaction\PortRegistry;

class ComponentTraitTest extends \PHPUnit_Framework_TestCase
{
Expand Down
14 changes: 13 additions & 1 deletion src/PhpFlo/Core/Tests/GraphTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
<?php
namespace Tests\PhpFlo;

use org\bovigo\vfs\vfsStream;
use PhpFlo\Core\Graph;
use PhpFlo\Core\Test\TestCase;

class GraphTest extends TestCase
{
public function testLoadFile()
{
$graph = Graph::loadFile(__DIR__ . '/../../examples/linecount/count.json');
$fbp = <<<EOF
ReadFile(ReadFile) out -> in SplitbyLines(SplitStr)
ReadFile(ReadFile) error -> in Display(Output)
SplitbyLines(SplitStr) out -> in CountLines(Counter)
CountLines(Counter) count -> in Display(Output)
EOF;

$root = vfsStream::setup();
$file = vfsStream::newFile('count.fbp')->at($root);
$file->setContent($fbp);

$graph = Graph::loadFile($file->url());
$readFile = $graph->getNode('ReadFile');
$this->assertEquals('ReadFile', $readFile['id']);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace PhpFlo\Common\Tests;
namespace PhpFlo\Core\Tests;

use PhpFlo\Common\HookableNetworkTrait;
use PhpFlo\Core\HookableNetworkTrait;
use PhpFlo\Common\Test\TestUtilityTrait;
use PhpFlo\Core\Interaction\InternalSocket;

class HookableNetworkTraitTest extends \PHPUnit_Framework_TestCase
Expand Down
41 changes: 37 additions & 4 deletions src/PhpFlo/Core/Tests/NetworkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@

use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamFile;
use PhpFlo\Common\ComponentBuilderInterface;
use PhpFlo\Common\ComponentInterface;
use PhpFlo\Common\PortInterface;
use PhpFlo\Core\Builder\ComponentFactory;
use PhpFlo\Common\NetworkInterface;
use PhpFlo\Core\Component;
use PhpFlo\Core\Graph;
use PhpFlo\Core\Interaction\PortRegistry;
use PhpFlo\Core\Network;
use PhpFlo\Core\Test\TestCase;

Expand All @@ -30,12 +35,40 @@ public function setUp()

public function testLoadFile()
{
$builder = new ComponentFactory();
$builder = $this->stub(
ComponentBuilderInterface::class,
[
'build' => \Closure::bind(
function ($name) {
$component = new Component();
switch ($name) {
case 'ReadFile':
$component->inPorts()->add('source', []);
$component->outPorts()->add('out', []);
$component->outPorts()->add('error', []);
break;
case 'SplitStr':
$component->inPorts()->add('in', []);
$component->outPorts()->add('out', []);
break;
case 'Counter':
$component->inPorts()->add('in', []);
$component->outPorts()->add('count', []);
break;
case 'Output':
$component->inPorts()->add('in', ['addressable' => true]);
break;
}

return $component;
},
$this
),
]
);

$network = new Network($builder);
$network
->boot($this->filesystem->url());

$network->boot($this->filesystem->url());
$readFile = $network->getNode('ReadFile');
$this->assertEquals('ReadFile', $readFile['id']);

Expand Down
2 changes: 1 addition & 1 deletion src/PhpFlo/Core/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.7/phpunit.xsd"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
Expand Down
2 changes: 1 addition & 1 deletion src/PhpFlo/Fbp/Tests/FbpParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ public function testMultiInitializersTest()
}

/**
* @expectedException PhpFlo\Common\Exception\ParserException
* @expectedException \PhpFlo\Common\Exception\ParserException
*/
public function testComplexMultiDefSingleDefError()
{
Expand Down
2 changes: 1 addition & 1 deletion src/PhpFlo/Fbp/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.7/phpunit.xsd"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
Expand Down
2 changes: 1 addition & 1 deletion src/PhpFlo/FlowTrace/Tests/Logger/SimpleFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use org\bovigo\vfs\vfsStream;
use PhpFlo\FlowTrace\Test\TestCase;
use PhpFlo\Logger\SimpleFile;
use PhpFlo\FlowTrace\Logger\SimpleFile;
use Psr\Log\LogLevel;

class SimpleFileTest extends TestCase
Expand Down
2 changes: 0 additions & 2 deletions src/PhpFlo/FlowTrace/Tests/TraceableNetworkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

class TraceableNetworkTest extends TestCase
{
use TestUtilityTrait;

public function testInstance()
{
//$this->markTestSkipped('Needs change in phpflo');
Expand Down
Loading

0 comments on commit bbb5d2f

Please sign in to comment.