Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion class as parameter for Codeception config #65

Open
wants to merge 2 commits into
base: 1.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,39 @@ To perform framework-specific checks, include also this file:
```

</details>


## Codeception parameters

This extension works well with [Codeception](https://github.com/Codeception/Codeception) too.

[Unit tests](https://codeception.com/docs/05-UnitTests) are already recognised by default;
[Functional tests](https://codeception.com/docs/04-FunctionalTests) and
[Acceptance tests](https://codeception.com/docs/03-AcceptanceTests) instead have to be configured
manually since assertion classes are generated at runtime with different namespaces and class names.

Here's an example configuration:

```
services:
-
class: PHPStan\Type\PHPUnit\Assert\AssertMethodTypeSpecifyingExtension
arguments:
classWithAssertionMethods: My\CustomNamespace\_support\FunctionalTester
tags:
- phpstan.typeSpecifier.methodTypeSpecifyingExtension
-
class: PHPStan\Type\PHPUnit\Assert\AssertStaticMethodTypeSpecifyingExtension
arguments:
classWithAssertionMethods: My\CustomNamespace\_support\FunctionalTester
tags:
- phpstan.typeSpecifier.staticMethodTypeSpecifyingExtension

parameters:
earlyTerminatingMethodCalls:
My\CustomNamespace\_support\FunctionalTester:
- fail
Codeception\Scenario:
- incomplete
- skip
```
4 changes: 4 additions & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ services:
- phpstan.typeSpecifier.functionTypeSpecifyingExtension
-
class: PHPStan\Type\PHPUnit\Assert\AssertMethodTypeSpecifyingExtension
arguments:
classWithAssertionMethods: PHPUnit\Framework\TestCase
Copy link
Author

@Slamdunk Slamdunk Mar 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've retained the class used in https://github.com/phpstan/phpstan-phpunit/pull/65/files#diff-afc1ebcbfd95543266d01a244f0e43deL27, but shouldn't this be PHPUnit\Framework\Assert too?

tags:
- phpstan.typeSpecifier.methodTypeSpecifyingExtension
-
class: PHPStan\Type\PHPUnit\Assert\AssertStaticMethodTypeSpecifyingExtension
arguments:
classWithAssertionMethods: PHPUnit\Framework\Assert
tags:
- phpstan.typeSpecifier.staticMethodTypeSpecifyingExtension
-
Expand Down
13 changes: 12 additions & 1 deletion src/Type/PHPUnit/Assert/AssertMethodTypeSpecifyingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,28 @@
class AssertMethodTypeSpecifyingExtension implements MethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
{

/** @var class-string */
private $classWithAssertionMethods;

/** @var TypeSpecifier */
private $typeSpecifier;

/**
* @param class-string $classWithAssertionMethods
*/
public function __construct(string $classWithAssertionMethods)
{
$this->classWithAssertionMethods = $classWithAssertionMethods;
}

public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void
{
$this->typeSpecifier = $typeSpecifier;
}

public function getClass(): string
{
return 'PHPUnit\Framework\TestCase';
return $this->classWithAssertionMethods;
}

public function isMethodSupported(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,28 @@
class AssertStaticMethodTypeSpecifyingExtension implements StaticMethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
{

/** @var class-string */
private $classWithAssertionMethods;

/** @var TypeSpecifier */
private $typeSpecifier;

/**
* @param class-string $classWithAssertionMethods
*/
public function __construct(string $classWithAssertionMethods)
{
$this->classWithAssertionMethods = $classWithAssertionMethods;
}

public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void
{
$this->typeSpecifier = $typeSpecifier;
}

public function getClass(): string
{
return 'PHPUnit\Framework\Assert';
return $this->classWithAssertionMethods;
}

public function isStaticMethodSupported(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function getRule(): Rule
protected function getMethodTypeSpecifyingExtensions(): array
{
return [
new AssertMethodTypeSpecifyingExtension(),
new AssertMethodTypeSpecifyingExtension('PHPUnit\Framework\TestCase'),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function getRule(): Rule
protected function getStaticMethodTypeSpecifyingExtensions(): array
{
return [
new AssertStaticMethodTypeSpecifyingExtension(),
new AssertStaticMethodTypeSpecifyingExtension('PHPUnit\Framework\Assert'),
];
}

Expand Down