DefaultImplementationTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * Copyright 2014 Fabian Grutschus. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  19. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *
  26. * The views and conclusions contained in the software and documentation are those
  27. * of the authors and should not be interpreted as representing official policies,
  28. * either expressed or implied, of the copyright holders.
  29. *
  30. * @author Fabian Grutschus <f.grutschus@lubyte.de>
  31. * @copyright 2014 Fabian Grutschus. All rights reserved.
  32. * @license BSD
  33. * @link http://github.com/fabiang/xmpp
  34. */
  35. namespace Fabiang\Xmpp\Protocol;
  36. use PHPUnit\Framework\TestCase;
  37. use Fabiang\Xmpp\Options;
  38. use Fabiang\Xmpp\Connection\Test;
  39. /**
  40. * Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2014-01-17 at 09:54:58.
  41. *
  42. * @coversDefaultClass Fabiang\Xmpp\Protocol\DefaultImplementation
  43. */
  44. class DefaultImplementationTest extends TestCase
  45. {
  46. /**
  47. * @var DefaultImplementation
  48. */
  49. protected $object;
  50. /**
  51. * Sets up the fixture, for example, opens a network connection.
  52. * This method is called before a test is executed.
  53. *
  54. * @return void
  55. */
  56. protected function setUp()
  57. {
  58. $this->object = new DefaultImplementation;
  59. }
  60. /**
  61. * Test registering implementation.
  62. *
  63. * @covers ::register
  64. * @covers ::registerListener
  65. * @uses Fabiang\Xmpp\Protocol\DefaultImplementation::getOptions
  66. * @uses Fabiang\Xmpp\Protocol\DefaultImplementation::setOptions
  67. * @uses Fabiang\Xmpp\Protocol\DefaultImplementation::getEventManager
  68. * @uses Fabiang\Xmpp\Protocol\DefaultImplementation::setEventManager
  69. * @uses Fabiang\Xmpp\EventListener\Stream\StreamError
  70. * @uses Fabiang\Xmpp\EventListener\Stream\Authentication
  71. * @uses Fabiang\Xmpp\EventListener\AbstractEventListener
  72. * @uses Fabiang\Xmpp\Connection\AbstractConnection
  73. * @uses Fabiang\Xmpp\EventListener\Stream\Bind
  74. * @uses Fabiang\Xmpp\EventListener\Stream\Roster
  75. * @uses Fabiang\Xmpp\EventListener\Stream\StartTls
  76. * @uses Fabiang\Xmpp\Options
  77. * @uses Fabiang\Xmpp\Event\EventManager
  78. * @uses Fabiang\Xmpp\EventListener\Stream\Session
  79. * @uses Fabiang\Xmpp\EventListener\Stream\Stream
  80. * @uses Fabiang\Xmpp\Stream\XMLStream
  81. * @return void
  82. */
  83. public function testRegister()
  84. {
  85. $connection = new Test;
  86. $options = new Options();
  87. $options->setConnection($connection);
  88. $this->object->setOptions($options);
  89. $eventManager = $this->object->getEventManager();
  90. $this->object->register();
  91. foreach ($connection->getListeners() as $listener) {
  92. $this->assertSame($eventManager, $listener->getEventManager());
  93. $this->assertSame($connection, $listener->getOptions()->getConnection());
  94. }
  95. }
  96. /**
  97. * Test setting and getting options.
  98. *
  99. * @covers ::getOptions
  100. * @covers ::setOptions
  101. * @return void
  102. */
  103. public function testSetAndGetOptions()
  104. {
  105. $options = $this->getMockBuilder('Fabiang\Xmpp\Options')
  106. ->disableOriginalConstructor()
  107. ->getMock();
  108. $this->assertSame($options, $this->object->setOptions($options)->getOptions());
  109. }
  110. /**
  111. * Test setting and getting event manager.
  112. *
  113. * @covers ::getEventManager
  114. * @covers ::setEventManager
  115. * @uses Fabiang\Xmpp\Event\EventManager
  116. * @return void
  117. */
  118. public function testSetAndGetEventManager()
  119. {
  120. $this->assertInstanceOf('\Fabiang\Xmpp\Event\EventManager', $this->object->getEventManager());
  121. $eventManager = $this->getMockBuilder('\Fabiang\Xmpp\Event\EventManager')
  122. ->disableOriginalConstructor()
  123. ->getMock();
  124. $this->assertSame($eventManager, $this->object->setEventManager($eventManager)->getEventManager());
  125. }
  126. }