1<?php
2
3/**
4 * Hoa
5 *
6 *
7 * @license
8 *
9 * New BSD License
10 *
11 * Copyright © 2007-2017, Hoa community. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions are met:
15 *     * Redistributions of source code must retain the above copyright
16 *       notice, this list of conditions and the following disclaimer.
17 *     * Redistributions in binary form must reproduce the above copyright
18 *       notice, this list of conditions and the following disclaimer in the
19 *       documentation and/or other materials provided with the distribution.
20 *     * Neither the name of the Hoa nor the names of its contributors may be
21 *       used to endorse or promote products derived from this software without
22 *       specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37namespace Hoa\Protocol\Test\Unit\Node;
38
39use Hoa\Protocol\Node\Library as SUT;
40use Hoa\Test;
41
42/**
43 * Class \Hoa\Protocol\Test\Unit\Node\Library.
44 *
45 * Test suite of the library node class.
46 *
47 * @copyright  Copyright © 2007-2017 Hoa community
48 * @license    New BSD License
49 */
50class Library extends Test\Unit\Suite
51{
52    public function case_reach_without_composer_without_a_queue()
53    {
54        $this
55            ->given(
56                $this->constant->WITH_COMPOSER = false,
57                $node = new SUT('foo', 'bar')
58            )
59            ->when($result = $node->reach())
60            ->then
61                ->string($result)
62                    ->isEqualTo('bar');
63    }
64
65    public function case_reach_without_composer_with_a_queue()
66    {
67        $this
68            ->given(
69                $this->constant->WITH_COMPOSER = false,
70                $node = new SUT('foo', 'bar')
71            )
72            ->when($result = $node->reach('baz'))
73            ->then
74                ->string($result)
75                    ->isEqualTo('baz');
76    }
77
78    public function case_reach_with_composer_without_a_queue_and_a_single_reach()
79    {
80        $this
81            ->given(
82                $this->constant->WITH_COMPOSER = true,
83                $node = new SUT('foo', 'Bar' . DS . 'Baz' . DS . 'Qux' . DS)
84            )
85            ->when($result = $node->reach())
86            ->then
87                ->string($result)
88                    ->isEqualTo('Bar' . DS . 'Baz' . DS . 'qux' . DS);
89    }
90
91    public function case_reach_with_composer_without_a_queue_and_a_multiple_reaches()
92    {
93        $this
94            ->given(
95                $this->constant->WITH_COMPOSER = true,
96                $node = new SUT(
97                    'foo',
98                    'Bar' . DS . 'Baz' . DS . 'Qux' . DS . RS .
99                    'Hello' . DS . 'Mister' . DS . 'Anderson' . DS
100                )
101            )
102            ->when($result = $node->reach())
103            ->then
104                ->string($result)
105                    ->isEqualTo(
106                        'Bar' . DS . 'Baz' . DS . 'qux' . DS . RS .
107                        'Hello' . DS . 'Mister' . DS . 'anderson' . DS
108                    );
109    }
110
111    public function case_reach_with_composer_with_a_simple_queue()
112    {
113        $this
114            ->given(
115                $this->constant->WITH_COMPOSER = true,
116                $node = new SUT('foo', 'Bar' . DS . 'Baz' . DS . 'Qux' . DS)
117            )
118            ->when($result = $node->reach('Hello'))
119            ->then
120            ->string($result)
121                ->isEqualTo(
122                    "\r" . 'Bar' . DS . 'Baz' . DS . 'Qux' . DS . 'hello' . RS .
123                    "\r" . dirname(dirname(dirname(dirname(dirname(dirname(__DIR__))))))
124                );
125    }
126
127    public function case_reach_with_composer_with_a_queue()
128    {
129        $this
130            ->given(
131                $this->constant->WITH_COMPOSER = true,
132                $node = new SUT('foo', 'Bar' . DS)
133            )
134            ->when($result = $node->reach('Hello/Mister/Anderson'))
135            ->then
136            ->string($result)
137                ->isEqualTo(
138                    "\r" . 'Bar' . DS . 'hello' . DS . 'Mister' . DS . 'Anderson' . RS .
139                    "\r" . dirname(dirname(dirname(dirname(dirname(dirname(__DIR__)))))) . DS . 'Mister' . DS . 'Anderson'
140                );
141    }
142}
143