diff --git a/src/DeclareStatement.php b/src/DeclareStatement.php index 9e6f678a..faf55ee6 100644 --- a/src/DeclareStatement.php +++ b/src/DeclareStatement.php @@ -26,8 +26,7 @@ class DeclareStatement self::ENCODING => 'string', ]; - /** @var string */ - protected $directive; + protected string $directive; /** @var int|string */ protected $value; diff --git a/src/Generator/AbstractGenerator.php b/src/Generator/AbstractGenerator.php index d5920d58..1de17bc0 100644 --- a/src/Generator/AbstractGenerator.php +++ b/src/Generator/AbstractGenerator.php @@ -24,14 +24,15 @@ abstract class AbstractGenerator implements GeneratorInterface */ public const LINE_FEED = "\n"; - /** @var bool */ - protected $isSourceDirty = true; + protected bool $isSourceDirty = true; - /** @var int|string 4 spaces by default */ - protected $indentation = ' '; + /** @var string 4 spaces by default */ + protected string $indentation = ' '; - /** @var string */ - protected $sourceContent; + /** + * TODO: Type should be changed to "string" in the next major version. Nullable for BC + */ + protected ?string $sourceContent = null; /** * @param array $options @@ -80,7 +81,7 @@ public function getIndentation() } /** - * @param string $sourceContent + * @param ?string $sourceContent * @return AbstractGenerator */ public function setSourceContent($sourceContent) @@ -90,7 +91,7 @@ public function setSourceContent($sourceContent) } /** - * @return string + * @return ?string */ public function getSourceContent() { diff --git a/src/Generator/AbstractMemberGenerator.php b/src/Generator/AbstractMemberGenerator.php index 0d18a148..d2f05762 100644 --- a/src/Generator/AbstractMemberGenerator.php +++ b/src/Generator/AbstractMemberGenerator.php @@ -25,17 +25,14 @@ abstract class AbstractMemberGenerator extends AbstractGenerator public const VISIBILITY_PROTECTED = 'protected'; public const VISIBILITY_PRIVATE = 'private'; - /** @var DocBlockGenerator|null */ - protected $docBlock; + protected ?DocBlockGenerator $docBlock = null; - /** @var string */ - protected $name; + protected string $name = ''; - /** @var int */ - protected $flags = self::FLAG_PUBLIC; + protected int $flags = self::FLAG_PUBLIC; /** - * @param int|array $flags + * @param int|int[] $flags * @return AbstractMemberGenerator */ public function setFlags($flags) diff --git a/src/Generator/BodyGenerator.php b/src/Generator/BodyGenerator.php index db7c1ffa..51c209a9 100644 --- a/src/Generator/BodyGenerator.php +++ b/src/Generator/BodyGenerator.php @@ -10,8 +10,7 @@ class BodyGenerator extends AbstractGenerator { - /** @var string */ - protected $content; + protected string $content = ''; /** * @param string $content diff --git a/src/Generator/ClassGenerator.php b/src/Generator/ClassGenerator.php index 30083074..5885f5ed 100644 --- a/src/Generator/ClassGenerator.php +++ b/src/Generator/ClassGenerator.php @@ -39,41 +39,38 @@ class ClassGenerator extends AbstractGenerator implements TraitUsageInterface public const FLAG_ABSTRACT = 0x01; public const FLAG_FINAL = 0x02; - /** @var FileGenerator */ - protected $containingFileGenerator; + protected ?FileGenerator $containingFileGenerator = null; - /** @var string */ - protected $namespaceName; + protected ?string $namespaceName = null; - /** @var DocBlockGenerator */ - protected $docBlock; + protected ?DocBlockGenerator $docBlock = null; - /** @var string */ - protected $name; + protected string $name = ''; - /** @var bool */ - protected $flags = 0x00; + protected int $flags = 0x00; - /** @var string */ - protected $extendedClass; + /** @psalm-var ?class-string */ + protected ?string $extendedClass = null; /** - * @var string[] Array of string names + * Array of implemented interface names + * + * @var string[] * @psalm-var array */ - protected $implementedInterfaces = []; + protected array $implementedInterfaces = []; /** @var PropertyGenerator[] */ - protected $properties = []; + protected array $properties = []; /** @var PropertyGenerator[] */ - protected $constants = []; + protected array $constants = []; /** @var MethodGenerator[] */ - protected $methods = []; + protected array $methods = []; /** @var TraitUsageGenerator Object to encapsulate trait usage logic */ - protected $traitUsageGenerator; + protected TraitUsageGenerator $traitUsageGenerator; /** * Build a Code Generation Php Object from a Class Reflection @@ -109,7 +106,6 @@ public static function fromReflection(ClassReflection $classReflection) $interfaceNames = []; foreach ($interfaces as $interface) { - /** @var ClassReflection $interface */ $interfaceNames[] = $interface->getName(); } @@ -139,7 +135,11 @@ public static function fromReflection(ClassReflection $classReflection) $methods = []; foreach ($classReflection->getMethods() as $reflectionMethod) { - $className = $cg->getNamespaceName() ? $cg->getNamespaceName() . '\\' . $cg->getName() : $cg->getName(); + $className = $cg->getName(); + $namespaceName = $cg->getNamespaceName(); + if ($namespaceName !== null) { + $className = $namespaceName . '\\' . $className; + } if ($reflectionMethod->getDeclaringClass()->getName() == $className) { $methods[] = MethodGenerator::fromReflection($reflectionMethod); @@ -211,23 +211,24 @@ public static function fromArray(array $array) } /** - * @param string $name - * @param string $namespaceName - * @param array|string $flags - * @param string $extends - * @param array $interfaces - * @param array $properties - * @param array $methods - * @param DocBlockGenerator $docBlock + * @param string $name + * @param string $namespaceName + * @param int|int[]|null $flags + * @param class-string|null $extends + * @param string[] $interfaces + * @psalm-param array $interfaces + * @param PropertyGenerator[]|string[]|array[] $properties + * @param MethodGenerator[]|string[]|array[] $methods + * @param DocBlockGenerator $docBlock */ public function __construct( $name = null, $namespaceName = null, $flags = null, $extends = null, - $interfaces = [], - $properties = [], - $methods = [], + array $interfaces = [], + array $properties = [], + array $methods = [], $docBlock = null ) { $this->traitUsageGenerator = new TraitUsageGenerator($this); @@ -247,7 +248,7 @@ public function __construct( if ($extends !== null) { $this->setExtendedClass($extends); } - if (is_array($interfaces)) { + if ($interfaces !== []) { $this->setImplementedInterfaces($interfaces); } if ($methods !== []) { @@ -283,7 +284,7 @@ public function getName() } /** - * @param string $namespaceName + * @param ?string $namespaceName * @return self */ public function setNamespaceName($namespaceName) @@ -293,7 +294,7 @@ public function setNamespaceName($namespaceName) } /** - * @return string + * @return ?string */ public function getNamespaceName() { @@ -310,7 +311,7 @@ public function setContainingFileGenerator(FileGenerator $fileGenerator) } /** - * @return FileGenerator + * @return ?FileGenerator */ public function getContainingFileGenerator() { @@ -327,7 +328,7 @@ public function setDocBlock(DocBlockGenerator $docBlock) } /** - * @return DocBlockGenerator + * @return ?DocBlockGenerator */ public function getDocBlock() { @@ -335,7 +336,7 @@ public function getDocBlock() } /** - * @param array|string $flags + * @param int[]|int $flags * @return self */ public function setFlags($flags) @@ -354,7 +355,7 @@ public function setFlags($flags) } /** - * @param string $flag + * @param int $flag * @return self */ public function addFlag($flag) @@ -364,7 +365,7 @@ public function addFlag($flag) } /** - * @param string $flag + * @param int $flag * @return self */ public function removeFlag($flag) @@ -404,11 +405,12 @@ public function setFinal($isFinal) */ public function isFinal() { - return $this->flags & self::FLAG_FINAL; + return (bool) ($this->flags & self::FLAG_FINAL); } /** - * @param string $extendedClass + * @param ?string $extendedClass + * @psalm-param ?class-string $extendedClass * @return self */ public function setExtendedClass($extendedClass) @@ -418,7 +420,8 @@ public function setExtendedClass($extendedClass) } /** - * @return string + * @return ?string + * @psalm-return ?class-string */ public function getExtendedClass() { @@ -459,7 +462,7 @@ public function setImplementedInterfaces(array $implementedInterfaces) } /** - * @return string + * @return string[] * @psalm-return array */ public function getImplementedInterfaces() @@ -469,6 +472,7 @@ public function getImplementedInterfaces() /** * @param string $implementedInterface + * @psalm-param class-string $implementedInterface * @return bool */ public function hasImplementedInterface($implementedInterface) @@ -491,8 +495,8 @@ public function removeImplementedInterface($implementedInterface) $interfaceType = TypeGenerator::fromTypeString($implementedInterface); $this->implementedInterfaces = array_filter( - array_map([TypeGenerator::class, 'fromTypeString'], $this->implementedInterfaces), - static fn (TypeGenerator $interface): bool => ! $interfaceType->equals($interface) + $this->implementedInterfaces, + static fn (string $interface): bool => ! TypeGenerator::fromTypeString($interface)->equals($interfaceType) ); return $this; @@ -612,7 +616,7 @@ public function addConstants(array $constants) } /** - * @param array $properties + * @param PropertyGenerator[]|string[]|array[] $properties * @return self */ public function addProperties(array $properties) @@ -620,12 +624,10 @@ public function addProperties(array $properties) foreach ($properties as $property) { if ($property instanceof PropertyGenerator) { $this->addPropertyFromGenerator($property); + } elseif (is_string($property)) { + $this->addProperty($property); } else { - if (is_string($property)) { - $this->addProperty($property); - } elseif (is_array($property)) { - $this->addProperty(...array_values($property)); - } + $this->addProperty(...array_values($property)); } } @@ -792,7 +794,7 @@ public function hasProperty($propertyName) } /** - * @param array $methods + * @param MethodGenerator[]|string[]|array[] $methods * @return self */ public function addMethods(array $methods) @@ -800,12 +802,10 @@ public function addMethods(array $methods) foreach ($methods as $method) { if ($method instanceof MethodGenerator) { $this->addMethodFromGenerator($method); + } elseif (is_string($method)) { + $this->addMethod($method); } else { - if (is_string($method)) { - $this->addMethod($method); - } elseif (is_array($method)) { - $this->addMethod(...array_values($method)); - } + $this->addMethod(...array_values($method)); } } @@ -816,7 +816,7 @@ public function addMethods(array $methods) * Add Method from scalars * * @param string $name - * @param array $parameters + * @param ParameterGenerator[]|array[]|string[] $parameters * @param int $flags * @param string $body * @param string $docBlock diff --git a/src/Generator/DocBlockGenerator.php b/src/Generator/DocBlockGenerator.php index 4728c84a..09a3d87f 100644 --- a/src/Generator/DocBlockGenerator.php +++ b/src/Generator/DocBlockGenerator.php @@ -23,23 +23,17 @@ class DocBlockGenerator extends AbstractGenerator { - /** @var string */ - protected $shortDescription; + protected string $shortDescription = ''; - /** @var string */ - protected $longDescription; + protected string $longDescription = ''; - /** @var array */ - protected $tags = []; + protected array $tags = []; - /** @var string */ - protected $indentation = ''; + protected string $indentation = ''; - /** @var bool */ - protected $wordwrap = true; + protected bool $wordwrap = true; - /** @var TagManager|null */ - protected static $tagManager; + protected static ?TagManager $tagManager = null; /** * Build a DocBlock generator object from a reflection object @@ -108,9 +102,9 @@ protected static function getTagManager() } /** - * @param string $shortDescription - * @param string $longDescription - * @param array $tags + * @param ?string $shortDescription + * @param ?string $longDescription + * @param array[]|TagInterface[] $tags */ public function __construct($shortDescription = null, $longDescription = null, array $tags = []) { @@ -120,7 +114,7 @@ public function __construct($shortDescription = null, $longDescription = null, a if ($longDescription) { $this->setLongDescription($longDescription); } - if (is_array($tags) && $tags) { + if ($tags) { $this->setTags($tags); } } @@ -162,7 +156,7 @@ public function getLongDescription() } /** - * @param array $tags + * @param array[]|TagInterface[] $tags * @return DocBlockGenerator */ public function setTags(array $tags) @@ -230,7 +224,7 @@ public function getWordWrap() public function generate() { if (! $this->isSourceDirty()) { - return $this->docCommentize(trim($this->getSourceContent())); + return $this->docCommentize(trim($this->getSourceContent() ?? '')); } $output = ''; diff --git a/src/Generator/FileGenerator.php b/src/Generator/FileGenerator.php index 78a4d051..6d04d377 100644 --- a/src/Generator/FileGenerator.php +++ b/src/Generator/FileGenerator.php @@ -45,38 +45,36 @@ class FileGenerator extends AbstractGenerator { - /** @var string */ - protected $filename; + protected string $filename = ''; - /** @var DocBlockGenerator */ - protected $docBlock; + protected ?DocBlockGenerator $docBlock = null; - /** @var array */ - protected $requiredFiles = []; + /** @var string[] */ + protected array $requiredFiles = []; + + protected string $namespace = ''; + + /** @psalm-var list */ + protected array $uses = []; - /** @var string */ - protected $namespace; - /** - * @var array - * @psalm-var list - */ - protected $uses = []; /** * @var ClassGenerator[] * @psalm-var array */ - protected $classes = []; + protected array $classes = []; - /** @var string */ - protected $body; + protected string $body = ''; - /** @var DeclareStatement[] */ - protected $declares = []; + /** + * @var DeclareStatement[] + * @psalm-var array + */ + protected array $declares = []; /** * Passes $options to {@link setOptions()}. * - * @param array|Traversable $options + * @param array|Traversable|null $options */ public function __construct($options = null) { @@ -150,7 +148,7 @@ public function setDocBlock($docBlock) } /** - * @return DocBlockGenerator + * @return ?DocBlockGenerator */ public function getDocBlock() { @@ -158,7 +156,7 @@ public function getDocBlock() } /** - * @param array $requiredFiles + * @param string[] $requiredFiles * @return FileGenerator */ public function setRequiredFiles(array $requiredFiles) @@ -168,7 +166,7 @@ public function setRequiredFiles(array $requiredFiles) } /** - * @return array + * @return string[] */ public function getRequiredFiles() { @@ -258,7 +256,7 @@ public function setUse($use, $as = null) } /** - * @param array $classes + * @param array[]|string[]|ClassGenerator[] $classes * @return FileGenerator */ public function setClasses(array $classes) @@ -364,10 +362,14 @@ public function getBody() return $this->body; } - /** @return static */ + /** + * @param DeclareStatement[] $declares + * @return static + */ public function setDeclares(array $declares) { foreach ($declares as $declare) { + /** @psalm-suppress DocblockTypeContradiction $declare should be always DeclareStatement */ if (! $declare instanceof DeclareStatement) { throw new InvalidArgumentException(sprintf( '%s is expecting an array of %s objects', @@ -409,7 +411,7 @@ public function isSourceDirty() public function generate() { if ($this->isSourceDirty() === false) { - return $this->sourceContent; + return $this->sourceContent ?? ''; } $output = ''; diff --git a/src/Generator/InterfaceGenerator.php b/src/Generator/InterfaceGenerator.php index 77d91bf3..cde3a214 100644 --- a/src/Generator/InterfaceGenerator.php +++ b/src/Generator/InterfaceGenerator.php @@ -50,9 +50,11 @@ public static function fromReflection(ClassReflection $classReflection) } foreach ($classReflection->getMethods() as $reflectionMethod) { - $className = $cg->getNamespaceName() - ? $cg->getNamespaceName() . '\\' . $cg->getName() - : $cg->getName(); + $className = $cg->getName(); + $namespaceName = $cg->getNamespaceName(); + if ($namespaceName !== null) { + $className = $namespaceName . '\\' . $className; + } if ($reflectionMethod->getDeclaringClass()->getName() == $className) { $methods[] = MethodGenerator::fromReflection($reflectionMethod); diff --git a/src/Generator/MethodGenerator.php b/src/Generator/MethodGenerator.php index f067f89c..9c20d3a1 100644 --- a/src/Generator/MethodGenerator.php +++ b/src/Generator/MethodGenerator.php @@ -24,20 +24,16 @@ class MethodGenerator extends AbstractMemberGenerator { - /** @var DocBlockGenerator */ - protected $docBlock; + protected ?DocBlockGenerator $docBlock = null; /** @var ParameterGenerator[] */ - protected $parameters = []; + protected array $parameters = []; - /** @var string */ - protected $body; + protected string $body = ''; - /** @var null|TypeGenerator */ - private $returnType; + private ?TypeGenerator $returnType = null; - /** @var bool */ - private $returnsReference = false; + private bool $returnsReference = false; /** * @return MethodGenerator @@ -186,11 +182,11 @@ public static function fromArray(array $array) } /** - * @param string $name - * @param array $parameters - * @param int $flags - * @param string $body - * @param DocBlockGenerator|string $docBlock + * @param ?string $name + * @param ParameterGenerator[]|array[]|string[] $parameters + * @param int|int[] $flags + * @param ?string $body + * @param DocBlockGenerator|string|null $docBlock */ public function __construct( $name = null, @@ -217,7 +213,7 @@ public function __construct( } /** - * @param array $parameters + * @param ParameterGenerator[]|array[]|string[] $parameters * @return MethodGenerator */ public function setParameters(array $parameters) diff --git a/src/Generator/ParameterGenerator.php b/src/Generator/ParameterGenerator.php index 0a1b52d4..9e6b0420 100644 --- a/src/Generator/ParameterGenerator.php +++ b/src/Generator/ParameterGenerator.php @@ -16,26 +16,19 @@ class ParameterGenerator extends AbstractGenerator { - /** @var string */ - protected $name; + protected string $name = ''; - /** @var TypeGenerator|null */ - protected $type; + protected ?TypeGenerator $type = null; - /** @var ValueGenerator */ - protected $defaultValue; + protected ?ValueGenerator $defaultValue = null; - /** @var int */ - protected $position; + protected int $position = 0; - /** @var bool */ - protected $passedByReference = false; + protected bool $passedByReference = false; - /** @var bool */ - private $variadic = false; + private bool $variadic = false; - /** @var bool */ - private $omitDefaultValue = false; + private bool $omitDefaultValue = false; /** * @return ParameterGenerator @@ -128,10 +121,10 @@ public static function fromArray(array $array) } /** - * @param string $name - * @param string $type - * @param mixed $defaultValue - * @param int $position + * @param ?string $name + * @param ?string $type + * @param ?mixed $defaultValue + * @param ?int $position * @param bool $passByReference */ public function __construct( @@ -216,7 +209,7 @@ public function setDefaultValue($defaultValue) } /** - * @return ValueGenerator + * @return ?ValueGenerator */ public function getDefaultValue() { diff --git a/src/Generator/PropertyGenerator.php b/src/Generator/PropertyGenerator.php index 42095d35..9ca6503d 100644 --- a/src/Generator/PropertyGenerator.php +++ b/src/Generator/PropertyGenerator.php @@ -18,14 +18,11 @@ class PropertyGenerator extends AbstractMemberGenerator { public const FLAG_CONSTANT = 0x08; - /** @var bool */ - protected $isConst; + protected bool $isConst = false; - /** @var PropertyValueGenerator */ - protected $defaultValue; + protected ?PropertyValueGenerator $defaultValue = null; - /** @var bool */ - private $omitDefaultValue = false; + private bool $omitDefaultValue = false; /** * @return static @@ -128,8 +125,8 @@ public static function fromArray(array $array) } /** - * @param string $name - * @param PropertyValueGenerator|string|array $defaultValue + * @param ?string $name + * @param PropertyValueGenerator|string|array|null $defaultValue * @param int $flags */ public function __construct($name = null, $defaultValue = null, $flags = self::FLAG_PUBLIC) @@ -189,7 +186,7 @@ public function setDefaultValue( } /** - * @return PropertyValueGenerator + * @return ?PropertyValueGenerator */ public function getDefaultValue() { diff --git a/src/Generator/PropertyValueGenerator.php b/src/Generator/PropertyValueGenerator.php index db10bb38..c65e219c 100644 --- a/src/Generator/PropertyValueGenerator.php +++ b/src/Generator/PropertyValueGenerator.php @@ -10,8 +10,7 @@ class PropertyValueGenerator extends ValueGenerator { - /** @var int */ - protected $arrayDepth = 1; + protected int $arrayDepth = 1; /** * @return string diff --git a/src/Generator/TraitGenerator.php b/src/Generator/TraitGenerator.php index 0e6c59fc..0caa3f19 100644 --- a/src/Generator/TraitGenerator.php +++ b/src/Generator/TraitGenerator.php @@ -49,9 +49,11 @@ public static function fromReflection(ClassReflection $classReflection) $methods = []; foreach ($classReflection->getMethods() as $reflectionMethod) { - $className = $cg->getNamespaceName() - ? $cg->getNamespaceName() . '\\' . $cg->getName() - : $cg->getName(); + $className = $cg->getName(); + $namespaceName = $cg->getNamespaceName(); + if ($namespaceName !== null) { + $className = $namespaceName . '\\' . $className; + } if ($reflectionMethod->getDeclaringClass()->getName() == $className) { $methods[] = MethodGenerator::fromReflection($reflectionMethod); } @@ -109,8 +111,8 @@ public static function fromArray(array $array) } /** - * @param array|string $flags - * @return self + * @inheritDoc + * @param int[]|int $flags */ public function setFlags($flags) { @@ -118,7 +120,7 @@ public function setFlags($flags) } /** - * @param string $flag + * @param int $flag * @return self */ public function addFlag($flag) @@ -127,7 +129,7 @@ public function addFlag($flag) } /** - * @param string $flag + * @param int $flag * @return self */ public function removeFlag($flag) @@ -136,8 +138,7 @@ public function removeFlag($flag) } /** - * @param bool $isFinal - * @return self + * @inheritDoc */ public function setFinal($isFinal) { @@ -145,7 +146,7 @@ public function setFinal($isFinal) } /** - * @param string $extendedClass + * @param ?string $extendedClass * @return self */ public function setExtendedClass($extendedClass) @@ -154,8 +155,7 @@ public function setExtendedClass($extendedClass) } /** - * @param array $implementedInterfaces - * @return self + * @inheritDoc */ public function setImplementedInterfaces(array $implementedInterfaces) { @@ -163,8 +163,7 @@ public function setImplementedInterfaces(array $implementedInterfaces) } /** - * @param bool $isAbstract - * @return self + * @inheritDoc */ public function setAbstract($isAbstract) { diff --git a/src/Generator/TraitUsageGenerator.php b/src/Generator/TraitUsageGenerator.php index 79896f1b..39cdee30 100644 --- a/src/Generator/TraitUsageGenerator.php +++ b/src/Generator/TraitUsageGenerator.php @@ -26,20 +26,19 @@ class TraitUsageGenerator extends AbstractGenerator implements TraitUsageInterface { - /** @var ClassGenerator */ - protected $classGenerator; + protected ClassGenerator $classGenerator; - /** @var array Array of trait names */ - protected $traits = []; + /** @psalm-var array Array of trait names */ + protected array $traits = []; /** @var array Array of trait aliases */ - protected $traitAliases = []; + protected array $traitAliases = []; /** @var array Array of trait overrides */ - protected $traitOverrides = []; + protected array $traitOverrides = []; /** @var array Array of string names */ - protected $uses = []; + protected array $uses = []; public function __construct(ClassGenerator $classGenerator) { @@ -166,7 +165,6 @@ public function removeUseAlias($use) */ public function addTrait($trait) { - $traitName = $trait; if (is_array($trait)) { if (! array_key_exists('traitName', $trait)) { throw new Exception\InvalidArgumentException('Missing required value for traitName'); @@ -184,6 +182,8 @@ public function addTrait($trait) $this->addTraitOverride($insteadof); } } + } else { + $traitName = $trait; } if (! $this->hasTrait($traitName)) { diff --git a/src/Generator/TraitUsageInterface.php b/src/Generator/TraitUsageInterface.php index c199d7d3..9ac25fd8 100644 --- a/src/Generator/TraitUsageInterface.php +++ b/src/Generator/TraitUsageInterface.php @@ -41,7 +41,8 @@ public function getUses(); * key: method value: @see self::addTraitOverride * key: traitToReplace value: @see self::addTraitOverride * - * @param mixed $trait String | Array + * @param string|array $trait + * @psalm-param string|array{traitName: string, aliases?: array, insteadof?: array} $trait * @return self */ public function addTrait($trait); @@ -51,6 +52,7 @@ public function addTrait($trait); * configurations * * @param array $traits Array of string names or configurations (@see addTrait) + * @psalm-param list $traits * @return self */ public function addTraits(array $traits); diff --git a/src/Generator/ValueGenerator.php b/src/Generator/ValueGenerator.php index e77a79b3..0c3862bf 100644 --- a/src/Generator/ValueGenerator.php +++ b/src/Generator/ValueGenerator.php @@ -59,17 +59,14 @@ class ValueGenerator extends AbstractGenerator /** @var mixed */ protected $value; - /** @var string */ - protected $type = self::TYPE_AUTO; + protected string $type = self::TYPE_AUTO; - /** @var int */ - protected $arrayDepth = 0; + protected int $arrayDepth = 0; - /** @var string */ - protected $outputMode = self::OUTPUT_MULTIPLE_LINE; + protected string $outputMode = self::OUTPUT_MULTIPLE_LINE; /** @var array */ - protected $allowedTypes; + protected array $allowedTypes = []; /** * Autodetectable constants diff --git a/test/Generator/AbstractGeneratorTest.php b/test/Generator/AbstractGeneratorTest.php index c087bf41..a4e62c7e 100644 --- a/test/Generator/AbstractGeneratorTest.php +++ b/test/Generator/AbstractGeneratorTest.php @@ -28,7 +28,7 @@ public function testConstructor() ]); self::assertInstanceOf(GeneratorInterface::class, $generator); - self::assertEquals('foo', $generator->getIndentation()); + self::assertSame('foo', $generator->getIndentation()); } public function testSetOptionsThrowsExceptionOnInvalidArgument() diff --git a/test/Generator/AbstractMemberGeneratorTest.php b/test/Generator/AbstractMemberGeneratorTest.php index 70fdad30..a7517829 100644 --- a/test/Generator/AbstractMemberGeneratorTest.php +++ b/test/Generator/AbstractMemberGeneratorTest.php @@ -33,8 +33,8 @@ public function testSetFlagsWithArray() ] ); - self::assertEquals(AbstractMemberGenerator::VISIBILITY_PUBLIC, $this->fixture->getVisibility()); - self::assertEquals(true, $this->fixture->isFinal()); + self::assertSame(AbstractMemberGenerator::VISIBILITY_PUBLIC, $this->fixture->getVisibility()); + self::assertSame(true, $this->fixture->isFinal()); } public function testSetDocBlockThrowsExceptionWithInvalidType() diff --git a/test/Generator/ClassGeneratorTest.php b/test/Generator/ClassGeneratorTest.php index 62eefaf4..f9fd41b8 100644 --- a/test/Generator/ClassGeneratorTest.php +++ b/test/Generator/ClassGeneratorTest.php @@ -20,7 +20,9 @@ use LaminasTest\Code\TestAsset\FooClass; use PHPUnit\Framework\TestCase; use ReflectionMethod; +use Serializable; use stdClass; +use Throwable; use function current; use function fclose; @@ -43,7 +45,7 @@ public function testNameAccessors() { $classGenerator = new ClassGenerator(); $classGenerator->setName('TestClass'); - self::assertEquals('TestClass', $classGenerator->getName()); + self::assertSame('TestClass', $classGenerator->getName()); } public function testClassDocBlockAccessors() @@ -66,7 +68,7 @@ public function testExtendedClassAccessors() { $classGenerator = new ClassGenerator(); $classGenerator->setExtendedClass('ExtendedClass'); - self::assertEquals('ExtendedClass', $classGenerator->getExtendedClass()); + self::assertSame('ExtendedClass', $classGenerator->getExtendedClass()); } public function testHasExtendedClass() @@ -91,27 +93,27 @@ public function testImplementedInterfacesAccessors() { $classGenerator = new ClassGenerator(); $classGenerator->setImplementedInterfaces(['Class1', 'Class2']); - self::assertEquals(['Class1', 'Class2'], $classGenerator->getImplementedInterfaces()); + self::assertSame(['Class1', 'Class2'], $classGenerator->getImplementedInterfaces()); } public function testHasImplementedInterface() { $classGenerator = new ClassGenerator(); - $classGenerator->setImplementedInterfaces(['Class1', 'Class2']); + $classGenerator->setImplementedInterfaces([Throwable::class, Serializable::class]); - self::assertTrue($classGenerator->hasImplementedInterface('Class1')); + self::assertTrue($classGenerator->hasImplementedInterface(Throwable::class)); } public function testRemoveImplementedInterface() { $classGenerator = new ClassGenerator(); - $classGenerator->setImplementedInterfaces(['Class1', 'Class2']); + $classGenerator->setImplementedInterfaces([Throwable::class, Serializable::class]); - self::assertTrue($classGenerator->hasImplementedInterface('Class1')); + self::assertTrue($classGenerator->hasImplementedInterface(Throwable::class)); - $classGenerator->removeImplementedInterface('Class1'); - self::assertFalse($classGenerator->hasImplementedInterface('Class1')); - self::assertTrue($classGenerator->hasImplementedInterface('Class2')); + $classGenerator->removeImplementedInterface(Throwable::class); + self::assertFalse($classGenerator->hasImplementedInterface(Throwable::class)); + self::assertTrue($classGenerator->hasImplementedInterface(Serializable::class)); } public function testPropertyAccessors() @@ -128,7 +130,7 @@ public function testPropertyAccessors() $property = $classGenerator->getProperty('propTwo'); self::assertInstanceOf(PropertyGenerator::class, $property); - self::assertEquals('propTwo', $property->getName()); + self::assertSame('propTwo', $property->getName()); // add a new property $classGenerator->addProperty('prop3'); @@ -168,7 +170,7 @@ public function testMethodAccessors() $method = $classGenerator->getMethod('methodOne'); self::assertInstanceOf(MethodGenerator::class, $method); - self::assertEquals('methodOne', $method->getName()); + self::assertSame('methodOne', $method->getName()); // add a new property $classGenerator->addMethod('methodThree'); @@ -274,7 +276,7 @@ public function baz() EOS; $output = $classGenerator->generate(); - self::assertEquals($expectedOutput, $output, $output); + self::assertSame($expectedOutput, $output, $output); } /** @@ -341,7 +343,7 @@ class MyClass } CODE; - self::assertEquals($expected, $classGeneratorClass->generate()); + self::assertSame($expected, $classGeneratorClass->generate()); } /** @@ -360,7 +362,7 @@ class MyClass extends ParentClass } CODE; - self::assertEquals($expected, $classGeneratorClass->generate()); + self::assertSame($expected, $classGeneratorClass->generate()); } /** @@ -370,8 +372,8 @@ public function testCodeGenerationShouldTakeIntoAccountNamespacesFromReflection( { $reflClass = new ClassReflection(TestAsset\ClassWithNamespace::class); $classGenerator = ClassGenerator::fromReflection($reflClass); - self::assertEquals('LaminasTest\Code\Generator\TestAsset', $classGenerator->getNamespaceName()); - self::assertEquals('ClassWithNamespace', $classGenerator->getName()); + self::assertSame('LaminasTest\Code\Generator\TestAsset', $classGenerator->getNamespaceName()); + self::assertSame('ClassWithNamespace', $classGenerator->getName()); $expected = <<generate(); - self::assertEquals($expected, $received, $received); + self::assertSame($expected, $received, $received); } /** @@ -391,7 +393,7 @@ public function testSetNameShouldDetermineIfNamespaceSegmentIsPresent() { $classGeneratorClass = new ClassGenerator(); $classGeneratorClass->setName('My\Namespaced\FunClass'); - self::assertEquals('My\Namespaced', $classGeneratorClass->getNamespaceName()); + self::assertSame('My\Namespaced', $classGeneratorClass->getNamespaceName()); } /** @@ -577,7 +579,7 @@ public function methodOne() CODE; $output = $classGenerator->generate(); - self::assertEquals($expected, $output); + self::assertSame($expected, $output); } /** @@ -596,7 +598,10 @@ public function testCanAddConstant() self::assertInstanceOf(PropertyGenerator::class, $constant); self::assertTrue($constant->isConst()); - self::assertEquals('value', $constant->getDefaultValue()->getValue()); + + $defaultValue = $constant->getDefaultValue(); + self::assertNotNull($defaultValue); + self::assertSame('value', $defaultValue->getValue()); } /** @@ -612,8 +617,13 @@ public function testCanAddConstantsWithArrayOfGenerators() ]); self::assertCount(2, $classGenerator->getConstants()); - self::assertEquals('value1', $classGenerator->getConstant('x')->getDefaultValue()->getValue()); - self::assertEquals('value2', $classGenerator->getConstant('y')->getDefaultValue()->getValue()); + $valueX = $classGenerator->getConstant('x')->getDefaultValue(); + self::assertNotNull($valueX); + self::assertSame('value1', $valueX->getValue()); + + $valueY = $classGenerator->getConstant('y')->getDefaultValue(); + self::assertNotNull($valueY); + self::assertSame('value2', $valueY->getValue()); } /** @@ -629,8 +639,14 @@ public function testCanAddConstantsWithArrayOfKeyValues() ]); self::assertCount(2, $classGenerator->getConstants()); - self::assertEquals('value1', $classGenerator->getConstant('x')->getDefaultValue()->getValue()); - self::assertEquals('value2', $classGenerator->getConstant('y')->getDefaultValue()->getValue()); + + $valueX = $classGenerator->getConstant('x')->getDefaultValue(); + self::assertNotNull($valueX); + self::assertSame('value1', $valueX->getValue()); + + $valueY = $classGenerator->getConstant('y')->getDefaultValue(); + self::assertNotNull($valueY); + self::assertSame('value2', $valueY->getValue()); } /** @@ -664,13 +680,33 @@ public function testAddConstantAcceptsMixedScalars() $classGenerator->addConstant('f', ['v1' => ['v2' => 'v3']]); $classGenerator->addConstant('g', null); - self::assertEquals('v', $classGenerator->getConstant('a')->getDefaultValue()->getValue()); - self::assertEquals(123, $classGenerator->getConstant('b')->getDefaultValue()->getValue()); - self::assertEquals(123.456, $classGenerator->getConstant('c')->getDefaultValue()->getValue()); - self::assertEquals([], $classGenerator->getConstant('d')->getDefaultValue()->getValue()); - self::assertEquals(['v1' => 'v2'], $classGenerator->getConstant('e')->getDefaultValue()->getValue()); - self::assertEquals(['v1' => ['v2' => 'v3']], $classGenerator->getConstant('f')->getDefaultValue()->getValue()); - self::assertEquals(null, $classGenerator->getConstant('g')->getDefaultValue()->getValue()); + $valueA = $classGenerator->getConstant('a')->getDefaultValue(); + self::assertNotNull($valueA); + self::assertSame('v', $valueA->getValue()); + + $valueB = $classGenerator->getConstant('b')->getDefaultValue(); + self::assertNotNull($valueB); + self::assertSame(123, $valueB->getValue()); + + $valueC = $classGenerator->getConstant('c')->getDefaultValue(); + self::assertNotNull($valueC); + self::assertSame(123.456, $valueC->getValue()); + + $valueD = $classGenerator->getConstant('d')->getDefaultValue(); + self::assertNotNull($valueD); + self::assertSame([], $valueD->getValue()); + + $valueE = $classGenerator->getConstant('e')->getDefaultValue(); + self::assertNotNull($valueE); + self::assertSame(['v1' => 'v2'], $valueE->getValue()); + + $valueF = $classGenerator->getConstant('f')->getDefaultValue(); + self::assertNotNull($valueF); + self::assertSame(['v1' => ['v2' => 'v3']], $valueF->getValue()); + + $valueG = $classGenerator->getConstant('g')->getDefaultValue(); + self::assertNotNull($valueG); + self::assertSame(null, $valueG->getValue()); } public function testAddConstantRejectsObjectConstantValue() @@ -714,7 +750,7 @@ public function testAddConstantThrowsExceptionOnDuplicate() $classGenerator = new ClassGenerator(); $classGenerator->addConstant('x', 'value1'); - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $classGenerator->addConstant('x', 'value1'); } @@ -737,7 +773,9 @@ public function testAddPropertyIsBackwardsCompatibleWithConstants() $classGenerator->addProperty('x', 'value1', PropertyGenerator::FLAG_CONSTANT); - self::assertEquals('value1', $classGenerator->getConstant('x')->getDefaultValue()->getValue()); + $valueX = $classGenerator->getConstant('x')->getDefaultValue(); + self::assertNotNull($valueX); + self::assertSame('value1', $valueX->getValue()); } /** @@ -754,8 +792,13 @@ public function testAddPropertiesIsBackwardsCompatibleWithConstants() $classGenerator->addProperties($constants); self::assertCount(2, $classGenerator->getConstants()); - self::assertEquals('value1', $classGenerator->getConstant('x')->getDefaultValue()->getValue()); - self::assertEquals('value2', $classGenerator->getConstant('y')->getDefaultValue()->getValue()); + $valueX = $classGenerator->getConstant('x')->getDefaultValue(); + self::assertNotNull($valueX); + self::assertSame('value1', $valueX->getValue()); + + $valueY = $classGenerator->getConstant('y')->getDefaultValue(); + self::assertNotNull($valueY); + self::assertSame('value2', $valueY->getValue()); } /** @@ -767,7 +810,9 @@ public function testConstantsAddedFromReflection() $classGenerator = ClassGenerator::fromReflection($reflector); $constant = $classGenerator->getConstant('FOO'); - self::assertEquals('foo', $constant->getDefaultValue()->getValue()); + $constantValue = $constant->getDefaultValue(); + self::assertNotNull($constantValue); + self::assertSame('foo', $constantValue->getValue()); } /** @@ -817,7 +862,7 @@ protected function withParamsAndReturnType($mixed, array $array, ?callable $call CODE; - self::assertEquals($contents, $classGenerator->generate()); + self::assertSame($contents, $classGenerator->generate()); } /** @@ -852,7 +897,7 @@ public function someFunction() CODE; - self::assertEquals($contents, $classGenerator->generate()); + self::assertSame($contents, $classGenerator->generate()); } public function testCanAddTraitWithString() @@ -897,8 +942,8 @@ public function testCanAddTraitAliasWithString() $aliases = $classGenerator->getTraitAliases(); self::assertArrayHasKey('myTrait::method', $aliases); - self::assertEquals('useMe', $aliases['myTrait::method']['alias']); - self::assertEquals(ReflectionMethod::IS_PRIVATE, $aliases['myTrait::method']['visibility']); + self::assertSame('useMe', $aliases['myTrait::method']['alias']); + self::assertSame(ReflectionMethod::IS_PRIVATE, $aliases['myTrait::method']['visibility']); } public function testCanAddTraitAliasWithArray() @@ -913,8 +958,8 @@ public function testCanAddTraitAliasWithArray() $aliases = $classGenerator->getTraitAliases(); self::assertArrayHasKey('myTrait::method', $aliases); - self::assertEquals('useMe', $aliases['myTrait::method']['alias']); - self::assertEquals(ReflectionMethod::IS_PRIVATE, $aliases['myTrait::method']['visibility']); + self::assertSame('useMe', $aliases['myTrait::method']['alias']); + self::assertSame(ReflectionMethod::IS_PRIVATE, $aliases['myTrait::method']['visibility']); } public function testAddTraitAliasExceptionInvalidMethodFormat() @@ -984,8 +1029,8 @@ public function testCanAddTraitOverride() $overrides = $classGenerator->getTraitOverrides(); self::assertCount(1, $overrides); - self::assertEquals('myTrait::foo', key($overrides)); - self::assertEquals('hisTrait', $overrides['myTrait::foo'][0]); + self::assertSame('myTrait::foo', key($overrides)); + self::assertSame('hisTrait', $overrides['myTrait::foo'][0]); } public function testCanAddMultipleTraitOverrides() @@ -996,7 +1041,7 @@ public function testCanAddMultipleTraitOverrides() $overrides = $classGenerator->getTraitOverrides(); self::assertCount(2, $overrides['myTrait::foo']); - self::assertEquals('thatTrait', $overrides['myTrait::foo'][1]); + self::assertSame('thatTrait', $overrides['myTrait::foo'][1]); } public function testAddTraitOverrideExceptionInvalidMethodFormat() @@ -1067,7 +1112,7 @@ public function testCanRemoveTraitOverride() $overrides = $classGenerator->getTraitOverrides(); self::assertCount(1, $overrides['myTrait::foo']); - self::assertEquals('thatTrait', $overrides['myTrait::foo'][1]); + self::assertSame('thatTrait', $overrides['myTrait::foo'][1]); } public function testCanRemoveAllTraitOverrides() @@ -1103,7 +1148,7 @@ class myClass } CODE; - self::assertEquals($output, $classGenerator->generate()); + self::assertSame($output, $classGenerator->generate()); } /** @@ -1131,7 +1176,7 @@ class myClass } CODE; - self::assertEquals($output, $classGenerator->generate()); + self::assertSame($output, $classGenerator->generate()); } public function testGenerateWithFinalFlag() @@ -1149,7 +1194,7 @@ final class SomeClass EOS; $output = $classGenerator->generate(); - self::assertEquals($expectedOutput, $output, $output); + self::assertSame($expectedOutput, $output, $output); } public function testCorrectExtendNames() @@ -1170,7 +1215,7 @@ public function testCorrectlyExtendsFullyQualifiedParentClass() $classGenerator = new ClassGenerator(); $classGenerator->setName('ClassName'); $classGenerator->setNamespaceName('SomeNamespace'); - $classGenerator->setExtendedClass('DateTime'); + $classGenerator->setExtendedClass(DateTime::class); self::assertStringContainsString('class ClassName extends \DateTime', $classGenerator->generate()); } @@ -1181,7 +1226,7 @@ public function testCorrectlyExtendsRelativeParentClass() { $classGenerator = new ClassGenerator(); $classGenerator->setName('ClassName'); - $classGenerator->setExtendedClass('DateTime'); + $classGenerator->setExtendedClass(DateTime::class); self::assertStringContainsString('class ClassName extends DateTime', $classGenerator->generate()); } @@ -1207,8 +1252,10 @@ public function testCorrectlyExtendsProvidedAliasIfUseAliasExists() $classGenerator = new ClassGenerator(); $classGenerator->setName('ClassName'); $classGenerator->setNamespaceName('SomeNamespace'); - $classGenerator->addUse('Foo\\Bar', 'BarAlias'); - $classGenerator->setExtendedClass('BarAlias'); + /** @psalm-var class-string $useAlias */ + $useAlias = 'BarAlias'; + $classGenerator->addUse('Foo\\Bar', $useAlias); + $classGenerator->setExtendedClass($useAlias); $generated = $classGenerator->generate(); self::assertStringContainsString('class ClassName extends BarAlias', $generated); } @@ -1219,7 +1266,9 @@ public function testCorrectlyExtendsProvidedNamespaceAliasIfUseAliasExistsForNam $classGenerator->setName('ClassName'); $classGenerator->setNamespaceName('SomeNamespace'); $classGenerator->addUse('Foo\\Bar', 'BarAlias'); - $classGenerator->setExtendedClass('BarAlias\\FooBar'); + /** @psalm-var class-string $extendedClass */ + $extendedClass = 'BarAlias\\FooBar'; + $classGenerator->setExtendedClass($extendedClass); $generated = $classGenerator->generate(); self::assertStringContainsString('class ClassName extends BarAlias\\FooBar', $generated); } @@ -1230,7 +1279,10 @@ public function testCorrectlyExtendsAliasOfProvidedFQCNIfUseAliasExists() $classGenerator->setName('ClassName'); $classGenerator->setNamespaceName('SomeNamespace'); $classGenerator->addUse('Foo\\Bar', 'BarAlias'); - $classGenerator->setExtendedClass('Foo\\Bar'); + + /** @psalm-var class-string $extendedClass */ + $extendedClass = 'Foo\\Bar'; + $classGenerator->setExtendedClass($extendedClass); $generated = $classGenerator->generate(); self::assertStringContainsString('class ClassName extends BarAlias', $generated); } @@ -1241,7 +1293,10 @@ public function testCorrectlyExtendsWithNamespaceAliasOfProvidedFQCNIfUseAliasEx $classGenerator->setName('ClassName'); $classGenerator->setNamespaceName('SomeNamespace'); $classGenerator->addUse('Foo\\Bar', 'BarAlias'); - $classGenerator->setExtendedClass('Foo\\Bar\\FooBar'); + + /** @psalm-var class-string */ + $extendedClass = 'Foo\\Bar\\FooBar'; + $classGenerator->setExtendedClass($extendedClass); $generated = $classGenerator->generate(); self::assertStringContainsString('class ClassName extends BarAlias\\FooBar', $generated); } @@ -1252,11 +1307,14 @@ public function testCorrectImplementNames() $classGenerator->setName('ClassName'); $classGenerator->setNamespaceName('SomeNamespace'); $classGenerator->addUse(GeneratorInterface::class); - $classGenerator->setImplementedInterfaces([ + + /** @psalm-var array */ + $implementedInterfaces = [ 'SomeNamespace\ClassInterface', GeneratorInterface::class, 'Iteratable', - ]); + ]; + $classGenerator->setImplementedInterfaces($implementedInterfaces); $expected = 'class ClassName implements ClassInterface, GeneratorInterface, \Iteratable'; self::assertStringContainsString($expected, $classGenerator->generate()); diff --git a/test/Generator/DocBlock/Tag/AuthorTagTest.php b/test/Generator/DocBlock/Tag/AuthorTagTest.php index 769ffd35..1e1d8024 100644 --- a/test/Generator/DocBlock/Tag/AuthorTagTest.php +++ b/test/Generator/DocBlock/Tag/AuthorTagTest.php @@ -42,20 +42,20 @@ public function testGetterAndSetterPersistValue() { $this->tag->setAuthorName('Foo'); $this->tag->setAuthorEmail('Bar'); - self::assertEquals('Foo', $this->tag->getAuthorName()); - self::assertEquals('Bar', $this->tag->getAuthorEmail()); + self::assertSame('Foo', $this->tag->getAuthorName()); + self::assertSame('Bar', $this->tag->getAuthorEmail()); } public function testParamProducesCorrectDocBlockLine() { $this->tag->setAuthorName('foo'); $this->tag->setAuthorEmail('string'); - self::assertEquals('@author foo ', $this->tag->generate()); + self::assertSame('@author foo ', $this->tag->generate()); } public function testNameIsCorrect() { - self::assertEquals('author', $this->tag->getName()); + self::assertSame('author', $this->tag->getName()); } public function testConstructorWithOptions() @@ -65,7 +65,7 @@ public function testConstructorWithOptions() 'authorName' => 'foo', ]); $tagWithOptionsFromConstructor = new AuthorTag('foo', 'string'); - self::assertEquals($this->tag->generate(), $tagWithOptionsFromConstructor->generate()); + self::assertSame($this->tag->generate(), $tagWithOptionsFromConstructor->generate()); } public function testCreatingTagFromReflection() @@ -76,7 +76,7 @@ public function testCreatingTagFromReflection() /** @var AuthorTag $tag */ $tag = $this->tagmanager->createTagFromReflection($reflectionTag); self::assertInstanceOf(AuthorTag::class, $tag); - self::assertEquals('Mister Miller', $tag->getAuthorName()); - self::assertEquals('mister.miller@zend.com', $tag->getAuthorEmail()); + self::assertSame('Mister Miller', $tag->getAuthorName()); + self::assertSame('mister.miller@zend.com', $tag->getAuthorEmail()); } } diff --git a/test/Generator/DocBlock/Tag/GenericTagTest.php b/test/Generator/DocBlock/Tag/GenericTagTest.php index 0c4eb425..556e4b2e 100644 --- a/test/Generator/DocBlock/Tag/GenericTagTest.php +++ b/test/Generator/DocBlock/Tag/GenericTagTest.php @@ -42,15 +42,15 @@ public function testGetterAndSetterPersistValue() { $this->tag->setName('var'); $this->tag->setContent('string'); - self::assertEquals('var', $this->tag->getName()); - self::assertEquals('string', $this->tag->getContent()); + self::assertSame('var', $this->tag->getName()); + self::assertSame('string', $this->tag->getContent()); } public function testParamProducesCorrectDocBlockLine() { $this->tag->setName('var'); $this->tag->setContent('string'); - self::assertEquals('@var string', $this->tag->generate()); + self::assertSame('@var string', $this->tag->generate()); } public function testConstructorWithOptions() @@ -60,7 +60,7 @@ public function testConstructorWithOptions() 'content' => 'string', ]); $tagWithOptionsFromConstructor = new GenericTag('var', 'string'); - self::assertEquals($this->tag->generate(), $tagWithOptionsFromConstructor->generate()); + self::assertSame($this->tag->generate(), $tagWithOptionsFromConstructor->generate()); } public function testCreatingTagFromReflection() @@ -71,7 +71,7 @@ public function testCreatingTagFromReflection() /** @var GenericTag $tag */ $tag = $this->tagmanager->createTagFromReflection($reflectionTag); self::assertInstanceOf(GenericTag::class, $tag); - self::assertEquals('global', $tag->getName()); - self::assertEquals('string', $tag->getContent()); + self::assertSame('global', $tag->getName()); + self::assertSame('string', $tag->getContent()); } } diff --git a/test/Generator/DocBlock/Tag/LicenseTagTest.php b/test/Generator/DocBlock/Tag/LicenseTagTest.php index c25349d0..f694bbeb 100644 --- a/test/Generator/DocBlock/Tag/LicenseTagTest.php +++ b/test/Generator/DocBlock/Tag/LicenseTagTest.php @@ -43,20 +43,20 @@ public function testGetterAndSetterPersistValue() $this->tag->setUrl('foo'); $this->tag->setLicenseName('bar'); - self::assertEquals('foo', $this->tag->getUrl()); - self::assertEquals('bar', $this->tag->getLicenseName()); + self::assertSame('foo', $this->tag->getUrl()); + self::assertSame('bar', $this->tag->getLicenseName()); } public function testNameIsCorrect() { - self::assertEquals('license', $this->tag->getName()); + self::assertSame('license', $this->tag->getName()); } public function testLicenseProducesCorrectDocBlockLine() { $this->tag->setUrl('foo'); $this->tag->setLicenseName('bar bar bar'); - self::assertEquals('@license foo bar bar bar', $this->tag->generate()); + self::assertSame('@license foo bar bar bar', $this->tag->generate()); } public function testConstructorWithOptions() @@ -66,7 +66,7 @@ public function testConstructorWithOptions() 'licenseName' => 'bar', ]); $tagWithOptionsFromConstructor = new LicenseTag('foo', 'bar'); - self::assertEquals($this->tag->generate(), $tagWithOptionsFromConstructor->generate()); + self::assertSame($this->tag->generate(), $tagWithOptionsFromConstructor->generate()); } public function testCreatingTagFromReflection() @@ -77,7 +77,7 @@ public function testCreatingTagFromReflection() /** @var LicenseTag $tag */ $tag = $this->tagmanager->createTagFromReflection($reflectionTag); self::assertInstanceOf(LicenseTag::class, $tag); - self::assertEquals('http://zend.com', $tag->getUrl()); - self::assertEquals('License', $tag->getLicenseName()); + self::assertSame('http://zend.com', $tag->getUrl()); + self::assertSame('License', $tag->getLicenseName()); } } diff --git a/test/Generator/DocBlock/Tag/MethodTagTest.php b/test/Generator/DocBlock/Tag/MethodTagTest.php index 40b5063e..3b554b37 100644 --- a/test/Generator/DocBlock/Tag/MethodTagTest.php +++ b/test/Generator/DocBlock/Tag/MethodTagTest.php @@ -42,19 +42,19 @@ public function testGetterAndSetterPersistValue() { $this->tag->setIsStatic(true); $this->tag->setMethodName('method'); - self::assertEquals(true, $this->tag->isStatic()); - self::assertEquals('method', $this->tag->getMethodName()); + self::assertSame(true, $this->tag->isStatic()); + self::assertSame('method', $this->tag->getMethodName()); } public function testGetterForMethodNameTrimsCorrectly() { $this->tag->setMethodName('()method()'); - self::assertEquals('()method', $this->tag->getMethodName()); + self::assertSame('()method', $this->tag->getMethodName()); } public function testNameIsCorrect() { - self::assertEquals('method', $this->tag->getName()); + self::assertSame('method', $this->tag->getName()); } public function testParamProducesCorrectDocBlockLine() @@ -63,7 +63,7 @@ public function testParamProducesCorrectDocBlockLine() $this->tag->setMethodName('method'); $this->tag->setTypes('int'); $this->tag->setDescription('method(string $a)'); - self::assertEquals('@method static int method() method(string $a)', $this->tag->generate()); + self::assertSame('@method static int method() method(string $a)', $this->tag->generate()); } public function testConstructorWithOptions() @@ -75,7 +75,7 @@ public function testConstructorWithOptions() 'description' => 'description', ]); $tagWithOptionsFromConstructor = new MethodTag('method', ['string'], 'description', true); - self::assertEquals($this->tag->generate(), $tagWithOptionsFromConstructor->generate()); + self::assertSame($this->tag->generate(), $tagWithOptionsFromConstructor->generate()); } public function testCreatingTagFromReflection() @@ -86,9 +86,9 @@ public function testCreatingTagFromReflection() /** @var MethodTag $tag */ $tag = $this->tagmanager->createTagFromReflection($reflectionTag); self::assertInstanceOf(MethodTag::class, $tag); - self::assertEquals(true, $tag->isStatic()); - self::assertEquals('int', $tag->getTypesAsString()); - self::assertEquals('method', $tag->getMethodName()); - self::assertEquals('method(int $a)', $tag->getDescription()); + self::assertSame(true, $tag->isStatic()); + self::assertSame('int', $tag->getTypesAsString()); + self::assertSame('method', $tag->getMethodName()); + self::assertSame('method(int $a)', $tag->getDescription()); } } diff --git a/test/Generator/DocBlock/Tag/ParamTagTest.php b/test/Generator/DocBlock/Tag/ParamTagTest.php index 99c328fd..e228e4bd 100644 --- a/test/Generator/DocBlock/Tag/ParamTagTest.php +++ b/test/Generator/DocBlock/Tag/ParamTagTest.php @@ -41,18 +41,18 @@ protected function tearDown(): void public function testGetterAndSetterPersistValue() { $this->tag->setVariableName('Foo'); - self::assertEquals('Foo', $this->tag->getVariableName()); + self::assertSame('Foo', $this->tag->getVariableName()); } public function testGetterForVariableNameTrimsCorrectly() { $this->tag->setVariableName('$param$'); - self::assertEquals('param$', $this->tag->getVariableName()); + self::assertSame('param$', $this->tag->getVariableName()); } public function testNameIsCorrect() { - self::assertEquals('param', $this->tag->getName()); + self::assertSame('param', $this->tag->getName()); } public function testParamProducesCorrectDocBlockLine() @@ -60,7 +60,7 @@ public function testParamProducesCorrectDocBlockLine() $this->tag->setVariableName('foo'); $this->tag->setTypes('string|null'); $this->tag->setDescription('description'); - self::assertEquals('@param string|null $foo description', $this->tag->generate()); + self::assertSame('@param string|null $foo description', $this->tag->generate()); } public function testConstructorWithOptions() @@ -71,7 +71,7 @@ public function testConstructorWithOptions() 'description' => 'description', ]); $tagWithOptionsFromConstructor = new ParamTag('foo', ['string'], 'description'); - self::assertEquals($this->tag->generate(), $tagWithOptionsFromConstructor->generate()); + self::assertSame($this->tag->generate(), $tagWithOptionsFromConstructor->generate()); } public function testCreatingTagFromReflection() @@ -82,8 +82,8 @@ public function testCreatingTagFromReflection() /** @var ParamTag $tag */ $tag = $this->tagmanager->createTagFromReflection($reflectionTag); self::assertInstanceOf(ParamTag::class, $tag); - self::assertEquals('foo', $tag->getVariableName()); - self::assertEquals('description', $tag->getDescription()); - self::assertEquals('int', $tag->getTypesAsString()); + self::assertSame('foo', $tag->getVariableName()); + self::assertSame('description', $tag->getDescription()); + self::assertSame('int', $tag->getTypesAsString()); } } diff --git a/test/Generator/DocBlock/Tag/PropertyTagTest.php b/test/Generator/DocBlock/Tag/PropertyTagTest.php index 3e7e9b4e..7da9af3e 100644 --- a/test/Generator/DocBlock/Tag/PropertyTagTest.php +++ b/test/Generator/DocBlock/Tag/PropertyTagTest.php @@ -41,18 +41,18 @@ protected function tearDown(): void public function testGetterAndSetterPersistValue() { $this->tag->setPropertyName('property'); - self::assertEquals('property', $this->tag->getPropertyName()); + self::assertSame('property', $this->tag->getPropertyName()); } public function testGetterForVariableNameTrimsCorrectly() { $this->tag->setPropertyName('$property$'); - self::assertEquals('property$', $this->tag->getPropertyName()); + self::assertSame('property$', $this->tag->getPropertyName()); } public function testNameIsCorrect() { - self::assertEquals('property', $this->tag->getName()); + self::assertSame('property', $this->tag->getName()); } public function testParamProducesCorrectDocBlockLine() @@ -60,7 +60,7 @@ public function testParamProducesCorrectDocBlockLine() $this->tag->setPropertyName('property'); $this->tag->setTypes('string[]'); $this->tag->setDescription('description'); - self::assertEquals('@property string[] $property description', $this->tag->generate()); + self::assertSame('@property string[] $property description', $this->tag->generate()); } public function testConstructorWithOptions() @@ -71,7 +71,7 @@ public function testConstructorWithOptions() 'description' => 'description', ]); $tagWithOptionsFromConstructor = new PropertyTag('property', ['string'], 'description'); - self::assertEquals($this->tag->generate(), $tagWithOptionsFromConstructor->generate()); + self::assertSame($this->tag->generate(), $tagWithOptionsFromConstructor->generate()); } public function testCreatingTagFromReflection() @@ -82,8 +82,8 @@ public function testCreatingTagFromReflection() /** @var PropertyTag $tag */ $tag = $this->tagmanager->createTagFromReflection($reflectionTag); self::assertInstanceOf(PropertyTag::class, $tag); - self::assertEquals('foo', $tag->getPropertyName()); - self::assertEquals('description', $tag->getDescription()); - self::assertEquals('int', $tag->getTypesAsString()); + self::assertSame('foo', $tag->getPropertyName()); + self::assertSame('description', $tag->getDescription()); + self::assertSame('int', $tag->getTypesAsString()); } } diff --git a/test/Generator/DocBlock/Tag/ReturnTagTest.php b/test/Generator/DocBlock/Tag/ReturnTagTest.php index 720c1443..c0d11a17 100644 --- a/test/Generator/DocBlock/Tag/ReturnTagTest.php +++ b/test/Generator/DocBlock/Tag/ReturnTagTest.php @@ -40,14 +40,14 @@ protected function tearDown(): void public function testNameIsCorrect() { - self::assertEquals('return', $this->tag->getName()); + self::assertSame('return', $this->tag->getName()); } public function testReturnProducesCorrectDocBlockLine() { $this->tag->setTypes('string|int'); $this->tag->setDescription('bar bar bar'); - self::assertEquals('@return string|int bar bar bar', $this->tag->generate()); + self::assertSame('@return string|int bar bar bar', $this->tag->generate()); } public function testCreatingTagFromReflection() @@ -58,7 +58,7 @@ public function testCreatingTagFromReflection() /** @var ReturnTag $tag */ $tag = $this->tagmanager->createTagFromReflection($reflectionTag); self::assertInstanceOf(ReturnTag::class, $tag); - self::assertEquals('The return', $tag->getDescription()); - self::assertEquals('int', $tag->getTypesAsString()); + self::assertSame('The return', $tag->getDescription()); + self::assertSame('int', $tag->getTypesAsString()); } } diff --git a/test/Generator/DocBlock/Tag/ThrowsTagTest.php b/test/Generator/DocBlock/Tag/ThrowsTagTest.php index a8774471..8314379b 100644 --- a/test/Generator/DocBlock/Tag/ThrowsTagTest.php +++ b/test/Generator/DocBlock/Tag/ThrowsTagTest.php @@ -40,14 +40,14 @@ protected function tearDown(): void public function testNameIsCorrect() { - self::assertEquals('throws', $this->tag->getName()); + self::assertSame('throws', $this->tag->getName()); } public function testParamProducesCorrectDocBlockLine() { $this->tag->setTypes('Exception\\MyException'); $this->tag->setDescription('description'); - self::assertEquals('@throws Exception\\MyException description', $this->tag->generate()); + self::assertSame('@throws Exception\\MyException description', $this->tag->generate()); } public function testCreatingTagFromReflection() @@ -58,7 +58,7 @@ public function testCreatingTagFromReflection() /** @var ThrowsTag $tag */ $tag = $this->tagmanager->createTagFromReflection($reflectionTag); self::assertInstanceOf(ThrowsTag::class, $tag); - self::assertEquals('description', $tag->getDescription()); - self::assertEquals('Exception\Invalid', $tag->getTypesAsString()); + self::assertSame('description', $tag->getDescription()); + self::assertSame('Exception\Invalid', $tag->getTypesAsString()); } } diff --git a/test/Generator/DocBlock/Tag/TypableTagTest.php b/test/Generator/DocBlock/Tag/TypableTagTest.php index 9311c34a..e5673bfa 100644 --- a/test/Generator/DocBlock/Tag/TypableTagTest.php +++ b/test/Generator/DocBlock/Tag/TypableTagTest.php @@ -34,32 +34,32 @@ public function testGetterAndSetterPersistValue() { $this->tag->setTypes(['string', 'null']); $this->tag->setDescription('Description'); - self::assertEquals(['string', 'null'], $this->tag->getTypes()); - self::assertEquals('Description', $this->tag->getDescription()); + self::assertSame(['string', 'null'], $this->tag->getTypes()); + self::assertSame('Description', $this->tag->getDescription()); } public function testGetterForTypesAsStringWithSingleType() { $this->tag->setTypes(['string']); - self::assertEquals('string', $this->tag->getTypesAsString()); + self::assertSame('string', $this->tag->getTypesAsString()); } public function testGetterForTypesAsStringWithSingleTypeAndDelimiter() { $this->tag->setTypes(['string']); - self::assertEquals('string', $this->tag->getTypesAsString('/')); + self::assertSame('string', $this->tag->getTypesAsString('/')); } public function testGetterForTypesAsStringWithMultipleTypes() { $this->tag->setTypes(['string', 'null']); - self::assertEquals('string|null', $this->tag->getTypesAsString()); + self::assertSame('string|null', $this->tag->getTypesAsString()); } public function testGetterForTypesAsStringWithMultipleTypesAndDelimiter() { $this->tag->setTypes(['string', 'null']); - self::assertEquals('string/null', $this->tag->getTypesAsString('/')); + self::assertSame('string/null', $this->tag->getTypesAsString('/')); } public function testConstructorWithOptions() @@ -69,6 +69,6 @@ public function testConstructorWithOptions() 'description' => 'description', ]); $tagWithOptionsFromConstructor = new TypeableTag(['string', 'null'], 'description'); - self::assertEquals($this->tag->generate(), $tagWithOptionsFromConstructor->generate()); + self::assertSame($this->tag->generate(), $tagWithOptionsFromConstructor->generate()); } } diff --git a/test/Generator/DocBlock/Tag/VarTagTest.php b/test/Generator/DocBlock/Tag/VarTagTest.php index 98ed543d..f45ef534 100644 --- a/test/Generator/DocBlock/Tag/VarTagTest.php +++ b/test/Generator/DocBlock/Tag/VarTagTest.php @@ -45,12 +45,12 @@ public function testGetterAndSetterPersistValue(): void public function testGetterForVariableNameTrimsCorrectly(): void { $this->tag->setVariableName('$variable$'); - $this->assertEquals('variable$', $this->tag->getVariableName()); + $this->assertSame('variable$', $this->tag->getVariableName()); } public function testNameIsCorrect(): void { - $this->assertEquals('var', $this->tag->getName()); + $this->assertSame('var', $this->tag->getName()); } public function testParamProducesCorrectDocBlockLine(): void @@ -58,7 +58,7 @@ public function testParamProducesCorrectDocBlockLine(): void $this->tag->setVariableName('variable'); $this->tag->setTypes('string[]'); $this->tag->setDescription('description'); - $this->assertEquals('@var string[] $variable description', $this->tag->generate()); + $this->assertSame('@var string[] $variable description', $this->tag->generate()); } public function testConstructorWithOptions(): void @@ -69,7 +69,7 @@ public function testConstructorWithOptions(): void 'description' => 'description', ]); $tagWithOptionsFromConstructor = new VarTag('foo', ['string'], 'description'); - $this->assertEquals($this->tag->generate(), $tagWithOptionsFromConstructor->generate()); + $this->assertSame($this->tag->generate(), $tagWithOptionsFromConstructor->generate()); } public function testCreatingTagFromReflection(): void @@ -83,8 +83,8 @@ public function testCreatingTagFromReflection(): void $tag = $this->tagManager->createTagFromReflection($reflectionTag); $this->assertInstanceOf(VarTag::class, $tag); - $this->assertEquals('foo', $tag->getVariableName()); - $this->assertEquals('description', $tag->getDescription()); - $this->assertEquals('int', $tag->getTypesAsString()); + $this->assertSame('foo', $tag->getVariableName()); + $this->assertSame('description', $tag->getDescription()); + $this->assertSame('int', $tag->getTypesAsString()); } } diff --git a/test/Generator/DocBlockGeneratorTest.php b/test/Generator/DocBlockGeneratorTest.php index aadbe91d..07301399 100644 --- a/test/Generator/DocBlockGeneratorTest.php +++ b/test/Generator/DocBlockGeneratorTest.php @@ -55,19 +55,19 @@ public function testCanPassTagsToConstructor() $tags = $docBlockGenerator->getTags(); self::assertCount(1, $tags); - self::assertEquals('foo', $tags[0]->getName()); + self::assertSame('foo', $tags[0]->getName()); } public function testShortDescriptionGetterAndSetter() { $this->docBlockGenerator->setShortDescription('Short Description'); - self::assertEquals('Short Description', $this->docBlockGenerator->getShortDescription()); + self::assertSame('Short Description', $this->docBlockGenerator->getShortDescription()); } public function testLongDescriptionGetterAndSetter() { $this->docBlockGenerator->setLongDescription('Long Description'); - self::assertEquals('Long Description', $this->docBlockGenerator->getLongDescription()); + self::assertSame('Long Description', $this->docBlockGenerator->getLongDescription()); } public function testTagGettersAndSetters() @@ -92,7 +92,7 @@ public function testTagGettersAndSetters() EOS; - self::assertEquals($target, $this->docBlockGenerator->generate()); + self::assertSame($target, $this->docBlockGenerator->generate()); } public function testGenerationOfDocBlock() @@ -101,7 +101,7 @@ public function testGenerationOfDocBlock() $expected = '/**' . DocBlockGenerator::LINE_FEED . ' * @var Foo this is foo bar' . DocBlockGenerator::LINE_FEED . ' */' . DocBlockGenerator::LINE_FEED; - self::assertEquals($expected, $this->docBlockGenerator->generate()); + self::assertSame($expected, $this->docBlockGenerator->generate()); } public function testCreateFromArray() @@ -117,8 +117,8 @@ public function testCreateFromArray() ], ]); - self::assertEquals('foo', $docBlock->getShortDescription()); - self::assertEquals('bar', $docBlock->getLongDescription()); + self::assertSame('foo', $docBlock->getShortDescription()); + self::assertSame('bar', $docBlock->getLongDescription()); self::assertCount(1, $docBlock->getTags()); } @@ -134,7 +134,7 @@ public function testGenerateWordWrapIsEnabledByDefault() . ' * @var This is a very large string that will be wrapped if it contains more than' . DocBlockGenerator::LINE_FEED . ' * 80 characters' . DocBlockGenerator::LINE_FEED . ' */' . DocBlockGenerator::LINE_FEED; - self::assertEquals($expected, $this->docBlockGenerator->generate()); + self::assertSame($expected, $this->docBlockGenerator->generate()); } /** @@ -149,17 +149,17 @@ public function testGenerateWithWordWrapDisabled() $expected = '/**' . DocBlockGenerator::LINE_FEED . ' * @var This is a very large string that will not be wrapped if it contains more than' . ' 80 characters' . DocBlockGenerator::LINE_FEED . ' */' . DocBlockGenerator::LINE_FEED; - self::assertEquals($expected, $this->docBlockGenerator->generate()); + self::assertSame($expected, $this->docBlockGenerator->generate()); } public function testDocBlockFromReflectionLongDescription() { - self::assertEquals('Long Description', $this->reflectionDocBlockGenerator->getLongDescription()); + self::assertSame('Long Description', $this->reflectionDocBlockGenerator->getLongDescription()); } public function testDocBlockFromReflectionShortDescription() { - self::assertEquals('Short Description', $this->reflectionDocBlockGenerator->getShortDescription()); + self::assertSame('Short Description', $this->reflectionDocBlockGenerator->getShortDescription()); } public function testDocBlockFromReflectionTagsCount() diff --git a/test/Generator/FileGeneratorTest.php b/test/Generator/FileGeneratorTest.php index 0066a125..b0708d18 100644 --- a/test/Generator/FileGeneratorTest.php +++ b/test/Generator/FileGeneratorTest.php @@ -34,21 +34,21 @@ class FileGeneratorTest extends TestCase public function testConstruction() { $file = new FileGenerator(); - self::assertEquals(FileGenerator::class, get_class($file)); + self::assertSame(FileGenerator::class, get_class($file)); } public function testSourceContentGetterAndSetter() { $file = new FileGenerator(); $file->setSourceContent('Foo'); - self::assertEquals('Foo', $file->getSourceContent()); + self::assertSame('Foo', $file->getSourceContent()); } public function testIndentationGetterAndSetter() { $file = new FileGenerator(); $file->setIndentation(' '); - self::assertEquals(' ', $file->getIndentation()); + self::assertSame(' ', $file->getIndentation()); } public function testToString() @@ -76,7 +76,7 @@ abstract class SampleClass extends ExtendedClassName implements Iterator, Traver EOS; $output = $codeGenFile->generate(); - self::assertEquals($expectedOutput, $output, $output); + self::assertSame($expectedOutput, $output, $output); } public function testClassNotFoundException() @@ -111,8 +111,8 @@ public function testFileLineEndingsAreAlwaysLineFeed() $lines = explode("\n", $codeGenFile->generate()); $targetLength = strlen('require_once \'SampleClass.php\';'); - self::assertEquals($targetLength, strlen($lines[2])); - self::assertEquals(';', $lines[2][$targetLength - 1]); + self::assertSame($targetLength, strlen($lines[2])); + self::assertSame(';', $lines[2][$targetLength - 1]); } /** @@ -260,7 +260,7 @@ class SampleClass EOS; $actual = file_get_contents(sys_get_temp_dir() . '/result_file.php'); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } public function testMultiDeclareStatements(): void @@ -291,7 +291,7 @@ class SampleClass EOS; $actual = file_get_contents(sys_get_temp_dir() . '/result_file.php'); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } public function testDeclareUnknownDirectiveShouldRaiseException(): void @@ -351,7 +351,7 @@ class SampleClass EOS; $actual = file_get_contents(sys_get_temp_dir() . '/result_file.php'); - $this->assertEquals($expected, $actual); + $this->assertSame($expected, $actual); } public function testWrongDeclareTypeShouldRaiseException(): void @@ -360,6 +360,7 @@ public function testWrongDeclareTypeShouldRaiseException(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('setDeclares is expecting an array of Laminas\\Code\\DeclareStatement objects'); + /** @psalm-suppress InvalidArgument */ $generator->setDeclares([new stdClass()]); } diff --git a/test/Generator/InterfaceGeneratorTest.php b/test/Generator/InterfaceGeneratorTest.php index 307cca94..772e70b7 100644 --- a/test/Generator/InterfaceGeneratorTest.php +++ b/test/Generator/InterfaceGeneratorTest.php @@ -9,6 +9,7 @@ namespace LaminasTest\Code\Generator; use Countable; +use DateTime; use IteratorAggregate; use Laminas\Code\Generator\DocBlockGenerator; use Laminas\Code\Generator\Exception\InvalidArgumentException; @@ -36,7 +37,7 @@ public function testAbstractAccessorsReturnsFalse() public function testExtendedClassAccessors() { $classGenerator = new InterfaceGenerator(); - $classGenerator->setExtendedClass('ExtendedClass'); + $classGenerator->setExtendedClass(DateTime::class); self::assertNull($classGenerator->getExtendedClass()); } @@ -95,7 +96,7 @@ public function baz(); EOS; - self::assertEquals($expectedOutput, $classGenerator->generate()); + self::assertSame($expectedOutput, $classGenerator->generate()); } public function testSetextendedclassShouldIgnoreEmptyClassnameOnGenerate() @@ -103,7 +104,7 @@ public function testSetextendedclassShouldIgnoreEmptyClassnameOnGenerate() $classGeneratorClass = new InterfaceGenerator(); $classGeneratorClass ->setName('MyInterface') - ->setExtendedClass(''); + ->setExtendedClass(null); $expected = <<generate()); + self::assertSame($expected, $classGeneratorClass->generate()); } public function testSetextendedclassShouldNotIgnoreNonEmptyClassnameOnGenerate() @@ -119,7 +120,7 @@ public function testSetextendedclassShouldNotIgnoreNonEmptyClassnameOnGenerate() $classGeneratorClass = new InterfaceGenerator(); $classGeneratorClass ->setName('MyInterface') - ->setExtendedClass('MyInterface'); + ->setExtendedClass(DateTime::class); $expected = <<generate()); + self::assertSame($expected, $classGeneratorClass->generate()); } /** @@ -138,8 +139,8 @@ public function testCodeGenerationShouldTakeIntoAccountNamespacesFromReflection( $reflClass = new ClassReflection(FooInterface::class); $classGenerator = InterfaceGenerator::fromReflection($reflClass); - self::assertEquals('LaminasTest\Code\TestAsset', $classGenerator->getNamespaceName()); - self::assertEquals('FooInterface', $classGenerator->getName()); + self::assertSame('LaminasTest\Code\TestAsset', $classGenerator->getNamespaceName()); + self::assertSame('FooInterface', $classGenerator->getName()); $expected = <<generate(); - self::assertEquals($expected, $received, $received); + self::assertSame($expected, $received, $received); } /** @@ -164,7 +165,7 @@ public function testSetNameShouldDetermineIfNamespaceSegmentIsPresent() { $classGeneratorClass = new InterfaceGenerator(); $classGeneratorClass->setName('My\Namespaced\FunClass'); - self::assertEquals('My\Namespaced', $classGeneratorClass->getNamespaceName()); + self::assertSame('My\Namespaced', $classGeneratorClass->getNamespaceName()); } /** @@ -223,7 +224,7 @@ interface MyInterface CODE; self::assertInstanceOf(DocBlockGenerator::class, $docBlock); - self::assertEquals($expected, $output); + self::assertSame($expected, $output); } public function testGenerateClassAndAddMethod() @@ -241,7 +242,7 @@ public function methodOne(); CODE; $output = $classGenerator->generate(); - self::assertEquals($expected, $output); + self::assertSame($expected, $output); } public function testGenerateImplementsInterface() @@ -261,7 +262,7 @@ public function isEmpty(); CODE; $output = $classGenerator->generate(); - self::assertEquals($expected, $output); + self::assertSame($expected, $output); } public function testClassNotAnInterfaceException() diff --git a/test/Generator/MethodGeneratorTest.php b/test/Generator/MethodGeneratorTest.php index 04708958..ca39d375 100644 --- a/test/Generator/MethodGeneratorTest.php +++ b/test/Generator/MethodGeneratorTest.php @@ -67,14 +67,14 @@ public function testMethodParameterMutator() /** @var ParameterGenerator $foo */ $foo = array_shift($params); self::assertInstanceOf(ParameterGenerator::class, $foo); - self::assertEquals('foo', $foo->getName()); + self::assertSame('foo', $foo->getName()); $bar = array_shift($params); self::assertEquals(ParameterGenerator::fromArray(['name' => 'bar', 'type' => 'array']), $bar); /** @var ParameterGenerator $baz */ $baz = array_shift($params); - self::assertEquals('baz', $baz->getName()); + self::assertSame('baz', $baz->getName()); $this->expectException(InvalidArgumentException::class); $methodGenerator->setParameter(new stdClass()); @@ -84,7 +84,7 @@ public function testMethodBodyGetterAndSetter() { $method = new MethodGenerator(); $method->setBody('Foo'); - self::assertEquals('Foo', $method->getBody()); + self::assertSame('Foo', $method->getBody()); } public function testDocBlockGetterAndSetter() @@ -107,7 +107,7 @@ protected function withParamsAndReturnType($mixed, array $array, ?callable $call } EOS; - self::assertEquals($target, (string) $methodGenerator); + self::assertSame($target, (string) $methodGenerator); } public function testMethodFromReflection() @@ -127,7 +127,7 @@ public function someMethod() } EOS; - self::assertEquals($target, (string) $methodGenerator); + self::assertSame($target, (string) $methodGenerator); } public function testMethodFromReflectionMultiLinesIndention() @@ -151,7 +151,7 @@ public function someMethod() } EOS; - self::assertEquals($target, (string) $methodGenerator); + self::assertSame($target, (string) $methodGenerator); } /** @@ -171,7 +171,7 @@ public static function foo(\$one) EOS; - self::assertEquals($expected, $methodGenerator->generate()); + self::assertSame($expected, $methodGenerator->generate()); } /** @@ -190,7 +190,7 @@ final public function foo(\$one) } EOS; - self::assertEquals($expected, $methodGenerator->generate()); + self::assertSame($expected, $methodGenerator->generate()); } /** @@ -207,7 +207,7 @@ public function testMethodWithFinalModifierIsNotEmittedWhenMethodIsAbstract() $expected = <<generate()); + self::assertSame($expected, $methodGenerator->generate()); } /** @@ -232,7 +232,7 @@ protected static function someFoo() } EOS; - self::assertEquals($expected, $methodGeneratorProperty->generate()); + self::assertSame($expected, $methodGeneratorProperty->generate()); } /** @@ -267,15 +267,15 @@ public function testCreateFromArray() 'returntype' => '\\SampleType', ]); - self::assertEquals('SampleMethod', $methodGenerator->getName()); - self::assertEquals('foo', $methodGenerator->getBody()); + self::assertSame('SampleMethod', $methodGenerator->getName()); + self::assertSame('foo', $methodGenerator->getBody()); self::assertInstanceOf(DocBlockGenerator::class, $methodGenerator->getDocBlock()); self::assertTrue($methodGenerator->isAbstract()); self::assertTrue($methodGenerator->isFinal()); self::assertTrue($methodGenerator->isStatic()); - self::assertEquals(MethodGenerator::VISIBILITY_PROTECTED, $methodGenerator->getVisibility()); + self::assertSame(MethodGenerator::VISIBILITY_PROTECTED, $methodGenerator->getVisibility()); self::assertInstanceOf(TypeGenerator::class, $methodGenerator->getReturnType()); - self::assertEquals('\\SampleType', $methodGenerator->getReturnType()->generate()); + self::assertSame('\\SampleType', $methodGenerator->getReturnType()->generate()); } public function testCreateInterfaceMethodFromArray() @@ -298,8 +298,8 @@ public function execute(\Runnable $command); $methodGenerator->setParameter(['name' => 'command', 'type' => 'Runnable']); self::assertTrue($methodGenerator->isInterface()); - self::assertEquals('execute', $methodGenerator->getName()); - self::assertEquals($expected, $methodGenerator->generate()); + self::assertSame('execute', $methodGenerator->getName()); + self::assertSame($expected, $methodGenerator->generate()); self::assertInstanceOf(DocBlockGenerator::class, $methodGenerator->getDocBlock()); } diff --git a/test/Generator/ParameterGeneratorTest.php b/test/Generator/ParameterGeneratorTest.php index 84b13913..23233f80 100644 --- a/test/Generator/ParameterGeneratorTest.php +++ b/test/Generator/ParameterGeneratorTest.php @@ -50,14 +50,14 @@ public function testTypeGetterAndSetterPersistValue() { $parameterGenerator = new ParameterGenerator(); $parameterGenerator->setType('Foo'); - self::assertEquals('Foo', $parameterGenerator->getType()); + self::assertSame('Foo', $parameterGenerator->getType()); } public function testNameGetterAndSetterPersistValue() { $parameterGenerator = new ParameterGenerator(); $parameterGenerator->setName('Foo'); - self::assertEquals('Foo', $parameterGenerator->getName()); + self::assertSame('Foo', $parameterGenerator->getName()); } public function testDefaultValueGetterAndSetterPersistValue() @@ -66,14 +66,14 @@ public function testDefaultValueGetterAndSetterPersistValue() $value = new ValueGenerator('Foo', ValueGenerator::TYPE_CONSTANT); $parameterGenerator->setDefaultValue($value); - self::assertEquals('Foo', (string) $parameterGenerator->getDefaultValue()); + self::assertSame('Foo', (string) $parameterGenerator->getDefaultValue()); } public function testPositionGetterAndSetterPersistValue() { $parameterGenerator = new ParameterGenerator(); $parameterGenerator->setPosition(2); - self::assertEquals(2, $parameterGenerator->getPosition()); + self::assertSame(2, $parameterGenerator->getPosition()); } public function testGenerateIsCorrect() @@ -82,10 +82,10 @@ public function testGenerateIsCorrect() $parameterGenerator->setType('Foo'); $parameterGenerator->setName('bar'); $parameterGenerator->setDefaultValue(15); - self::assertEquals('\\Foo $bar = 15', $parameterGenerator->generate()); + self::assertSame('\\Foo $bar = 15', $parameterGenerator->generate()); $parameterGenerator->setDefaultValue('foo'); - self::assertEquals('\\Foo $bar = \'foo\'', $parameterGenerator->generate()); + self::assertSame('\\Foo $bar = \'foo\'', $parameterGenerator->generate()); } public function testFromReflectionGetParameterName() @@ -93,7 +93,7 @@ public function testFromReflectionGetParameterName() $reflectionParameter = $this->getFirstReflectionParameter('name'); $codeGenParam = ParameterGenerator::fromReflection($reflectionParameter); - self::assertEquals('param', $codeGenParam->getName()); + self::assertSame('param', $codeGenParam->getName()); } public function testFromReflectionGetParameterType() @@ -101,7 +101,7 @@ public function testFromReflectionGetParameterType() $reflectionParameter = $this->getFirstReflectionParameter('type'); $codeGenParam = ParameterGenerator::fromReflection($reflectionParameter); - self::assertEquals('stdClass', $codeGenParam->getType()); + self::assertSame('stdClass', $codeGenParam->getType()); } public function testFromReflectionGetReference() @@ -118,7 +118,7 @@ public function testFromReflectionGetDefaultValue() $codeGenParam = ParameterGenerator::fromReflection($reflectionParameter); $defaultValue = $codeGenParam->getDefaultValue(); - self::assertEquals('\'foo\'', (string) $defaultValue); + self::assertSame('\'foo\'', (string) $defaultValue); } /** @@ -133,8 +133,9 @@ public function testFromReflectionGetDefaultValueNotOptional() self::assertCount(2, $params); $firstParameter = ParameterGenerator::fromReflection($params[0]); - self::assertInstanceOf(ValueGenerator::class, $firstParameter->getDefaultValue()); - self::assertNull($firstParameter->getDefaultValue()->getSourceContent()); + $valueGenerator = $firstParameter->getDefaultValue(); + self::assertInstanceOf(ValueGenerator::class, $valueGenerator); + self::assertNull($valueGenerator->getSourceContent()); } public function testFromReflectionGetArrayHint() @@ -142,7 +143,7 @@ public function testFromReflectionGetArrayHint() $reflectionParameter = $this->getFirstReflectionParameter('fromArray'); $codeGenParam = ParameterGenerator::fromReflection($reflectionParameter); - self::assertEquals('array', $codeGenParam->getType()); + self::assertSame('array', $codeGenParam->getType()); } public function testFromReflectionGetWithNativeType() @@ -151,7 +152,7 @@ public function testFromReflectionGetWithNativeType() $codeGenParam = ParameterGenerator::fromReflection($reflectionParameter); self::assertNotEquals('int', $codeGenParam->getType()); - self::assertEquals('', $codeGenParam->getType()); + self::assertSame(null, $codeGenParam->getType()); } public function testCallableTypeHint() @@ -160,7 +161,7 @@ public function testCallableTypeHint() new ParameterReflection([TestAsset\CallableTypeHintClass::class, 'foo'], 'bar') ); - self::assertEquals('callable', $parameter->getType()); + self::assertSame('callable', $parameter->getType()); } /** @@ -173,7 +174,7 @@ public function testFromReflectionGenerate($methodName, $expectedCode) $reflectionParameter = $this->getFirstReflectionParameter($methodName); $codeGenParam = ParameterGenerator::fromReflection($reflectionParameter); - self::assertEquals($expectedCode, $codeGenParam->generate()); + self::assertSame($expectedCode, $codeGenParam->generate()); } /** @@ -229,14 +230,14 @@ public function testCreateFromArray() 'omitdefaultvalue' => true, ]); - self::assertEquals('SampleParameter', $parameterGenerator->getName()); - self::assertEquals('int', $parameterGenerator->getType()); + self::assertSame('SampleParameter', $parameterGenerator->getName()); + self::assertSame('int', $parameterGenerator->getType()); self::assertInstanceOf(ValueGenerator::class, $parameterGenerator->getDefaultValue()); self::assertFalse($parameterGenerator->getPassedByReference()); - self::assertEquals(1, $parameterGenerator->getPosition()); + self::assertSame(1, $parameterGenerator->getPosition()); self::assertFalse($parameterGenerator->isSourceDirty()); - self::assertEquals('foo', $parameterGenerator->getSourceContent()); - self::assertEquals('-', $parameterGenerator->getIndentation()); + self::assertSame('foo', $parameterGenerator->getSourceContent()); + self::assertSame('-', $parameterGenerator->getIndentation()); self::assertStringNotContainsString('default-foo', $parameterGenerator->generate()); $reflectionOmitDefaultValue = new ReflectionProperty($parameterGenerator, 'omitDefaultValue'); @@ -258,7 +259,7 @@ public function testParameterGeneratorReturnsCorrectTypeForNonNamespaceClasses() $param = ParameterGenerator::fromReflection($params[0]); - self::assertEquals('LaminasTest_Code_NsTest_BarClass', $param->getType()); + self::assertSame('LaminasTest_Code_NsTest_BarClass', $param->getType()); } /** @@ -273,7 +274,7 @@ public function testTypehintsWithNamespaceInNamepsacedClassReturnTypewithBacksla $param = ParameterGenerator::fromReflection($params[0]); - self::assertEquals('OtherNamespace\ParameterClass', $param->getType()); + self::assertSame('OtherNamespace\ParameterClass', $param->getType()); } /** @@ -655,6 +656,6 @@ public function testOmitType() $parameter = new ParameterGenerator('foo', 'string', 'bar'); $parameter->omitDefaultValue(); - self::assertEquals('string $foo', $parameter->generate()); + self::assertSame('string $foo', $parameter->generate()); } } diff --git a/test/Generator/PropertyGeneratorTest.php b/test/Generator/PropertyGeneratorTest.php index 34267f86..3552dcab 100644 --- a/test/Generator/PropertyGeneratorTest.php +++ b/test/Generator/PropertyGeneratorTest.php @@ -65,8 +65,8 @@ public function testSetTypeSetValueGenerate(string $type, $value, string $code): $defaultValue->setType($type); $defaultValue->setValue($value); - self::assertEquals($type, $defaultValue->getType()); - self::assertEquals($code, $defaultValue->generate()); + self::assertSame($type, $defaultValue->getType()); + self::assertSame($code, $defaultValue->generate()); } /** @@ -83,13 +83,13 @@ public function testSetBogusTypeSetValueGenerateUseAutoDetection(string $type, $ $defaultValue->setType('bogus'); $defaultValue->setValue($value); - self::assertEquals($code, $defaultValue->generate()); + self::assertSame($code, $defaultValue->generate()); } public function testPropertyReturnsSimpleValue(): void { $codeGenProperty = new PropertyGenerator('someVal', 'some string value'); - self::assertEquals(' public $someVal = \'some string value\';', $codeGenProperty->generate()); + self::assertSame(' public $someVal = \'some string value\';', $codeGenProperty->generate()); } public function testPropertyMultilineValue(): void @@ -119,7 +119,7 @@ public function testPropertyMultilineValue(): void $targetSource = $property->generate(); $targetSource = str_replace("\r", '', $targetSource); - self::assertEquals($expectedSource, $targetSource); + self::assertSame($expectedSource, $targetSource); } public function visibility(): Generator @@ -141,7 +141,7 @@ public function testPropertyCanProduceConstatWithVisibility(int $flag, string $v public function testPropertyCanProduceContstantModifier(): void { $codeGenProperty = new PropertyGenerator('someVal', 'some string value', PropertyGenerator::FLAG_CONSTANT); - self::assertEquals(' public const someVal = \'some string value\';', $codeGenProperty->generate()); + self::assertSame(' public const someVal = \'some string value\';', $codeGenProperty->generate()); } /** @@ -151,13 +151,13 @@ public function testPropertyCanProduceContstantModifierWithSetter(): void { $codeGenProperty = new PropertyGenerator('someVal', 'some string value'); $codeGenProperty->setConst(true); - self::assertEquals(' public const someVal = \'some string value\';', $codeGenProperty->generate()); + self::assertSame(' public const someVal = \'some string value\';', $codeGenProperty->generate()); } public function testPropertyCanProduceStaticModifier(): void { $codeGenProperty = new PropertyGenerator('someVal', 'some string value', PropertyGenerator::FLAG_STATIC); - self::assertEquals(' public static $someVal = \'some string value\';', $codeGenProperty->generate()); + self::assertSame(' public static $someVal = \'some string value\';', $codeGenProperty->generate()); } /** @@ -172,19 +172,23 @@ public function testPropertyWillLoadFromReflection(): void $cgProp = PropertyGenerator::fromReflection($reflProp); - self::assertEquals('_bazProperty', $cgProp->getName()); - self::assertEquals([true, false, true], $cgProp->getDefaultValue()->getValue()); - self::assertEquals('private', $cgProp->getVisibility()); + self::assertSame('_bazProperty', $cgProp->getName()); + $bazPropertyValue = $cgProp->getDefaultValue(); + self::assertNotNull($bazPropertyValue); + self::assertSame([true, false, true], $bazPropertyValue->getValue()); + self::assertSame('private', $cgProp->getVisibility()); $reflProp = $reflectionClass->getProperty('_bazStaticProperty'); // test property 2 $cgProp = PropertyGenerator::fromReflection($reflProp); - self::assertEquals('_bazStaticProperty', $cgProp->getName()); - self::assertEquals(TestAsset\TestClassWithManyProperties::FOO, $cgProp->getDefaultValue()->getValue()); + self::assertSame('_bazStaticProperty', $cgProp->getName()); + $bazStaticValue = $cgProp->getDefaultValue(); + self::assertNotNull($bazStaticValue); + self::assertSame(TestAsset\TestClassWithManyProperties::FOO, $bazStaticValue->getValue()); self::assertTrue($cgProp->isStatic()); - self::assertEquals('private', $cgProp->getVisibility()); + self::assertSame('private', $cgProp->getVisibility()); } /** @@ -197,7 +201,7 @@ public function testPropertyWillEmitStaticModifier(): void 'some string value', PropertyGenerator::FLAG_STATIC | PropertyGenerator::FLAG_PROTECTED ); - self::assertEquals(' protected static $someVal = \'some string value\';', $codeGenProperty->generate()); + self::assertSame(' protected static $someVal = \'some string value\';', $codeGenProperty->generate()); } /** @@ -219,7 +223,7 @@ public function testPropertyCanHaveDocBlock(): void */ protected static \$someVal = 'some string value'; EOS; - self::assertEquals($expected, $codeGenProperty->generate()); + self::assertSame($expected, $codeGenProperty->generate()); } public function testOtherTypesThrowExceptionOnGenerate(): void @@ -248,14 +252,14 @@ public function testCreateFromArray(): void 'omitdefaultvalue' => true, ]); - self::assertEquals('SampleProperty', $propertyGenerator->getName()); + self::assertSame('SampleProperty', $propertyGenerator->getName()); self::assertFalse($propertyGenerator->isConst()); self::assertInstanceOf(ValueGenerator::class, $propertyGenerator->getDefaultValue()); self::assertInstanceOf(DocBlockGenerator::class, $propertyGenerator->getDocBlock()); self::assertTrue($propertyGenerator->isAbstract()); self::assertTrue($propertyGenerator->isFinal()); self::assertTrue($propertyGenerator->isStatic()); - self::assertEquals(PropertyGenerator::VISIBILITY_PROTECTED, $propertyGenerator->getVisibility()); + self::assertSame(PropertyGenerator::VISIBILITY_PROTECTED, $propertyGenerator->getVisibility()); self::assertStringNotContainsString('default-foo', $propertyGenerator->generate()); $reflectionOmitDefaultValue = new ReflectionProperty($propertyGenerator, 'omitDefaultValue'); @@ -275,7 +279,7 @@ public function testPropertyDocBlockWillLoadFromReflection(): void $reflProp = $reflectionClass->getProperty('fooProperty'); $cgProp = PropertyGenerator::fromReflection($reflProp); - self::assertEquals('fooProperty', $cgProp->getName()); + self::assertSame('fooProperty', $cgProp->getName()); $docBlock = $cgProp->getDocBlock(); self::assertInstanceOf(DocBlockGenerator::class, $docBlock); @@ -284,7 +288,7 @@ public function testPropertyDocBlockWillLoadFromReflection(): void self::assertCount(1, $tags); $tag = array_shift($tags); self::assertInstanceOf(VarTag::class, $tag); - self::assertEquals('var', $tag->getName()); + self::assertSame('var', $tag->getName()); } /** @@ -296,8 +300,10 @@ public function testSetDefaultValue(string $type, $value): void $property = new PropertyGenerator(); $property->setDefaultValue($value, $type); - self::assertEquals($type, $property->getDefaultValue()->getType()); - self::assertEquals($value, $property->getDefaultValue()->getValue()); + $valueGenerator = $property->getDefaultValue(); + self::assertNotNull($valueGenerator); + self::assertSame($type, $valueGenerator->getType()); + self::assertSame($value, $valueGenerator->getValue()); } public function testOmitType() @@ -305,7 +311,7 @@ public function testOmitType() $property = new PropertyGenerator('foo', null); $property->omitDefaultValue(); - self::assertEquals(' public $foo;', $property->generate()); + self::assertSame(' public $foo;', $property->generate()); } public function testFromReflectionOmitsDefaultValueIfItIsNull(): void @@ -316,6 +322,6 @@ public function testFromReflectionOmitsDefaultValueIfItIsNull(): void $generator = PropertyGenerator::fromReflection($propertyReflection); $code = $generator->generate(); - $this->assertEquals(' public static $fooStaticProperty;', $code); + $this->assertSame(' public static $fooStaticProperty;', $code); } } diff --git a/test/Generator/PropertyValueGeneratorTest.php b/test/Generator/PropertyValueGeneratorTest.php index bf71f14e..8dafd8da 100644 --- a/test/Generator/PropertyValueGeneratorTest.php +++ b/test/Generator/PropertyValueGeneratorTest.php @@ -20,6 +20,6 @@ class PropertyValueGeneratorTest extends TestCase public function testPropertyValueAddsSemicolonToValueGenerator() { $value = new PropertyValueGenerator('foo'); - self::assertEquals('\'foo\';', $value->generate()); + self::assertSame('\'foo\';', $value->generate()); } } diff --git a/test/Generator/TraitGeneratorTest.php b/test/Generator/TraitGeneratorTest.php index f8dca7d9..a17e7aa3 100644 --- a/test/Generator/TraitGeneratorTest.php +++ b/test/Generator/TraitGeneratorTest.php @@ -8,6 +8,7 @@ namespace LaminasTest\Code\Generator; +use DateTime; use Laminas\Code\Generator\ClassGenerator; use Laminas\Code\Generator\DocBlockGenerator; use Laminas\Code\Generator\Exception\ExceptionInterface; @@ -21,6 +22,8 @@ use PHPUnit\Framework\TestCase; use ReflectionClass; use ReflectionException; +use Serializable; +use Throwable; use function current; @@ -30,10 +33,6 @@ */ class TraitGeneratorTest extends TestCase { - protected function setUp(): void - { - } - public function testConstruction(): void { $class = new TraitGenerator(); @@ -44,7 +43,7 @@ public function testNameAccessors(): void { $classGenerator = new TraitGenerator(); $classGenerator->setName('TestClass'); - self::assertEquals('TestClass', $classGenerator->getName()); + self::assertSame('TestClass', $classGenerator->getName()); } public function testClassDocBlockAccessors(): void @@ -75,7 +74,7 @@ public function testExtendedClassAccessors(): void public function testAddFlagDoesNothing(): void { $classGenerator = new TraitGenerator(); - $classGenerator->addFlag(ClassGenerator::OBJECT_TYPE); + $classGenerator->addFlag(ClassGenerator::FLAG_FINAL); self::assertSame(0x00, $this->getFlags($classGenerator)); } @@ -83,7 +82,7 @@ public function testAddFlagDoesNothing(): void public function testSetFlagsDoesNothing(): void { $classGenerator = new TraitGenerator(); - $classGenerator->setFlags(ClassGenerator::OBJECT_TYPE); + $classGenerator->setFlags(ClassGenerator::FLAG_FINAL); self::assertSame(0x00, $this->getFlags($classGenerator)); } @@ -91,9 +90,9 @@ public function testSetFlagsDoesNothing(): void public function testRemoveFlagDoesNothing(): void { $classGenerator = new TraitGenerator(); - $classGenerator->addFlag(ClassGenerator::OBJECT_TYPE); - $classGenerator->addFlag(ClassGenerator::IMPLEMENTS_KEYWORD); - $classGenerator->removeFlag(ClassGenerator::IMPLEMENTS_KEYWORD); + $classGenerator->addFlag(ClassGenerator::FLAG_ABSTRACT); + $classGenerator->addFlag(ClassGenerator::FLAG_FINAL); + $classGenerator->removeFlag(ClassGenerator::FLAG_ABSTRACT); self::assertSame(0x00, $this->getFlags($classGenerator)); } @@ -103,13 +102,13 @@ public function testSetFinalToTrueDoesNothing(): void $classGenerator = new TraitGenerator(); $classGenerator->setFinal(true); - self::assertSame(0x00, $classGenerator->isFinal()); + self::assertSame(false, $classGenerator->isFinal()); } public function testImplementedInterfacesAccessors(): void { $classGenerator = new TraitGenerator(); - $classGenerator->setImplementedInterfaces(['Class1', 'Class2']); + $classGenerator->setImplementedInterfaces([Serializable::class, Throwable::class]); self::assertCount(0, $classGenerator->getImplementedInterfaces()); } @@ -127,7 +126,7 @@ public function testPropertyAccessors(): void $property = $classGenerator->getProperty('propTwo'); self::assertInstanceOf(PropertyGenerator::class, $property); - self::assertEquals('propTwo', $property->getName()); + self::assertSame('propTwo', $property->getName()); // add a new property $classGenerator->addProperty('prop3'); @@ -167,7 +166,7 @@ public function testMethodAccessors(): void $method = $classGenerator->getMethod('methodOne'); self::assertInstanceOf(MethodGenerator::class, $method); - self::assertEquals('methodOne', $method->getName()); + self::assertSame('methodOne', $method->getName()); // add a new property $classGenerator->addMethod('methodThree'); @@ -260,7 +259,7 @@ public function baz() EOS; $output = $classGenerator->generate(); - self::assertEquals($expectedOutput, $output, $output); + self::assertSame($expectedOutput, $output, $output); } /** @@ -323,7 +322,7 @@ public function testSetextendedclassShouldIgnoreEmptyClassnameOnGenerate(): void $classGeneratorClass = new TraitGenerator(); $classGeneratorClass ->setName('MyClass') - ->setExtendedClass(''); + ->setExtendedClass(null); $expected = <<generate()); + self::assertSame($expected, $classGeneratorClass->generate()); } /** @@ -342,7 +341,7 @@ public function testSetextendedclassShouldNotIgnoreNonEmptyClassnameOnGenerate() $classGeneratorClass = new TraitGenerator(); $classGeneratorClass ->setName('MyClass') - ->setExtendedClass('ParentClass'); + ->setExtendedClass(DateTime::class); $expected = <<generate()); + self::assertSame($expected, $classGeneratorClass->generate()); } /** @@ -360,8 +359,8 @@ public function testCodeGenerationShouldTakeIntoAccountNamespacesFromReflection( { $reflClass = new ClassReflection(TestAsset\ClassWithNamespace::class); $classGenerator = TraitGenerator::fromReflection($reflClass); - self::assertEquals('LaminasTest\Code\Generator\TestAsset', $classGenerator->getNamespaceName()); - self::assertEquals('ClassWithNamespace', $classGenerator->getName()); + self::assertSame('LaminasTest\Code\Generator\TestAsset', $classGenerator->getNamespaceName()); + self::assertSame('ClassWithNamespace', $classGenerator->getName()); $expected = <<generate(); - self::assertEquals($expected, $received, $received); + self::assertSame($expected, $received, $received); } /** @@ -381,7 +380,7 @@ public function testSetNameShouldDetermineIfNamespaceSegmentIsPresent(): void { $classGeneratorClass = new TraitGenerator(); $classGeneratorClass->setName('My\Namespaced\FunClass'); - self::assertEquals('My\Namespaced', $classGeneratorClass->getNamespaceName()); + self::assertSame('My\Namespaced', $classGeneratorClass->getNamespaceName()); } /** @@ -558,7 +557,7 @@ public function methodOne() CODE; $output = $classGenerator->generate(); - self::assertEquals($expected, $output); + self::assertSame($expected, $output); } /** diff --git a/test/Generator/ValueGeneratorTest.php b/test/Generator/ValueGeneratorTest.php index 119d3d4d..88d61658 100644 --- a/test/Generator/ValueGeneratorTest.php +++ b/test/Generator/ValueGeneratorTest.php @@ -351,7 +351,7 @@ public function testPropertyDefaultValueCanHandleArrayWithUnsortedKeys($type, ar $valueGenerator->setType($type); $valueGenerator->setValue($value); - self::assertEquals($expected, $valueGenerator->generate()); + self::assertSame($expected, $valueGenerator->generate()); } public function testPropertyDefaultValueConstructor() @@ -364,14 +364,14 @@ public function testPropertyDefaultValueIsSettable() { $valueGenerator = new ValueGenerator(); $valueGenerator->setValue('foo'); - self::assertEquals('foo', $valueGenerator->getValue()); + self::assertSame('foo', $valueGenerator->getValue()); } public function testPropertyDefaultValueCanHandleStrings() { $valueGenerator = new ValueGenerator(); $valueGenerator->setValue('foo'); - self::assertEquals("'foo'", $valueGenerator->generate()); + self::assertSame("'foo'", $valueGenerator->generate()); } public function testPropertyDefaultValueCanHandleBool() @@ -406,7 +406,7 @@ public function testPropertyDefaultValueCanHandleArray($type, array $value, $exp $valueGenerator->setType($type); $valueGenerator->setValue($value); - self::assertEquals($expected, $valueGenerator->generate()); + self::assertSame($expected, $valueGenerator->generate()); } public function testPropertyDefaultValueCanHandleUnquotedString() @@ -414,15 +414,15 @@ public function testPropertyDefaultValueCanHandleUnquotedString() $valueGenerator = new ValueGenerator(); $valueGenerator->setValue('PHP_EOL'); $valueGenerator->setType('constant'); - self::assertEquals('PHP_EOL', $valueGenerator->generate()); + self::assertSame('PHP_EOL', $valueGenerator->generate()); $valueGenerator = new ValueGenerator(); $valueGenerator->setValue(5); - self::assertEquals('5', $valueGenerator->generate()); + self::assertSame('5', $valueGenerator->generate()); $valueGenerator = new ValueGenerator(); $valueGenerator->setValue(5.25); - self::assertEquals('5.25', $valueGenerator->generate()); + self::assertSame('5.25', $valueGenerator->generate()); } /** @@ -438,7 +438,7 @@ public function testPropertyDefaultValueCanHandleComplexArrayOfTypes($type, arra $valueGenerator->setType($type); $valueGenerator->setValue($value); - self::assertEquals($expected, $valueGenerator->generate()); + self::assertSame($expected, $valueGenerator->generate()); } /** @@ -454,7 +454,7 @@ public function testPropertyDefaultValueCanHandleComplexArrayWCustomIndentOfType $valueGenerator->setValue($value); $valueGenerator->setIndentation("\t"); - self::assertEquals($expected, $valueGenerator->generate()); + self::assertSame($expected, $valueGenerator->generate()); } /**