Skip to content

Commit

Permalink
Internal variables for generated assert has prefix underscore
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna committed Nov 15, 2023
1 parent b96bf26 commit 1ff3b82
Show file tree
Hide file tree
Showing 14 changed files with 470 additions and 470 deletions.
14 changes: 7 additions & 7 deletions src/Testing/Commands/MakeExpectationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,33 +195,33 @@ protected function generateExpectationMethodAssert(
$assertClass->addMember($assertMethod);

$assertMethod->addBody(sprintf(
'$expectation = $this->getExpectation(%s);',
'$_expectation = $this->getExpectation(%s);',
$expectationClassName . '::class'
));

$hookParameters = [];

if ($parameters !== []) {
$assertMethod->addBody('$message = $this->getDebugMessage();');
$assertMethod->addBody('$_message = $this->getDebugMessage();');
$assertMethod->addBody('');

foreach ($parameters as $parameter) {
$hookParameters[] = sprintf('$%s', $parameter->name);
$assertMethod->addBody(sprintf(
'Assert::assertEquals($expectation->%s, $%s, $message);',
'Assert::assertEquals($_expectation->%s, $%s, $_message);',
$parameter->name,
$parameter->name
));
}
}

$hookParameters[] = '$expectation';
$hookParameters[] = '$_expectation';

$assertMethod->addBody('');

$assertMethod->addBody(sprintf('if (is_callable($expectation->%s)) {', self::HookProperty));
$assertMethod->addBody(sprintf('if (is_callable($_expectation->%s)) {', self::HookProperty));
$assertMethod->addBody(sprintf(
' call_user_func($expectation->%s, %s);',
' call_user_func($_expectation->%s, %s);',
self::HookProperty,
implode(', ', $hookParameters),
));
Expand All @@ -240,7 +240,7 @@ protected function generateExpectationMethodAssert(
switch ($enumReturnType) {
case PhpType::Mixed:
$assertMethod->addBody('');
$assertMethod->addBody('return $expectation->return;');
$assertMethod->addBody('return $_expectation->return;');
break;
case PhpType::Self:
case PhpType::Static:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ class MultiFunctionContractAssert extends \LaraStrict\Testing\Assert\AbstractExp

function self(string $first, int $second, bool $third): self
{
$expectation = $this->getExpectation(MultiFunctionContractSelfExpectation::class);
$message = $this->getDebugMessage();
$_expectation = $this->getExpectation(MultiFunctionContractSelfExpectation::class);
$_message = $this->getDebugMessage();

Assert::assertEquals($expectation->first, $first, $message);
Assert::assertEquals($expectation->second, $second, $message);
Assert::assertEquals($expectation->third, $third, $message);
Assert::assertEquals($_expectation->first, $first, $_message);
Assert::assertEquals($_expectation->second, $second, $_message);
Assert::assertEquals($_expectation->third, $third, $_message);

if (is_callable($expectation->hook)) {
call_user_func($expectation->hook, $first, $second, $third, $expectation);
if (is_callable($_expectation->hook)) {
call_user_func($_expectation->hook, $first, $second, $third, $_expectation);
}

return $this;
Expand All @@ -72,15 +72,15 @@ class MultiFunctionContractAssert extends \LaraStrict\Testing\Assert\AbstractExp
*/
function phpDocThis(string $first, int $second, bool $third)
{
$expectation = $this->getExpectation(MultiFunctionContractPhpDocThisExpectation::class);
$message = $this->getDebugMessage();
$_expectation = $this->getExpectation(MultiFunctionContractPhpDocThisExpectation::class);
$_message = $this->getDebugMessage();

Assert::assertEquals($expectation->first, $first, $message);
Assert::assertEquals($expectation->second, $second, $message);
Assert::assertEquals($expectation->third, $third, $message);
Assert::assertEquals($_expectation->first, $first, $_message);
Assert::assertEquals($_expectation->second, $second, $_message);
Assert::assertEquals($_expectation->third, $third, $_message);

if (is_callable($expectation->hook)) {
call_user_func($expectation->hook, $first, $second, $third, $expectation);
if (is_callable($_expectation->hook)) {
call_user_func($_expectation->hook, $first, $second, $third, $_expectation);
}

return $this;
Expand All @@ -95,15 +95,15 @@ class MultiFunctionContractAssert extends \LaraStrict\Testing\Assert\AbstractExp
*/
function phpDocThisParams($first, $second, $third)
{
$expectation = $this->getExpectation(MultiFunctionContractPhpDocThisParamsExpectation::class);
$message = $this->getDebugMessage();
$_expectation = $this->getExpectation(MultiFunctionContractPhpDocThisParamsExpectation::class);
$_message = $this->getDebugMessage();

Assert::assertEquals($expectation->first, $first, $message);
Assert::assertEquals($expectation->second, $second, $message);
Assert::assertEquals($expectation->third, $third, $message);
Assert::assertEquals($_expectation->first, $first, $_message);
Assert::assertEquals($_expectation->second, $second, $_message);
Assert::assertEquals($_expectation->third, $third, $_message);

if (is_callable($expectation->hook)) {
call_user_func($expectation->hook, $first, $second, $third, $expectation);
if (is_callable($_expectation->hook)) {
call_user_func($_expectation->hook, $first, $second, $third, $_expectation);
}

return $this;
Expand All @@ -114,91 +114,91 @@ class MultiFunctionContractAssert extends \LaraStrict\Testing\Assert\AbstractExp
*/
function phpDocBool($first, $second, callable $third)
{
$expectation = $this->getExpectation(MultiFunctionContractPhpDocBoolExpectation::class);
$message = $this->getDebugMessage();
$_expectation = $this->getExpectation(MultiFunctionContractPhpDocBoolExpectation::class);
$_message = $this->getDebugMessage();

Assert::assertEquals($expectation->first, $first, $message);
Assert::assertEquals($expectation->second, $second, $message);
Assert::assertEquals($expectation->third, $third, $message);
Assert::assertEquals($_expectation->first, $first, $_message);
Assert::assertEquals($_expectation->second, $second, $_message);
Assert::assertEquals($_expectation->third, $third, $_message);

if (is_callable($expectation->hook)) {
call_user_func($expectation->hook, $first, $second, $third, $expectation);
if (is_callable($_expectation->hook)) {
call_user_func($_expectation->hook, $first, $second, $third, $_expectation);
}

return $expectation->return;
return $_expectation->return;
}

/**
* @return string
*/
function phpDocString($first, $second, $third)
{
$expectation = $this->getExpectation(MultiFunctionContractPhpDocStringExpectation::class);
$message = $this->getDebugMessage();
$_expectation = $this->getExpectation(MultiFunctionContractPhpDocStringExpectation::class);
$_message = $this->getDebugMessage();

Assert::assertEquals($expectation->first, $first, $message);
Assert::assertEquals($expectation->second, $second, $message);
Assert::assertEquals($expectation->third, $third, $message);
Assert::assertEquals($_expectation->first, $first, $_message);
Assert::assertEquals($_expectation->second, $second, $_message);
Assert::assertEquals($_expectation->third, $third, $_message);

if (is_callable($expectation->hook)) {
call_user_func($expectation->hook, $first, $second, $third, $expectation);
if (is_callable($_expectation->hook)) {
call_user_func($_expectation->hook, $first, $second, $third, $_expectation);
}

return $expectation->return;
return $_expectation->return;
}

/**
* @return float
*/
function phpDocFloat($first, $second, $third)
{
$expectation = $this->getExpectation(MultiFunctionContractPhpDocFloatExpectation::class);
$message = $this->getDebugMessage();
$_expectation = $this->getExpectation(MultiFunctionContractPhpDocFloatExpectation::class);
$_message = $this->getDebugMessage();

Assert::assertEquals($expectation->first, $first, $message);
Assert::assertEquals($expectation->second, $second, $message);
Assert::assertEquals($expectation->third, $third, $message);
Assert::assertEquals($_expectation->first, $first, $_message);
Assert::assertEquals($_expectation->second, $second, $_message);
Assert::assertEquals($_expectation->third, $third, $_message);

if (is_callable($expectation->hook)) {
call_user_func($expectation->hook, $first, $second, $third, $expectation);
if (is_callable($_expectation->hook)) {
call_user_func($_expectation->hook, $first, $second, $third, $_expectation);
}

return $expectation->return;
return $_expectation->return;
}

/**
* @return mixed
*/
function phpDocMixed($first, $second, $third)
{
$expectation = $this->getExpectation(MultiFunctionContractPhpDocMixedExpectation::class);
$message = $this->getDebugMessage();
$_expectation = $this->getExpectation(MultiFunctionContractPhpDocMixedExpectation::class);
$_message = $this->getDebugMessage();

Assert::assertEquals($expectation->first, $first, $message);
Assert::assertEquals($expectation->second, $second, $message);
Assert::assertEquals($expectation->third, $third, $message);
Assert::assertEquals($_expectation->first, $first, $_message);
Assert::assertEquals($_expectation->second, $second, $_message);
Assert::assertEquals($_expectation->third, $third, $_message);

if (is_callable($expectation->hook)) {
call_user_func($expectation->hook, $first, $second, $third, $expectation);
if (is_callable($_expectation->hook)) {
call_user_func($_expectation->hook, $first, $second, $third, $_expectation);
}

return $expectation->return;
return $_expectation->return;
}

/**
* @return static
*/
function phpDocStatic($first, $second, $third)
{
$expectation = $this->getExpectation(MultiFunctionContractPhpDocStaticExpectation::class);
$message = $this->getDebugMessage();
$_expectation = $this->getExpectation(MultiFunctionContractPhpDocStaticExpectation::class);
$_message = $this->getDebugMessage();

Assert::assertEquals($expectation->first, $first, $message);
Assert::assertEquals($expectation->second, $second, $message);
Assert::assertEquals($expectation->third, $third, $message);
Assert::assertEquals($_expectation->first, $first, $_message);
Assert::assertEquals($_expectation->second, $second, $_message);
Assert::assertEquals($_expectation->third, $third, $_message);

if (is_callable($expectation->hook)) {
call_user_func($expectation->hook, $first, $second, $third, $expectation);
if (is_callable($_expectation->hook)) {
call_user_func($_expectation->hook, $first, $second, $third, $_expectation);
}

return $this;
Expand All @@ -209,58 +209,58 @@ class MultiFunctionContractAssert extends \LaraStrict\Testing\Assert\AbstractExp
*/
function selfViaClass($first, $second, $third)
{
$expectation = $this->getExpectation(MultiFunctionContractSelfViaClassExpectation::class);
$message = $this->getDebugMessage();
$_expectation = $this->getExpectation(MultiFunctionContractSelfViaClassExpectation::class);
$_message = $this->getDebugMessage();

Assert::assertEquals($expectation->first, $first, $message);
Assert::assertEquals($expectation->second, $second, $message);
Assert::assertEquals($expectation->third, $third, $message);
Assert::assertEquals($_expectation->first, $first, $_message);
Assert::assertEquals($_expectation->second, $second, $_message);
Assert::assertEquals($_expectation->third, $third, $_message);

if (is_callable($expectation->hook)) {
call_user_func($expectation->hook, $first, $second, $third, $expectation);
if (is_callable($_expectation->hook)) {
call_user_func($_expectation->hook, $first, $second, $third, $_expectation);
}

return $expectation->return;
return $_expectation->return;
}

function noReturn($first, $second, $third)
{
$expectation = $this->getExpectation(MultiFunctionContractNoReturnExpectation::class);
$message = $this->getDebugMessage();
$_expectation = $this->getExpectation(MultiFunctionContractNoReturnExpectation::class);
$_message = $this->getDebugMessage();

Assert::assertEquals($expectation->first, $first, $message);
Assert::assertEquals($expectation->second, $second, $message);
Assert::assertEquals($expectation->third, $third, $message);
Assert::assertEquals($_expectation->first, $first, $_message);
Assert::assertEquals($_expectation->second, $second, $_message);
Assert::assertEquals($_expectation->third, $third, $_message);

if (is_callable($expectation->hook)) {
call_user_func($expectation->hook, $first, $second, $third, $expectation);
if (is_callable($_expectation->hook)) {
call_user_func($_expectation->hook, $first, $second, $third, $_expectation);
}
}

function mixed($first, $second, $third): mixed
{
$expectation = $this->getExpectation(MultiFunctionContractMixedExpectation::class);
$message = $this->getDebugMessage();
$_expectation = $this->getExpectation(MultiFunctionContractMixedExpectation::class);
$_message = $this->getDebugMessage();

Assert::assertEquals($expectation->first, $first, $message);
Assert::assertEquals($expectation->second, $second, $message);
Assert::assertEquals($expectation->third, $third, $message);
Assert::assertEquals($_expectation->first, $first, $_message);
Assert::assertEquals($_expectation->second, $second, $_message);
Assert::assertEquals($_expectation->third, $third, $_message);

if (is_callable($expectation->hook)) {
call_user_func($expectation->hook, $first, $second, $third, $expectation);
if (is_callable($_expectation->hook)) {
call_user_func($_expectation->hook, $first, $second, $third, $_expectation);
}

return $expectation->return;
return $_expectation->return;
}

function noParams(): string
{
$expectation = $this->getExpectation(MultiFunctionContractNoParamsExpectation::class);
$_expectation = $this->getExpectation(MultiFunctionContractNoParamsExpectation::class);

if (is_callable($expectation->hook)) {
call_user_func($expectation->hook, $expectation);
if (is_callable($_expectation->hook)) {
call_user_func($_expectation->hook, $_expectation);
}

return $expectation->return;
return $_expectation->return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ function __construct(array $execute = [])

function execute(string $first, int $second, bool $third)
{
$expectation = $this->getExpectation(SimpleActionContractExpectation::class);
$message = $this->getDebugMessage();
$_expectation = $this->getExpectation(SimpleActionContractExpectation::class);
$_message = $this->getDebugMessage();

Assert::assertEquals($expectation->first, $first, $message);
Assert::assertEquals($expectation->second, $second, $message);
Assert::assertEquals($expectation->third, $third, $message);
Assert::assertEquals($_expectation->first, $first, $_message);
Assert::assertEquals($_expectation->second, $second, $_message);
Assert::assertEquals($_expectation->third, $third, $_message);

if (is_callable($expectation->hook)) {
call_user_func($expectation->hook, $first, $second, $third, $expectation);
if (is_callable($_expectation->hook)) {
call_user_func($_expectation->hook, $first, $second, $third, $_expectation);
}
}
}
Loading

0 comments on commit 1ff3b82

Please sign in to comment.