acceptance tests (#3)

This commit is contained in:
Farhad Safarov 2019-11-14 10:27:50 +03:00 committed by GitHub
parent 7002339f2a
commit d1f94392cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 172 additions and 7 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
vendor
composer.lock
.php_cs.cache

View File

@ -1,8 +1,14 @@
# Symfony Psalm Plugin
[![Build Status](https://travis-ci.com/seferov/symfony-psalm-plugin.svg?branch=master)](https://travis-ci.com/seferov/symfony-psalm-plugin)
### Installation
```
composer require --dev seferov/symfony-psalm-plugin
vendor/bin/psalm-plugin enable seferov/symfony-psalm-plugin
```
### Credits
- [@weirdan](https://github.com/weirdan) for [codeception psalm module](https://github.com/weirdan/codeception-psalm-module)

14
codeception.yml Normal file
View File

@ -0,0 +1,14 @@
namespace: Psalm\PhpUnitPlugin\Tests
paths:
tests: tests
output: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
extensions:
enabled:
- Codeception\Extension\RunFailed

View File

@ -2,11 +2,6 @@
"name": "seferov/symfony-psalm-plugin",
"description": "Psalm Plugin for Symfony",
"type": "psalm-plugin",
"require": {
"php": "^7.1",
"vimeo/psalm": "^3.2",
"symfony/framework-bundle": "^3.0 || ^4.0"
},
"license": "MIT",
"authors": [
{
@ -14,11 +9,25 @@
"email": "farhad.safarov@gmail.com"
}
],
"require": {
"php": "^7.1",
"vimeo/psalm": "^3.2",
"symfony/framework-bundle": "^3.0 || ^4.0"
},
"require-dev": {
"codeception/base": "^2.5",
"weirdan/codeception-psalm-module": "^0.2.2"
},
"autoload": {
"psr-4": {
"Seferov\\SymfonyPsalmPlugin\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Seferov\\SymfonyPsalmPlugin\\Tests\\": ["tests/_support"]
}
},
"extra": {
"psalm" : {
"pluginClass": "Seferov\\SymfonyPsalmPlugin\\Plugin"
@ -26,8 +35,13 @@
},
"scripts": {
"check": [
"@analyze"
"@analyze",
"@test"
],
"analyze": "psalm"
"analyze": "psalm",
"test": [
"codecept build",
"codecept run -v"
]
}
}

2
tests/_output/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

2
tests/_run/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -0,0 +1,26 @@
<?php
namespace Psalm\PhpUnitPlugin\Tests;
use Codeception\Actor;
use Codeception\Lib\Friend;
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends Actor
{
use _generated\AcceptanceTesterActions;
}

2
tests/_support/_generated/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -0,0 +1,7 @@
actor: AcceptanceTester
modules:
enabled:
- Cli
- Filesystem
- \Weirdan\Codeception\Psalm\Module

View File

@ -0,0 +1,37 @@
Feature: ContainerDependency
In order to follow best practices for Symfony
As a Psalm user
I need Psalm to check container is not injected as a dependency
Background:
Given I have the following config
"""
<?xml version="1.0"?>
<psalm totallyTyped="true">
<projectFiles>
<directory name="."/>
<ignoreFiles> <directory name="../../vendor"/> </ignoreFiles>
</projectFiles>
<plugins>
<pluginClass class="Seferov\SymfonyPsalmPlugin\Plugin"/>
</plugins>
</psalm>
"""
Scenario: Asserting container dependency raises issue
Given I have the following code
"""
<?php
use Symfony\Component\DependencyInjection\ContainerInterface;
class SomeService
{
public function __construct(ContainerInterface $container)
{
}
}
"""
When I run Psalm
Then I see these errors
| Type | Message |
| ContainerDependency | Container must not inject into services as dependency! |
And I see no other errors

View File

@ -0,0 +1,54 @@
Feature: RepositoryStringShortcut
In order to follow best practices for Symfony
As a Psalm user
I need Psalm to check preferred repository syntax
Background:
Given I have the following config
"""
<?xml version="1.0"?>
<psalm totallyTyped="true">
<projectFiles>
<directory name="."/>
<ignoreFiles> <directory name="../../vendor"/> </ignoreFiles>
</projectFiles>
<issueHandlers>
<UndefinedClass errorLevel="info" />
</issueHandlers>
<plugins>
<pluginClass class="Seferov\SymfonyPsalmPlugin\Plugin"/>
</plugins>
</psalm>
"""
Scenario: Asserting using 'AppBundle:Entity' syntax raises issue
Given I have the following code
"""
<?php
use Doctrine\ORM\EntityManagerInterface;
class SomeService
{
public function __construct(EntityManagerInterface $entityManager)
{
$entityManager->getRepository('AppBundle:Entity');
}
}
namespace Doctrine\ORM;
interface EntityManagerInterface
{
/**
* @param string $className
*
* @return void
*/
public function getRepository($className);
}
"""
When I run Psalm
Then I see these errors
| Type | Message |
| RepositoryStringShortcut | Use Entity::class syntax instead |
And I see no other errors