-
Notifications
You must be signed in to change notification settings - Fork 46
Support zombie.js options #154
Changes from 2 commits
8a17347
f57a58e
860aaca
ab2a51e
80999d8
95fa786
847ecea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,11 @@ abstract class Server | |
| */ | ||
| protected $connection; | ||
|
|
||
| /** | ||
| * @var array | ||
| */ | ||
| protected $options = array(); | ||
|
|
||
| /** | ||
| * Constructor | ||
| * | ||
|
|
@@ -76,7 +81,8 @@ public function __construct( | |
| $nodeBin = null, | ||
| $serverPath = null, | ||
| $threshold = 2000000, | ||
| $nodeModulesPath = '' | ||
| $nodeModulesPath = '', | ||
| $options = array() | ||
| ) { | ||
| if (null === $nodeBin) { | ||
| $nodeBin = 'node'; | ||
|
|
@@ -93,6 +99,8 @@ public function __construct( | |
|
|
||
| $this->serverPath = $serverPath; | ||
| $this->threshold = intval($threshold); | ||
|
|
||
| $this->setOptions($options); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -253,6 +261,52 @@ public function getConnection() | |
| return $this->connection; | ||
| } | ||
|
|
||
| /** | ||
| * Return the options. | ||
| * | ||
| * @return array | ||
| */ | ||
| public function getOptions() | ||
| { | ||
| return $this->options; | ||
| } | ||
|
|
||
| /** | ||
| * Set options array. | ||
| */ | ||
| public function setOptions($options) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update example in README.md to show that it's now possible to set Zombie options. While we're at it you can send PR's to MinkExtension and PHPUnit-Mink to update Zombie integration to allow specifying Zombie options in there as well. That would be a great addition.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than updating the readme, it would be better to update the docs repo though |
||
| { | ||
| // pass these to the setOption() method which will validate. | ||
| foreach ($options as $key => $value) { | ||
| $this->setOption($key, $value); | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add following code afterwards: $this->serverPath = $this->createTemporaryServer();to regenerate server code. |
||
|
|
||
| /** | ||
| * Set a single option. | ||
| */ | ||
| public function setOption($option, $value) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please inline this method (after fixing other snuff), because it will complicate things down the road.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I follow what this means. I just posted some other changes, so let me know and I'll get that in there.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inline means:
|
||
| { | ||
| $valid_options = array( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can define this once as class property instead of defining this array each option set.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually better not to validate any options at all, because:
|
||
| 'features', | ||
| 'headers', | ||
| 'waitDuration', | ||
| 'proxy', | ||
| 'referrer', | ||
| 'silent', | ||
| 'site', | ||
| 'strictSSL', | ||
| 'userAgent', | ||
| 'language', | ||
| 'runScripts', | ||
| 'localAddress', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these option are specific to ZombieServer, so they should not be in this class
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've said the same in above comment. |
||
| ); | ||
|
|
||
| if (in_array($option, $valid_options)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not normal case, when non-supported option is given, so better to throw an exception immediately. |
||
| $this->options[$option] = $value; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Starts the server process | ||
| * | ||
|
|
@@ -423,6 +477,7 @@ protected function createTemporaryServer() | |
| '%host%' => $this->host, | ||
| '%port%' => $this->port, | ||
| '%modules_path%' => $this->nodeModulesPath, | ||
| '%options%' => json_encode($this->options), | ||
| )); | ||
|
|
||
| $serverPath = tempnam(sys_get_temp_dir(), 'mink_nodejs_server'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at order of existing setters/getters shows that all getters are grouped into one group, and all setters are grouped into another group. Could you please move your setter/getter to comply with that?