given($this->mockGenerator->orphanize('__construct')) ->when($result = new SUT()) ->then ->object($result) ->isInstanceOf(HoaSocket\Node::class); } public function case_set_protocol_implementation() { $this ->given( $this->mockGenerator->orphanize('__construct'), $protocolA = new \Mock\Hoa\Websocket\Protocol\Generic(), $this->mockGenerator->orphanize('__construct'), $node = new SUT() ) ->when($result = $node->setProtocolImplementation($protocolA)) ->then ->variable($result) ->isNull() ->given( $this->mockGenerator->orphanize('__construct'), $protocolB = new \Mock\Hoa\Websocket\Protocol\Generic() ) ->when($result = $node->setProtocolImplementation($protocolB)) ->then ->object($result) ->isIdenticalTo($protocolA); } public function case_get_protocol_implementation() { $this ->given( $this->mockGenerator->orphanize('__construct'), $protocol = new \Mock\Hoa\Websocket\Protocol\Generic(), $this->mockGenerator->orphanize('__construct'), $node = new SUT(), $node->setProtocolImplementation($protocol) ) ->when($result = $node->getProtocolImplementation()) ->then ->object($result) ->isIdenticalTo($protocol); } public function case_set_handshake() { $this ->given( $this->mockGenerator->orphanize('__construct'), $node = new SUT() ) ->when($result = $node->setHandshake(true)) ->then ->boolean($result) ->isFalse() ->when($result = $node->setHandshake(false)) ->then ->boolean($result) ->isTrue(); } public function case_get_handshake() { $this ->given( $this->mockGenerator->orphanize('__construct'), $node = new SUT(), $node->setHandshake(true) ) ->when($result = $node->getHandshake()) ->then ->boolean($result) ->isTrue(); } public function case_append_message_fragment() { $this ->given( $this->mockGenerator->orphanize('__construct'), $node = new SUT() ) ->when($result = $node->appendMessageFragment('foo')) ->then ->string($result) ->isEqualTo('foo'); } public function case_append_many_message_fragments() { $this ->given( $this->mockGenerator->orphanize('__construct'), $node = new SUT(), $fragmentA = 'foo', $fragmentB = 'bar', $fragmentC = 'baz' ) ->when($result = $node->appendMessageFragment($fragmentA)) ->then ->string($result) ->isEqualTo($fragmentA) ->when($result = $node->appendMessageFragment($fragmentB)) ->then ->string($result) ->isEqualTo($fragmentA . $fragmentB) ->when($result = $node->appendMessageFragment($fragmentC)) ->then ->string($result) ->isEqualTo($fragmentA . $fragmentB . $fragmentC); } public function case_get_fragmented_message() { $this ->given( $this->mockGenerator->orphanize('__construct'), $node = new SUT(), $fragmentA = 'foo', $fragmentB = 'bar', $fragmentC = 'baz', $node->appendMessageFragment($fragmentA), $node->appendMessageFragment($fragmentB), $node->appendMessageFragment($fragmentC) ) ->when($result = $node->getFragmentedMessage()) ->then ->string($result) ->isEqualTo($fragmentA . $fragmentB . $fragmentC); } public function case_get_number_of_fragments_for_an_message() { $this ->given( $this->mockGenerator->orphanize('__construct'), $node = new SUT() ) ->when($result = $node->getNumberOfFragments()) ->then ->integer($result) ->isEqualTo(0); } public function case_get_number_of_fragments() { $this ->given( $this->mockGenerator->orphanize('__construct'), $node = new SUT(), $fragmentA = 'foo', $fragmentB = 'bar', $fragmentC = 'baz', $node->appendMessageFragment($fragmentA), $node->appendMessageFragment($fragmentB), $node->appendMessageFragment($fragmentC) ) ->when($result = $node->getNumberOfFragments()) ->then ->integer($result) ->isEqualTo(3); } public function case_set_complete() { $this ->given( $this->mockGenerator->orphanize('__construct'), $node = new SUT() ) ->when($result = $node->setComplete(false)) ->then ->boolean($result) ->isTrue() ->when($result = $node->setComplete(true)) ->then ->boolean($result) ->isFalse(); } public function case_is_message_complete() { $this ->given( $this->mockGenerator->orphanize('__construct'), $node = new SUT(), $node->setComplete(true) ) ->when($result = $node->isMessageComplete()) ->then ->boolean($result) ->isTrue(); } public function case_is_message_not_complete() { $this ->given( $this->mockGenerator->orphanize('__construct'), $node = new SUT(), $node->setComplete(false) ) ->when($result = $node->isMessageComplete()) ->then ->boolean($result) ->isFalse(); } public function case_message_is_complete_by_default() { $this ->given( $this->mockGenerator->orphanize('__construct'), $node = new SUT() ) ->when($result = $node->isMessageComplete()) ->then ->boolean($result) ->isTrue(); } public function case_set_binary() { $this ->given( $this->mockGenerator->orphanize('__construct'), $node = new SUT() ) ->when($result = $node->setBinary(true)) ->then ->boolean($result) ->isFalse() ->when($result = $node->setBinary(false)) ->then ->boolean($result) ->isTrue(); } public function case_is_binary() { $this ->given( $this->mockGenerator->orphanize('__construct'), $node = new SUT(), $node->setBinary(true) ) ->when($result = $node->isBinary()) ->then ->boolean($result) ->isTrue(); } public function case_is_not_binary() { $this ->given( $this->mockGenerator->orphanize('__construct'), $node = new SUT(), $node->setBinary(false) ) ->when($result = $node->isBinary()) ->then ->boolean($result) ->isFalse(); } public function case_not_binary_by_default() { $this ->given( $this->mockGenerator->orphanize('__construct'), $node = new SUT() ) ->when($result = $node->isBinary()) ->then ->boolean($result) ->isFalse(); } public function case_clear_fragmentation() { $this ->given( $this->mockGenerator->orphanize('__construct'), $protocol = new \Mock\Hoa\Websocket\Protocol\Generic(), $this->mockGenerator->orphanize('__construct'), $node = new SUT(), $node->setProtocolImplementation($protocol), $node->appendMessageFragment('foo'), $node->appendMessageFragment('bar'), $node->setBinary(true), $node->setComplete(false) ) ->when($result = $node->clearFragmentation()) ->then ->variable($result) ->isNull() ->object($node->getProtocolImplementation()) ->isIdenticalTo($protocol) ->variable($node->getFragmentedMessage()) ->isNull() ->boolean($node->isBinary()) ->isFalse() ->boolean($node->isMessageComplete()) ->isTrue(); } }