-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from evktalo/feature/magento-2-4-4
Support for PHP 8 and PHPUnit 9
- Loading branch information
Showing
12 changed files
with
540 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Olmer\UnitTestsGenerator\Code\Generator; | ||
|
||
class ClassNameParser | ||
{ | ||
/** | ||
* @param string $content | ||
* | ||
* @return string | ||
*/ | ||
public function parseClassName(string $content): string | ||
{ | ||
$class = $namespace = ''; | ||
$i = 0; | ||
$tokens = \token_get_all($content); | ||
$tokensCount = \count($tokens); | ||
for (; $i < $tokensCount; $i++) { | ||
if ($tokens[$i][0] === T_NAMESPACE) { | ||
for ($j = $i + 1; $j < $tokensCount; $j++) { | ||
// T_NAME_QUALIFIED for PHP > 8.0, T_STRING as fallback | ||
$qualifiedNameToken = defined('T_NAME_QUALIFIED') ? T_NAME_QUALIFIED : T_STRING; | ||
if ($tokens[$j][0] === $qualifiedNameToken) { | ||
$namespace .= '\\' . $tokens[$j][1]; | ||
} else { | ||
if ($tokens[$j] === '{' || $tokens[$j] === ';') { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
if ($tokens[$i][0] === T_CLASS) { | ||
for ($j = $i + 1; $j < $tokensCount; $j++) { | ||
if ($tokens[$j] === '{') { | ||
$class = '\\' . $tokens[$i + 2][1]; | ||
break 2; | ||
} | ||
} | ||
} | ||
} | ||
return $namespace . $class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Olmer\UnitTestsGenerator\Code\Generator\UnitTest; | ||
|
||
class ConstructorArgumentsResolver | ||
{ | ||
/** | ||
* @param \ReflectionMethod $constructor | ||
* | ||
* @return array | ||
*/ | ||
public function resolve(\ReflectionMethod $constructor): array | ||
{ | ||
$constructorArguments = []; | ||
|
||
try { | ||
foreach ($constructor->getParameters() as $parameter) { | ||
if (!$parameter->getType()) { | ||
continue; | ||
} | ||
$constructorArguments[] = [ | ||
'name' => $parameter->getName(), | ||
'class' => $parameter->getType()->getName() | ||
]; | ||
} | ||
} catch (\ReflectionException $e) { | ||
return $constructorArguments; | ||
} | ||
|
||
return $constructorArguments; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Olmer\UnitTestsGenerator\Code\Generator\UnitTest; | ||
|
||
class SetupMethodBuilder | ||
{ | ||
/** | ||
* @param array $setupMethodParamsDefinition | ||
* @param string $testObjectCreationCode | ||
* | ||
* @return array | ||
*/ | ||
public function build(array $setupMethodParamsDefinition, string $testObjectCreationCode): array | ||
{ | ||
return [ | ||
'name' => 'setUp', | ||
'parameters' => [], | ||
'body' => "\$this->objectManager = new ObjectManager(\$this);\n" | ||
. \implode("\n", $setupMethodParamsDefinition) . "\n" | ||
. $testObjectCreationCode, | ||
'docblock' => [ | ||
'shortDescription' => 'Main set up method', | ||
], | ||
'returnType' => 'void' | ||
]; | ||
} | ||
} |
Oops, something went wrong.