Skip to content

Commit

Permalink
Add tests for GetCollectionMockMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
shochdoerfer committed Jun 19, 2021
1 parent 281d55f commit 383dfc7
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

use bitExpert\PHPStan\Magento\Rules\Helper\SampleModel;
use bitExpert\PHPStan\Magento\Type\TestFrameworkObjectManagerDynamicReturnTypeExtension;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\ShouldNotHappenException;
use PHPStan\Testing\RuleTestCase;

/**
Expand Down Expand Up @@ -49,4 +53,57 @@ public function checkCaughtExceptions(): void
],
]);
}

/**
* @test
*/
public function getNodeTypeMethodReturnsMethodCall(): void
{
$rule = new GetCollectionMockMethodNeedsCollectionSubclassRule();

self::assertSame(MethodCall::class, $rule->getNodeType());
}
/**
* @test
*/
public function processNodeThrowsExceptionForNonMethodCallNodes(): void
{
$this->expectException(ShouldNotHappenException::class);

$node = new Variable('var');
$scope = $this->createMock(Scope::class);

$rule = new GetCollectionMockMethodNeedsCollectionSubclassRule();
$rule->processNode($node, $scope);
}

/**
* @test
*/
public function processNodeReturnsEarlyWhenNodeNameIsWrongType(): void
{
$node = new MethodCall(new Variable('var'), new Variable('wrong_node'));
$scope = $this->createMock(Scope::class);

$rule = new GetCollectionMockMethodNeedsCollectionSubclassRule();
$return = $rule->processNode($node, $scope);

self::assertIsArray($return);
self::assertCount(0, $return);
}

/**
* @test
*/
public function processNodeReturnsEarlyWhenNodeNameIsNotGetCollectionMock(): void
{
$node = new MethodCall(new Variable('var'), 'wrong_node_name');
$scope = $this->createMock(Scope::class);

$rule = new GetCollectionMockMethodNeedsCollectionSubclassRule();
$return = $rule->processNode($node, $scope);

self::assertIsArray($return);
self::assertCount(0, $return);
}
}

0 comments on commit 383dfc7

Please sign in to comment.