Beispiel #1
0
 public function testWithWillCallAddNamespaceOnBuilder()
 {
     $builder = m::mock(FlowBuilderInterface::class);
     Flow::setBuilder($builder);
     $builder->shouldReceive('addNamespace')->with('Graze\\DataFlow\\')->once();
     Flow::with('Graze\\DataFlow\\');
 }
Beispiel #2
0
 public function testStaticFlow()
 {
     $file = $this->makeFile('replaceText/static/from', 'some text');
     $flow = Flow::replaceText('text', 'bananas');
     $output = $flow->flow($file);
     static::assertNotSame($file, $output);
     static::assertInstanceOf(LocalFile::class, $output);
     static::assertEquals(['some bananas'], $output->getContents());
 }
Beispiel #3
0
 public function testStaticFlow()
 {
     $file = $this->makeFile('tail/static', "line 1\nline 2\nline 3");
     $flow = Flow::tail(1);
     $output = $flow->flow($file);
     static::assertNotSame($file, $output);
     static::assertInstanceOf(LocalFile::class, $output);
     static::assertEquals(["line 3"], $output->getContents());
 }
Beispiel #4
0
 public function testStaticFlow()
 {
     $file = $this->makeFile('makeDirectory/static/file');
     $flow = Flow::makeDirectory();
     static::assertFalse(is_dir($file->getDirectory()));
     $output = $flow->flow($file);
     static::assertInstanceOf(LocalFile::class, $output);
     static::assertTrue(is_dir($output->getDirectory()));
 }
Beispiel #5
0
 public function testInvokeFlow()
 {
     $file = $this->makeFile('gunzip/invoke/source', 'some text');
     $compressed = Flow::compress(Gzip::NAME)->flow($file);
     $flow = new Gunzip();
     $output = call_user_func($flow, $compressed);
     static::assertNotSame($file, $output);
     static::assertInstanceOf(LocalFile::class, $output);
     static::assertEquals(CompressionFactory::TYPE_NONE, $output->getCompression());
 }
 public function testInvokeFlow()
 {
     $file = $this->makeFile('encoding.invoke.utf8', mb_convert_encoding('some#¢±±§', 'UTF-8'));
     $file->setEncoding('UTF-8');
     $flow = Flow::convertEncoding('UTF-16');
     $output = call_user_func($flow, $file);
     static::assertNotSame($file, $output);
     static::assertInstanceOf(LocalFile::class, $output);
     static::assertEquals('UTF-16', $output->getEncoding());
 }
Beispiel #7
0
 public function testStaticFlow()
 {
     $file = $this->makeFile('gzip/static/source', 'some text');
     $file->setCompression(CompressionFactory::TYPE_NONE);
     $flow = Flow::gzip();
     $output = $flow->flow($file);
     static::assertNotSame($file, $output);
     static::assertInstanceOf(LocalFile::class, $output);
     static::assertEquals(Gzip::NAME, $output->getCompression());
 }
Beispiel #8
0
 public function testInvokeFlow()
 {
     $file = $this->makeFile('moves/invoke/source/file', 'some text');
     $target = $this->makeFile('moves/invoke/target/');
     $flow = Flow::moveFiles($target);
     $output = call_user_func($flow, new FileNodeCollection([$file]));
     static::assertInstanceOf(FileNodeCollection::class, $output);
     static::assertEquals(1, $output->count());
     static::assertEquals('moves/invoke/target/file', $output->getAll()[0]->getPath());
     static::assertFalse($file->exists(), "The original file should not exist");
 }
Beispiel #9
0
 public function testStaticFlow()
 {
     $file1 = $this->makeFile('merge/static/file1', "line 1\nline 2\n");
     $file2 = $this->makeFile('merge/static/file2', "line 3\nline 4\n");
     $merged = $this->makeFile('merge/static/merged');
     $flow = Flow::merge($merged);
     $collection = new FileNodeCollection([$file1, $file2]);
     $output = $flow->flow($collection);
     static::assertSame($output, $merged);
     static::assertEquals(["line 1", "line 2", "line 3", "line 4"], $output->getContents());
 }
Beispiel #10
0
 public function testCopyFileWithDirectoryTargetWillUseOriginalFileName()
 {
     $file = $this->makeFile('copy/todir/source', 'some text');
     $target = $this->makeFile('copy/todir/target/');
     $flow = Flow::copyFile($target);
     $output = $flow->flow($file);
     static::assertNotSame($target, $output);
     static::assertInstanceOf(FileNode::class, $output);
     static::assertEquals($file->getContents(), $output->getContents());
     static::assertEquals('source', $output->getFilename());
     static::assertEquals('copy/todir/target/source', $output->getPath());
 }
Beispiel #11
0
 public function testInvokeFlow()
 {
     $flow1 = m::mock(FlowInterface::class);
     $flow2 = m::mock(FlowInterface::class);
     $runner = Flow::run($flow1, $flow2);
     $node1 = m::mock(NodeInterface::class);
     $node2 = m::mock(NodeInterface::class);
     $node3 = m::mock(NodeInterface::class);
     $flow1->shouldReceive('flow')->with($node1)->andReturn($node2);
     $flow2->shouldReceive('flow')->with($node2)->andReturn($node3);
     static::assertEquals($node3, call_user_func($runner, $node1));
 }
Beispiel #12
0
 public function testInvokeFlow()
 {
     $func = function () use(&$called) {
         $called = true;
         return true;
     };
     $flow = Flow::first($func);
     $node = m::mock(NodeCollectionInterface::class);
     $node->shouldReceive('first')->with($func)->andReturn($node);
     $response = call_user_func($flow, $node);
     static::assertSame($response, $node);
 }
Beispiel #13
0
 public function testStaticFlow()
 {
     $eachFlow = m::mock(FlowInterface::class);
     $flow = Flow::each($eachFlow);
     $node = m::mock(NodeInterface::class);
     $collection = new NodeCollection([$node]);
     $eachFlow->shouldReceive('flow')->with($node)->andReturn($node);
     $response = $flow->flow($collection);
     static::assertNotSame($response, $collection);
     static::assertEquals($collection->getAll(), $response->getAll());
     static::assertInstanceOf(NodeCollectionInterface::class, $response);
 }
Beispiel #14
0
 public function testInvokeFlow()
 {
     $called = null;
     $return = m::mock(NodeInterface::class);
     $callbackFlow = Flow::callback(function ($item) use(&$called, $return) {
         $called = $item;
         return $return;
     });
     $node = m::mock(NodeInterface::class);
     $output = call_user_func($callbackFlow, $node);
     static::assertEquals($return, $output);
     static::assertEquals($called, $node);
 }
Beispiel #15
0
 public function testInvokeFlow()
 {
     $flow1 = m::mock(FlowInterface::class);
     $flow2 = m::mock(FlowInterface::class);
     $runner = Flow::toAll($flow1, $flow2);
     $node1 = m::mock(NodeInterface::class);
     $node2 = m::mock(NodeInterface::class);
     $node3 = m::mock(NodeInterface::class);
     $flow1->shouldReceive('flow')->with($node1)->andReturn($node2);
     $flow2->shouldReceive('flow')->with($node1)->andReturn($node3);
     $output = call_user_func($runner, $node1);
     static::assertInstanceOf(NodeCollection::class, $output);
     static::assertEquals([$node2, $node3], $output->getAll());
 }