Skip to content

Commit 68054b2

Browse files
author
Marc Aschmann
committed
Move to v1.0.0 of phpflo, Add tests, check DI loader
1 parent f954327 commit 68054b2

5 files changed

Lines changed: 211 additions & 38 deletions

File tree

Test/FlowTestCase.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/*
3+
* This file is part of the phpflo/phpflo-bundle package.
4+
*
5+
* (c) Marc Aschmann <maschmann@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PhpFlo\PhpFloBundle\Test;
11+
12+
/**
13+
* Stub and mock helper.
14+
*
15+
* @package Test
16+
* @author Marc Aschmann <maschmann@gmail.com>
17+
*/
18+
abstract class FlowTestCase extends \PHPUnit_Framework_TestCase
19+
{
20+
/**
21+
* Will create a stub with several methods and defined return values.
22+
* definition:
23+
* [
24+
* 'myMethod' => 'somevalue',
25+
* 'myOtherMethod' => $callback,
26+
* 'anotherMethod' => function ($x) use ($y) {},
27+
* ]
28+
*
29+
* @param string $class
30+
* @param array $methods
31+
* @return \PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
protected function stub($class, array $methods = [])
34+
{
35+
$stub = $this->getMockBuilder($class)
36+
->disableOriginalConstructor()
37+
->getMock();
38+
39+
foreach ($methods as $method => $value) {
40+
if (is_callable($value)) {
41+
$stub->expects($this->any())->method($method)->willReturnCallback($value);
42+
} else {
43+
$stub->expects($this->any())->method($method)->willReturn($value);
44+
}
45+
}
46+
47+
return $stub;
48+
}
49+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/*
3+
* This file is part of the <package> package.
4+
*
5+
* (c) Marc Aschmann <maschmann@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PhpFlo\PhpFloBundle\Tests\Flow;
11+
12+
use PhpFlo\Component;
13+
use PhpFlo\PhpFloBundle\Flow\DiNetworkBuilder;
14+
use PhpFlo\PhpFloBundle\Test\FlowTestCase;
15+
use org\bovigo\vfs\vfsStream;
16+
17+
18+
class DiNetworkBuilderTest extends FlowTestCase
19+
{
20+
private $file;
21+
private $defaultFlow = <<< EOF
22+
ReadFile(ReadFile) out -> in SplitbyLines(SplitStr)
23+
CountLines(Counter) count -> in Display(Output)
24+
EOF;
25+
26+
public function testLoadConfigs()
27+
{
28+
$elements = [
29+
'ReadFile' => ['out' => ['out'], 'in' => [],],
30+
'SplitStr' => ['in' => ['in'], 'out' => [],],
31+
'Counter' => ['out' => ['count'], 'in' => [], ],
32+
'Output' => ['in' => ['in'], 'out' => [],]
33+
];
34+
$components = [];
35+
foreach ($elements as $name => $element) {
36+
$components[$name] = new Component();
37+
foreach ($element['in'] as $port) {
38+
$components[$name]->inPorts()->add($port, []);
39+
}
40+
41+
foreach ($element['out'] as $port) {
42+
$components[$name]->outPorts()->add($port, []);
43+
}
44+
}
45+
46+
$componentsCb = function ($name) use ($components) {
47+
return $components[$name];
48+
};
49+
50+
$container = $this->stub(
51+
'\Symfony\Component\DependencyInjection\ContainerInterface',
52+
[
53+
'get' => $componentsCb,
54+
]
55+
);
56+
$file = $this->createFile('app/config/flow/default_flow.fbp', $this->defaultFlow);
57+
58+
$networkBuilder = new DiNetworkBuilder($container, 'vfs://root/test');
59+
$this->assertInstanceOf('PhpFlo\PhpFloBundle\Flow\DiNetworkBuilder', $networkBuilder);
60+
61+
$network = $networkBuilder->fromFile('flow/default_flow.fbp');
62+
$this->assertInstanceOf('PhpFlo\Network', $network);
63+
64+
$graph = $network->getGraph();
65+
$this->assertInstanceOf('PhpFlo\Graph', $graph);
66+
67+
$this->assertEquals($this->defaultFlow, $graph->toFbp());
68+
}
69+
70+
private function createFile($name, $content)
71+
{
72+
$root = vfsStream::setup();
73+
$this->file = vfsStream::newFile($name)->at($root);
74+
$this->file->setContent($content);
75+
76+
return $this->file->url();
77+
}
78+
}

Tests/Flow/NetworkBuilderTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/*
3+
* This file is part of the <package> package.
4+
*
5+
* (c) Marc Aschmann <maschmann@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PhpFlo\PhpFloBundle\Tests\Flow;
11+
12+
use PhpFlo\PhpFloBundle\Flow\NetworkBuilder;
13+
use PhpFlo\PhpFloBundle\Test\FlowTestCase;
14+
use org\bovigo\vfs\vfsStream;
15+
16+
class NetworkBuilderTest extends FlowTestCase
17+
{
18+
private $file;
19+
20+
private $defaultFlow = <<< EOF
21+
ReadFile(ReadFile) out -> in SplitbyLines(SplitStr)
22+
ReadFile(ReadFile) error -> in Display(Output)
23+
SplitbyLines(SplitStr) out -> in CountLines(Counter)
24+
CountLines(Counter) count -> in Display(Output)
25+
EOF;
26+
27+
28+
public function testInstance()
29+
{
30+
$registry = $this->stub('PhpFlo\Common\ComponentRegistryInterface');
31+
$networkBuilder = new NetworkBuilder($registry, '/');
32+
33+
$this->assertInstanceOf('PhpFlo\PhpFloBundle\Flow\NetworkBuilder', $networkBuilder);
34+
}
35+
36+
public function testLoadConfigs()
37+
{
38+
$registry = $this->stub('PhpFlo\Common\ComponentRegistryInterface');
39+
$file = $this->createFile('app/config/flow/default_flow.fbp', $this->defaultFlow);
40+
$networkBuilder = new NetworkBuilder($registry, 'vfs://root/test');
41+
42+
}
43+
44+
private function createFile($name, $content)
45+
{
46+
$root = vfsStream::setup();
47+
$this->file = vfsStream::newFile($name)->at($root);
48+
$this->file->setContent($content);
49+
50+
return $this->file->url();
51+
}
52+
}

Tests/Flow/NetworkTest.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,29 @@
88
* file that was distributed with this source code.
99
*/
1010

11-
namespace Tests\Flow;
11+
namespace PhpFlo\PhpFloBundle\Tests\Flow;
1212

1313
use PhpFlo\Network;
1414
use PhpFlo\Graph;
15+
use PhpFlo\PhpFloBundle\Test\FlowTestCase;
1516

1617
/**
1718
* Class NetworkTest
1819
*
1920
* @package Tests\Flow
2021
* @author Marc Aschmann <maschmann@gmail.com>
2122
*/
22-
class NetworkTest extends \PHPUnit_Framework_TestCase
23+
class NetworkTest extends FlowTestCase
2324
{
2425
public function testCreate()
2526
{
26-
// no interface for mocking available, constructor needs argument
27-
$graph = new Graph('test');//$this->getMockBuilder('\PhpFlo\Graph')->getMock();
28-
//$registry = $this->getMockBuilder('\PhpFlo\Common\RegistryInterface')->getMock();
29-
$builder = $this->getMockBuilder('\PhpFlo\Common\ComponentBuilderInterface')->getMock();
30-
27+
$graph = $this->stub('\PhpFlo\Graph');
28+
$graph->nodes = [];
29+
$graph->edges = [];
30+
$graph->initializers = [];
31+
$builder = $this->stub('\PhpFlo\Common\ComponentBuilderInterface');
3132
$network = Network::create($graph, $builder);
3233

3334
$this->assertInstanceOf('\PhpFlo\Network', $network);
3435
}
35-
36-
private function createNetwork()
37-
{
38-
$graph = $graph = new Graph('test');
39-
$builder = $this->getMockBuilder('\PhpFlo\Common\ComponentBuilderInterface')->getMock();
40-
41-
$network = new Network($graph, $builder);
42-
}
4336
}

composer.json

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
{
2-
"name": "phpflo/phpflo-bundle",
3-
"description": "Integrate phpflo into symfony",
4-
"type": "symfony-bundle",
5-
"require": {
6-
"php": ">=5.5.9",
7-
"symfony/symfony": "^2.8 || ^3.0",
8-
"phpflo/phpflo": "dev-master#48b1046bbd7c155d33fd24823b787a5420947054",
9-
"asm/php-utilities": "^2.0"
10-
},
11-
"require-dev": {
12-
"phpunit/phpunit": "^5.4"
13-
},
14-
"license": "MIT",
15-
"authors": [
16-
{
17-
"name": "Marc Aschmann",
18-
"email": "maschmann@gmail.com"
19-
}
20-
],
21-
"autoload": {
22-
"psr-4": {
23-
"PhpFlo\\PhpFloBundle\\": ""
24-
}
2+
"name": "phpflo/phpflo-bundle",
3+
"description": "Integrate phpflo into symfony",
4+
"type": "symfony-bundle",
5+
"require": {
6+
"php": ">=5.5.9",
7+
"symfony/symfony": "^2.8 || ^3.0",
8+
"phpflo/phpflo": "^1.0",
9+
"asm/php-utilities": "^2.0"
10+
},
11+
"require-dev": {
12+
"phpunit/phpunit": "^5.4",
13+
"mikey179/vfsStream": "~1.0"
14+
},
15+
"license": "MIT",
16+
"authors": [
17+
{
18+
"name": "Marc Aschmann",
19+
"email": "maschmann@gmail.com"
2520
}
21+
],
22+
"autoload": {
23+
"psr-4": {
24+
"PhpFlo\\PhpFloBundle\\": ""
25+
}
26+
}
2627
}

0 commit comments

Comments
 (0)