Skip to content

Commit

Permalink
fix(Testing): Internal variables for generated assert has prefix unde…
Browse files Browse the repository at this point in the history
…rscore
  • Loading branch information
h4kuna authored and pionl committed Nov 16, 2023
1 parent b96bf26 commit c644785
Show file tree
Hide file tree
Showing 76 changed files with 594 additions and 594 deletions.
16 changes: 8 additions & 8 deletions src/Testing/Commands/MakeExpectationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#[AsCommand(name: 'make:expectation', description: 'Make expectation class for given class')]
class MakeExpectationCommand extends Command
{
private const HookProperty = 'hook';
private const HookProperty = '_hook';

protected $signature = 'make:expectation
{class : Class name of path to class using PSR-4 specs}
Expand Down 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 @@ -7,14 +7,14 @@ namespace Tests\LaraStrict\Feature\Testing\Commands\MakeExpectationCommand;
final class MultiFunctionContractMixedExpectation
{
/**
* @param \Closure(mixed,mixed,mixed,self):void|null $hook
* @param \Closure(mixed,mixed,mixed,self):void|null $_hook
*/
public function __construct(
public readonly mixed $return,
public readonly mixed $first,
public readonly mixed $second,
public readonly mixed $third,
public readonly ?\Closure $hook = null,
public readonly ?\Closure $_hook = null,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace Tests\LaraStrict\Feature\Testing\Commands\MakeExpectationCommand;
final class MultiFunctionContractNoParamsExpectation
{
/**
* @param \Closure(self):void|null $hook
* @param \Closure(self):void|null $_hook
*/
public function __construct(
public readonly string $return,
public readonly ?\Closure $hook = null,
public readonly ?\Closure $_hook = null,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ namespace Tests\LaraStrict\Feature\Testing\Commands\MakeExpectationCommand;
final class MultiFunctionContractNoReturnExpectation
{
/**
* @param \Closure(mixed,mixed,mixed,self):void|null $hook
* @param \Closure(mixed,mixed,mixed,self):void|null $_hook
*/
public function __construct(
public readonly mixed $first,
public readonly mixed $second,
public readonly mixed $third,
public readonly ?\Closure $hook = null,
public readonly ?\Closure $_hook = null,
) {
}
}

0 comments on commit c644785

Please sign in to comment.