Skip to content

adding support for optional and referenced parameters in BUILT-IN functions #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 20, 2017

Conversation

bhoehl
Copy link
Contributor

@bhoehl bhoehl commented May 2, 2017

@DavertMik
fixes bug:
#106

@@ -3,54 +3,123 @@

class FunctionInjector
{
protected $template = <<<EOF
protected $template = <<<EOF

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

}
EOF;

protected $templateByRefOptional = <<<EOF

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

$this->function = $function;
$this->place('ns', $this->namespace);
$this->place('func', $this->function);
protected $namespace;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed


}
protected $function;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed


}
protected $function;
protected $fileName;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

$this->fileName = tempnam(sys_get_temp_dir(), $this->function);
file_put_contents($this->fileName, $this->template);
}
function __construct($namespace, $function)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Spaces must be used to indent lines; tabs are not allowed
  • Visibility must be declared on method __construct

file_put_contents($this->fileName, $this->template);
}
function __construct($namespace, $function)
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

}
function __construct($namespace, $function)
{
$this->namespace = $namespace;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

function __construct($namespace, $function)
{
$this->namespace = $namespace;
$this->function = $function;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

{
$this->namespace = $namespace;
$this->function = $function;
$this->placeOptionalAndReferenceFunction($namespace, $function);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

$this->namespace = $namespace;
$this->function = $function;
$this->placeOptionalAndReferenceFunction($namespace, $function);
$this->place('ns', $this->namespace);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

$this->function = $function;
$this->placeOptionalAndReferenceFunction($namespace, $function);
$this->place('ns', $this->namespace);
$this->place('func', $this->function);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

$this->placeOptionalAndReferenceFunction($namespace, $function);
$this->place('ns', $this->namespace);
$this->place('func', $this->function);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

{
require_once $this->fileName;
}
public function getParameterDeclaration(\ReflectionParameter $parameter)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

require_once $this->fileName;
}
public function getParameterDeclaration(\ReflectionParameter $parameter)
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

}
public function getParameterDeclaration(\ReflectionParameter $parameter)
{
$text = (string)$parameter;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

public function getParameterDeclaration(\ReflectionParameter $parameter)
{
$text = (string)$parameter;
if (preg_match('@Parameter\s#[0-9]+\s\[\s<(required|optional)>(.*)(\sor NULL)(.*)\s\]@', $text, $match)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

{
$text = (string)$parameter;
if (preg_match('@Parameter\s#[0-9]+\s\[\s<(required|optional)>(.*)(\sor NULL)(.*)\s\]@', $text, $match)) {
$text = $match(2).$match[4];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

$text = (string)$parameter;
if (preg_match('@Parameter\s#[0-9]+\s\[\s<(required|optional)>(.*)(\sor NULL)(.*)\s\]@', $text, $match)) {
$text = $match(2).$match[4];
} elseif (preg_match('@Parameter\s#[0-9]+\s\[\s<(required|optional)>\s(.*)\s\]@', $text, $match)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

if (preg_match('@Parameter\s#[0-9]+\s\[\s<(required|optional)>(.*)(\sor NULL)(.*)\s\]@', $text, $match)) {
$text = $match(2).$match[4];
} elseif (preg_match('@Parameter\s#[0-9]+\s\[\s<(required|optional)>\s(.*)\s\]@', $text, $match)) {
$text = $match[2];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

$text = $match(2).$match[4];
} elseif (preg_match('@Parameter\s#[0-9]+\s\[\s<(required|optional)>\s(.*)\s\]@', $text, $match)) {
$text = $match[2];
} else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

} elseif (preg_match('@Parameter\s#[0-9]+\s\[\s<(required|optional)>\s(.*)\s\]@', $text, $match)) {
$text = $match[2];
} else {
throw new \Exception('reflection api changed. adjust code.');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

$text = $match[2];
} else {
throw new \Exception('reflection api changed. adjust code.');
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

} else {
throw new \Exception('reflection api changed. adjust code.');
}
if ($parameter->isOptional()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

throw new \Exception('reflection api changed. adjust code.');
}
if ($parameter->isOptional()) {
$text .= "=NULL";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

}
if ($parameter->isOptional()) {
$text .= "=NULL";
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

if ($parameter->isOptional()) {
$text .= "=NULL";
}
return $text;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

$text .= "=NULL";
}
return $text;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

{
return $this->fileName;
}
public function placeOptionalAndReferenceFunction($namespace, $function)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

return $this->fileName;
}
public function placeOptionalAndReferenceFunction($namespace, $function)
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

}
public function placeOptionalAndReferenceFunction($namespace, $function)
{
$reflect = new \ReflectionFunction($function);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

public function placeOptionalAndReferenceFunction($namespace, $function)
{
$reflect = new \ReflectionFunction($function);
$parameters = [];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

{
$reflect = new \ReflectionFunction($function);
$parameters = [];
$args = '';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

$reflect = new \ReflectionFunction($function);
$parameters = [];
$args = '';
$byRef = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

$parameters = [];
$args = '';
$byRef = false;
$optionals = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

$args = '';
$byRef = false;
$optionals = false;
$names = [];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces must be used to indent lines; tabs are not allowed

@bhoehl
Copy link
Contributor Author

bhoehl commented May 3, 2017

@sergeyklay
please have a look

Copy link
Contributor

@sergeyklay sergeyklay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@DavertMik Could you please take a look

@DavertMik DavertMik merged commit 39140a1 into Codeception:master Sep 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants