|
|
@@ -9,9 +9,10 @@
|
|
|
namespace JonnyW\PhantomJs\Tests\Unit;
|
|
|
|
|
|
use JonnyW\PhantomJs\Client;
|
|
|
+use JonnyW\PhantomJs\Engine;
|
|
|
use JonnyW\PhantomJs\Http\MessageFactoryInterface;
|
|
|
use JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface;
|
|
|
-use JonnyW\PhantomJs\Procedure\ProcedureValidatorInterface;
|
|
|
+use JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface;
|
|
|
|
|
|
/**
|
|
|
* PHP PhantomJs
|
|
|
@@ -38,270 +39,54 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Test can get message factory
|
|
|
- *
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testCanGetMessageFactory()
|
|
|
- {
|
|
|
- $procedureLoader = $this->getProcedureLoader();
|
|
|
- $procedureValidator = $this->getProcedureValidator();
|
|
|
- $messageFactory = $this->getMessageFactory();
|
|
|
-
|
|
|
- $client = $this->getClient($procedureLoader, $procedureValidator, $messageFactory);
|
|
|
-
|
|
|
- $this->assertInstanceOf('\JonnyW\PhantomJs\Http\MessageFactoryInterface', $client->getMessageFactory());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Test can get procedure loader.
|
|
|
- *
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testCanGetProcedureLoader()
|
|
|
- {
|
|
|
- $procedureLoader = $this->getProcedureLoader();
|
|
|
- $procedureValidator = $this->getProcedureValidator();
|
|
|
- $messageFactory = $this->getMessageFactory();
|
|
|
-
|
|
|
- $client = $this->getClient($procedureLoader, $procedureValidator, $messageFactory);
|
|
|
-
|
|
|
- $this->assertInstanceOf('\JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface', $client->getProcedureLoader());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Test invalid executable exception is thrown
|
|
|
- * if phantom JS path is invalid.
|
|
|
- *
|
|
|
- * @access public
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testInvalidExecutableExceptionIsThrownIfPhantomJSPathIsInvalid()
|
|
|
- {
|
|
|
- $this->setExpectedException('\JonnyW\PhantomJs\Exception\InvalidExecutableException');
|
|
|
-
|
|
|
- $procedureLoader = $this->getProcedureLoader();
|
|
|
- $procedureValidator = $this->getProcedureValidator();
|
|
|
- $messageFactory = $this->getMessageFactory();
|
|
|
-
|
|
|
- $client = $this->getClient($procedureLoader, $procedureValidator, $messageFactory);
|
|
|
- $client->setPhantomJs('/invalid/phantomjs/path');
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Test default phantom JS path is returned
|
|
|
- * if no custom path is set.
|
|
|
- *
|
|
|
- * @access public
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testDefaultPhantomJSPathIsReturnedIfNoCustomPathIsSet()
|
|
|
- {
|
|
|
- $procedureLoader = $this->getProcedureLoader();
|
|
|
- $procedureValidator = $this->getProcedureValidator();
|
|
|
- $messageFactory = $this->getMessageFactory();
|
|
|
-
|
|
|
- $client = $this->getClient($procedureLoader, $procedureValidator, $messageFactory);
|
|
|
-
|
|
|
- $this->assertSame('bin/phantomjs', $client->getPhantomJs());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Test can log data.
|
|
|
- *
|
|
|
- * @access public
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testCanLogData()
|
|
|
- {
|
|
|
- $procedureLoader = $this->getProcedureLoader();
|
|
|
- $procedureValidator = $this->getProcedureValidator();
|
|
|
- $messageFactory = $this->getMessageFactory();
|
|
|
-
|
|
|
- $log = 'Test log info';
|
|
|
-
|
|
|
- $client = $this->getClient($procedureLoader, $procedureValidator, $messageFactory);
|
|
|
- $client->log($log);
|
|
|
-
|
|
|
- $this->assertSame($log, $client->getLog());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Test can clear log.
|
|
|
- *
|
|
|
- * @access public
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testCanClearLog()
|
|
|
- {
|
|
|
- $procedureLoader = $this->getProcedureLoader();
|
|
|
- $procedureValidator = $this->getProcedureValidator();
|
|
|
- $messageFactory = $this->getMessageFactory();
|
|
|
-
|
|
|
- $log = 'Test log info';
|
|
|
-
|
|
|
- $client = $this->getClient($procedureLoader, $procedureValidator, $messageFactory);
|
|
|
- $client->log($log);
|
|
|
- $client->clearLog();
|
|
|
-
|
|
|
- $this->assertEmpty($client->getLog());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Test can add run option.
|
|
|
- *
|
|
|
- * @access public
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testCanAddRunOption()
|
|
|
- {
|
|
|
- $procedureLoader = $this->getProcedureLoader();
|
|
|
- $procedureValidator = $this->getProcedureValidator();
|
|
|
- $messageFactory = $this->getMessageFactory();
|
|
|
-
|
|
|
- $options = array(
|
|
|
- 'option1',
|
|
|
- 'option2'
|
|
|
- );
|
|
|
-
|
|
|
- $client = $this->getClient($procedureLoader, $procedureValidator, $messageFactory);
|
|
|
- $client->setOptions($options);
|
|
|
- $client->addOption('option3');
|
|
|
-
|
|
|
- array_push($options, 'option3');
|
|
|
-
|
|
|
- $this->assertSame($options, $client->getOptions());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Test invalid executable exception is thrown when
|
|
|
- * building command if path to phantom JS is valid.
|
|
|
- *
|
|
|
- * @access public
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testInvalidExecutableExceptionIsThrownWhenBuildingCommandIfPathToPhantomJSIsInvalid()
|
|
|
- {
|
|
|
- $this->setExpectedException('\JonnyW\PhantomJs\Exception\InvalidExecutableException');
|
|
|
-
|
|
|
- $procedureLoader = $this->getProcedureLoader();
|
|
|
- $procedureValidator = $this->getProcedureValidator();
|
|
|
- $messageFactory = $this->getMessageFactory();
|
|
|
-
|
|
|
- $client = $this->getClient($procedureLoader, $procedureValidator, $messageFactory);
|
|
|
-
|
|
|
- $phantomJs = new \ReflectionProperty(get_class($client), 'phantomJs');
|
|
|
- $phantomJs->setAccessible(true);
|
|
|
- $phantomJs->setValue($client, 'invalid/path');
|
|
|
-
|
|
|
- $client->getCommand();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Test command contains phantom JS executable
|
|
|
- *
|
|
|
- * @access public
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testCommandContainsPhantomJSExecutable()
|
|
|
- {
|
|
|
- $procedureLoader = $this->getProcedureLoader();
|
|
|
- $procedureValidator = $this->getProcedureValidator();
|
|
|
- $messageFactory = $this->getMessageFactory();
|
|
|
-
|
|
|
- $client = $this->getClient($procedureLoader, $procedureValidator, $messageFactory);
|
|
|
-
|
|
|
- $this->assertContains($client->getPhantomJs(), $client->getCommand());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Test debug flag can be set.
|
|
|
+ * Test can get engine.
|
|
|
*
|
|
|
- * @access public
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function testDebugFlagCanBeSet()
|
|
|
+ public function testCanGetEngne()
|
|
|
{
|
|
|
+ $engine = $this->getEngine();
|
|
|
$procedureLoader = $this->getProcedureLoader();
|
|
|
- $procedureValidator = $this->getProcedureValidator();
|
|
|
+ $procedureCompiler = $this->getProcedureCompiler();
|
|
|
$messageFactory = $this->getMessageFactory();
|
|
|
|
|
|
- $client = $this->getClient($procedureLoader, $procedureValidator, $messageFactory);
|
|
|
- $client->debug(true);
|
|
|
+ $client = $this->getClient($engine, $procedureLoader, $procedureCompiler, $messageFactory);
|
|
|
|
|
|
- $this->assertContains('--debug=true', $client->getCommand());
|
|
|
+ $this->assertInstanceOf('\JonnyW\PhantomJs\Engine', $client->getEngine());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Test debug flag is not set if
|
|
|
- * debugging is not enabled.
|
|
|
- *
|
|
|
- * @access public
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function testDebugFlagIsNotSetIfDebuggingIsNotEnabled()
|
|
|
- {
|
|
|
- $procedureLoader = $this->getProcedureLoader();
|
|
|
- $procedureValidator = $this->getProcedureValidator();
|
|
|
- $messageFactory = $this->getMessageFactory();
|
|
|
-
|
|
|
- $client = $this->getClient($procedureLoader, $procedureValidator, $messageFactory);
|
|
|
- $client->debug(false);
|
|
|
-
|
|
|
- $this->assertNotContains('--debug=true', $client->getCommand());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Test command contains run options.
|
|
|
+ * Test can get message factory
|
|
|
*
|
|
|
- * @access public
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function testCommandContainsRunOptions()
|
|
|
+ public function testCanGetMessageFactory()
|
|
|
{
|
|
|
+ $engine = $this->getEngine();
|
|
|
$procedureLoader = $this->getProcedureLoader();
|
|
|
- $procedureValidator = $this->getProcedureValidator();
|
|
|
+ $procedureCompiler = $this->getProcedureCompiler();
|
|
|
$messageFactory = $this->getMessageFactory();
|
|
|
|
|
|
- $option1 = '--local-storage-path=/some/path';
|
|
|
- $option2 = '--local-storage-quota=5';
|
|
|
- $option3 = '--local-to-remote-url-access=true';
|
|
|
-
|
|
|
- $client = $this->getClient($procedureLoader, $procedureValidator, $messageFactory);
|
|
|
- $client->addOption($option1);
|
|
|
- $client->addOption($option2);
|
|
|
- $client->addOption($option3);
|
|
|
-
|
|
|
- $command = $client->getCommand();
|
|
|
+ $client = $this->getClient($engine, $procedureLoader, $procedureCompiler, $messageFactory);
|
|
|
|
|
|
- $this->assertContains($option1, $command);
|
|
|
- $this->assertContains($option2, $command);
|
|
|
- $this->assertContains($option3, $command);
|
|
|
+ $this->assertInstanceOf('\JonnyW\PhantomJs\Http\MessageFactoryInterface', $client->getMessageFactory());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Test debug flag is set if runs options
|
|
|
- * are also set.
|
|
|
+ * Test can get procedure loader.
|
|
|
*
|
|
|
- * @access public
|
|
|
* @return void
|
|
|
*/
|
|
|
- public function testDebugFlagIsSetIfRunOptionsAreAlsoSet()
|
|
|
+ public function testCanGetProcedureLoader()
|
|
|
{
|
|
|
+ $engine = $this->getEngine();
|
|
|
$procedureLoader = $this->getProcedureLoader();
|
|
|
- $procedureValidator = $this->getProcedureValidator();
|
|
|
+ $procedureCompiler = $this->getProcedureCompiler();
|
|
|
$messageFactory = $this->getMessageFactory();
|
|
|
|
|
|
- $option = '--local-storage-path=/some/path';
|
|
|
-
|
|
|
- $client = $this->getClient($procedureLoader, $procedureValidator, $messageFactory);
|
|
|
- $client->addOption($option);
|
|
|
- $client->debug(true);
|
|
|
+ $client = $this->getClient($engine, $procedureLoader, $procedureCompiler, $messageFactory);
|
|
|
|
|
|
- $command = $client->getCommand();
|
|
|
-
|
|
|
- $this->assertContains($option, $command);
|
|
|
- $this->assertContains('--debug=true', $command);
|
|
|
+ $this->assertInstanceOf('\JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface', $client->getProcedureLoader());
|
|
|
}
|
|
|
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/
|
|
|
@@ -311,14 +96,15 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|
|
/**
|
|
|
* Get client instance
|
|
|
*
|
|
|
- * @param \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface $procedureLoader
|
|
|
- * @param \JonnyW\PhantomJs\Procedure\ProcedureValidatorInterface $procedureValidator
|
|
|
- * @param \JonnyW\PhantomJs\Http\MessageFactoryInterface $messageFactory
|
|
|
+ * @param \JonnyW\PhantomJs\Engine $engine
|
|
|
+ * @param \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface $procedureLoader
|
|
|
+ * @param \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface $procedureCompiler
|
|
|
+ * @param \JonnyW\PhantomJs\Http\MessageFactoryInterface $messageFactory
|
|
|
* @return \JonnyW\PhantomJs\Client
|
|
|
*/
|
|
|
- protected function getClient(ProcedureLoaderInterface $procedureLoader, ProcedureValidatorInterface $procedureValidator, MessageFactoryInterface $messageFactory)
|
|
|
+ protected function getClient(Engine $engine, ProcedureLoaderInterface $procedureLoader, ProcedureCompilerInterface $procedureCompiler, MessageFactoryInterface $messageFactory)
|
|
|
{
|
|
|
- $client = new Client($procedureLoader, $procedureValidator, $messageFactory);
|
|
|
+ $client = new Client($engine, $procedureLoader, $procedureCompiler, $messageFactory);
|
|
|
|
|
|
return $client;
|
|
|
}
|
|
|
@@ -327,6 +113,19 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|
|
/** ++++++++++ MOCKS / STUBS ++++++++++ **/
|
|
|
/** +++++++++++++++++++++++++++++++++++ **/
|
|
|
|
|
|
+ /**
|
|
|
+ * Get engine
|
|
|
+ *
|
|
|
+ * @access protected
|
|
|
+ * @return \JonnyW\PhantomJs\Engine
|
|
|
+ */
|
|
|
+ protected function getEngine()
|
|
|
+ {
|
|
|
+ $engine = $this->getMock('\JonnyW\PhantomJs\Engine');
|
|
|
+
|
|
|
+ return $engine;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Get message factory
|
|
|
*
|
|
|
@@ -357,12 +156,12 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
|
|
* Get procedure validator.
|
|
|
*
|
|
|
* @access protected
|
|
|
- * @return \JonnyW\PhantomJs\Procedure\ProcedureLoaderInterface
|
|
|
+ * @return \JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface
|
|
|
*/
|
|
|
- protected function getProcedureValidator()
|
|
|
+ protected function getProcedureCompiler()
|
|
|
{
|
|
|
- $procedureValidator = $this->getMock('\JonnyW\PhantomJs\Procedure\ProcedureValidatorInterface');
|
|
|
+ $procedureCompiler = $this->getMock('\JonnyW\PhantomJs\Procedure\ProcedureCompilerInterface');
|
|
|
|
|
|
- return $procedureValidator;
|
|
|
+ return $procedureCompiler;
|
|
|
}
|
|
|
}
|