|
| 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 | +} |
0 commit comments