37 lines
		
	
	
		
			734 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
		
		
			
		
	
	
			37 lines
		
	
	
		
			734 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
| 
								 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace NoccyLabs\Ipc\Interop\Channel;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								class StreamChannelTest extends \PhpUnit\Framework\TestCase
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function testCreatingFromStreams()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $fd = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $sc1 = new StreamChannel($fd[0]);
							 | 
						||
| 
								 | 
							
								        $sc2 = new StreamChannel($fd[1]);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $frame = "Hello World";
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $sc1->send($frame);
							 | 
						||
| 
								 | 
							
								        $rcvd = $sc2->receive();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $this->assertEquals($frame, $rcvd);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    public function testCreatingPair()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        [ $sc1, $sc2 ] = StreamChannel::createPair();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $frame = "Hello World";
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $sc1->send($frame);
							 | 
						||
| 
								 | 
							
								        $rcvd = $sc2->receive();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								        $this->assertEquals($frame, $rcvd);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								}
							 |