FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Assertion class as parameter for Codeception config by Slamdunk · Pull Request #65 · phpstan/phpstan-phpunit · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .md  (1) .neon  (1) .php  (4) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
36 changes: 36 additions & 0 deletions README.md
This file contains hidden or 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
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
This file contains hidden or 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
Expand Up @@ -20,10 +20,14 @@ services:
- phpstan.typeSpecifier.functionTypeSpecifyingExtension
-
class: PHPStan\Type\PHPUnit\Assert\AssertMethodTypeSpecifyingExtension
arguments:
classWithAssertionMethods: PHPUnit\Framework\TestCase

Slamdunk Mar 20, 2020 •
edited
Loading

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
This file contains hidden or 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
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
This file contains hidden or 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
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
This file contains hidden or 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
Expand Up @@ -24,7 +24,7 @@ protected function getRule(): Rule
protected function getMethodTypeSpecifyingExtensions(): array
{
return [
new AssertMethodTypeSpecifyingExtension(),
new AssertMethodTypeSpecifyingExtension('PHPUnit\Framework\TestCase'),
];
}

Expand Down
This file contains hidden or 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
Expand Up @@ -24,7 +24,7 @@ protected function getRule(): Rule
protected function getStaticMethodTypeSpecifyingExtensions(): array
{
return [
new AssertStaticMethodTypeSpecifyingExtension(),
new AssertStaticMethodTypeSpecifyingExtension('PHPUnit\Framework\Assert'),
];
}

Expand Down

Back | FazBrowse Home | New Git URL