-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from shochdoerfer/feature/strict_dataobject
Make DataObject extension stricter
- Loading branch information
Showing
3 changed files
with
235 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
...PHPStan/Magento/Reflection/Framework/DataObjectMagicMethodReflectionExtensionUnitTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the phpstan-magento package. | ||
* | ||
* (c) bitExpert AG | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace bitExpert\PHPStan\Magento\Reflection\Framework; | ||
|
||
use PHPStan\Reflection\ClassReflection; | ||
use PHPStan\Type\BooleanType; | ||
use PHPStan\Type\MixedType; | ||
use PHPStan\Type\ObjectType; | ||
use PHPStan\Type\StringType; | ||
use PHPStan\Type\UnionType; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DataObjectMagicMethodReflectionExtensionUnitTest extends TestCase | ||
{ | ||
/** | ||
* @var DataObjectMagicMethodReflectionExtension | ||
*/ | ||
private $extension; | ||
/** | ||
* @var ClassReflection|\PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
private $classReflection; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->extension = new DataObjectMagicMethodReflectionExtension(); | ||
$this->classReflection = $this->createMock(ClassReflection::class); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function returnMagicMethodReflectionForGetMethod(): void | ||
{ | ||
$methodReflection = $this->extension->getMethod($this->classReflection, 'getTest'); | ||
|
||
$variants = $methodReflection->getVariants(); | ||
$params = $variants[0]->getParameters(); | ||
|
||
$this->assertCount(1, $variants); | ||
$this->assertInstanceOf(MixedType::class, $variants[0]->getReturnType()); | ||
$this->assertCount(2, $params); | ||
$this->assertInstanceOf(StringType::class, $params[0]->getType()); | ||
$this->assertInstanceOf(UnionType::class, $params[1]->getType()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function returnMagicMethodReflectionForSetMethod(): void | ||
{ | ||
$methodReflection = $this->extension->getMethod($this->classReflection, 'setTest'); | ||
|
||
$variants = $methodReflection->getVariants(); | ||
$params = $variants[0]->getParameters(); | ||
|
||
$this->assertCount(1, $variants); | ||
$this->assertInstanceOf(ObjectType::class, $variants[0]->getReturnType()); | ||
$this->assertCount(2, $params); | ||
$this->assertInstanceOf(UnionType::class, $params[0]->getType()); | ||
$this->assertInstanceOf(MixedType::class, $params[1]->getType()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function returnMagicMethodReflectionForUnsetMethod(): void | ||
{ | ||
$methodReflection = $this->extension->getMethod($this->classReflection, 'unsetTest'); | ||
|
||
$variants = $methodReflection->getVariants(); | ||
$params = $variants[0]->getParameters(); | ||
|
||
$this->assertCount(1, $variants); | ||
$this->assertInstanceOf(ObjectType::class, $variants[0]->getReturnType()); | ||
$this->assertCount(1, $params); | ||
$this->assertInstanceOf(UnionType::class, $params[0]->getType()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function returnMagicMethodReflectionForHasMethod(): void | ||
{ | ||
$methodReflection = $this->extension->getMethod($this->classReflection, 'hasTest'); | ||
|
||
$variants = $methodReflection->getVariants(); | ||
$params = $variants[0]->getParameters(); | ||
|
||
$this->assertCount(1, $variants); | ||
$this->assertInstanceOf(BooleanType::class, $variants[0]->getReturnType()); | ||
$this->assertCount(1, $params); | ||
$this->assertInstanceOf(StringType::class, $params[0]->getType()); | ||
} | ||
} |