| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- <?php
-
- /**
- * Hoa
- *
- *
- * @license
- *
- * New BSD License
- *
- * Copyright © 2007-2017, Hoa community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Hoa nor the names of its contributors may be
- * used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
- namespace Hoa\Websocket\Test\Unit;
-
- use Hoa\Socket as HoaSocket;
- use Hoa\Test;
- use Mock\Hoa\Websocket\Node as SUT;
-
- /**
- * Class \Hoa\Websocket\Test\Unit\Node.
- *
- * Test suite for the node class.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
- */
- class Node extends Test\Unit\Suite
- {
- public function case_is_a_node()
- {
- $this
- ->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();
- }
- }
|