ClientTest.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <?php
  2. /*
  3. * This file is part of the php-phantomjs.
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. namespace JonnyW\PhantomJs\Tests\Unit;
  9. use JonnyW\PhantomJs\Client;
  10. use JonnyW\PhantomJs\Engine;
  11. use JonnyW\PhantomJs\Http\MessageFactoryInterface;
  12. use JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface;
  13. use JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface;
  14. /**
  15. * PHP PhantomJs
  16. *
  17. * @author Jon Wenmoth <contact@jonnyw.me>
  18. */
  19. class ClientTest extends \PHPUnit_Framework_TestCase
  20. {
  21. /** +++++++++++++++++++++++++++++++++++ **/
  22. /** ++++++++++++++ TESTS ++++++++++++++ **/
  23. /** +++++++++++++++++++++++++++++++++++ **/
  24. /**
  25. * Test can get client through
  26. * factory method.
  27. *
  28. * @access public
  29. * @return void
  30. */
  31. public function testCanGetClientThroughFactoryMethod()
  32. {
  33. $this->assertInstanceOf('\JonnyW\PhantomJs\Client', Client::getInstance());
  34. }
  35. /**
  36. * Test can get engine.
  37. *
  38. * @return void
  39. */
  40. public function testCanGetEngne()
  41. {
  42. $engine = $this->getEngine();
  43. $procedureLoader = $this->getProcedureLoader();
  44. $procedureCompiler = $this->getProcedureCompiler();
  45. $messageFactory = $this->getMessageFactory();
  46. $client = $this->getClient($engine, $procedureLoader, $procedureCompiler, $messageFactory);
  47. $this->assertInstanceOf('\JonnyW\PhantomJs\Engine', $client->getEngine());
  48. }
  49. /**
  50. * Test can get message factory
  51. *
  52. * @return void
  53. */
  54. public function testCanGetMessageFactory()
  55. {
  56. $engine = $this->getEngine();
  57. $procedureLoader = $this->getProcedureLoader();
  58. $procedureCompiler = $this->getProcedureCompiler();
  59. $messageFactory = $this->getMessageFactory();
  60. $client = $this->getClient($engine, $procedureLoader, $procedureCompiler, $messageFactory);
  61. $this->assertInstanceOf('\JonnyW\PhantomJs\Http\MessageFactoryInterface', $client->getMessageFactory());
  62. }
  63. /**
  64. * Test can get procedure loader.
  65. *
  66. * @return void
  67. */
  68. public function testCanGetProcedureLoader()
  69. {
  70. $engine = $this->getEngine();
  71. $procedureLoader = $this->getProcedureLoader();
  72. $procedureCompiler = $this->getProcedureCompiler();
  73. $messageFactory = $this->getMessageFactory();
  74. $client = $this->getClient($engine, $procedureLoader, $procedureCompiler, $messageFactory);
  75. $this->assertInstanceOf('\JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface', $client->getProcedureLoader());
  76. }
  77. /** +++++++++++++++++++++++++++++++++++ **/
  78. /** ++++++++++ TEST ENTITIES ++++++++++ **/
  79. /** +++++++++++++++++++++++++++++++++++ **/
  80. /**
  81. * Get client instance
  82. *
  83. * @param \JonnyW\PhantomJs\Engine $engine
  84. * @param \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface $procedureLoader
  85. * @param \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface $procedureCompiler
  86. * @param \JonnyW\PhantomJs\Http\MessageFactoryInterface $messageFactory
  87. * @return \JonnyW\PhantomJs\Client
  88. */
  89. protected function getClient(Engine $engine, ProcedureLoaderInterface $procedureLoader, ProcedureCompilerInterface $procedureCompiler, MessageFactoryInterface $messageFactory)
  90. {
  91. $client = new Client($engine, $procedureLoader, $procedureCompiler, $messageFactory);
  92. return $client;
  93. }
  94. /** +++++++++++++++++++++++++++++++++++ **/
  95. /** ++++++++++ MOCKS / STUBS ++++++++++ **/
  96. /** +++++++++++++++++++++++++++++++++++ **/
  97. /**
  98. * Get engine
  99. *
  100. * @access protected
  101. * @return \JonnyW\PhantomJs\Engine
  102. */
  103. protected function getEngine()
  104. {
  105. $engine = $this->createMock('\JonnyW\PhantomJs\Engine');
  106. return $engine;
  107. }
  108. /**
  109. * Get message factory
  110. *
  111. * @access protected
  112. * @return \JonnyW\PhantomJs\Http\MessageFactoryInterface
  113. */
  114. protected function getMessageFactory()
  115. {
  116. $messageFactory = $this->createMock('\JonnyW\PhantomJs\Http\MessageFactoryInterface');
  117. return $messageFactory;
  118. }
  119. /**
  120. * Get procedure loader.
  121. *
  122. * @access protected
  123. * @return \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface
  124. */
  125. protected function getProcedureLoader()
  126. {
  127. $procedureLoader = $this->createMock('\JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface');
  128. return $procedureLoader;
  129. }
  130. /**
  131. * Get procedure validator.
  132. *
  133. * @access protected
  134. * @return \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface
  135. */
  136. protected function getProcedureCompiler()
  137. {
  138. $procedureCompiler = $this->createMock('\JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface');
  139. return $procedureCompiler;
  140. }
  141. }