Skip to content
Merged
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
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: PHPStan
run: vendor/bin/phpstan analyze
- name: Install Psalm
run: composer require --dev vimeo/psalm:dev-master@dev --no-suggest

- name: Psalm
run: vendor/bin/psalm --output-format=github --shepherd
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ features and integration tests. Special thanks goes to
[@lunika](https://github.com/lunika), [@rgazelot](https://github.com/rgazelot)
and [@krichprollsch](https://github.com/krichprollsch), who helped conceived
this extension, and also pushed me to open-source it.

Badges
------
![Psalm Shepherd](https://shepherd.dev/github/Taluu/Behapi/coverage.svg)
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@
"symfony/http-client": "^4.3 || ^5.0",
"symfony/var-dumper": "^2.8 || ^3.3 || ^4.0",

"phpstan/phpstan": "^0.10",
"phpstan/phpstan-strict-rules": "^0.10",
"phpstan/phpstan-beberlei-assert": "^0.10"
"vimeo/psalm": "^3.8"
}
}
19 changes: 0 additions & 19 deletions phpstan.neon

This file was deleted.

19 changes: 19 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<LessSpecificReturnType errorLevel="info" />
</issueHandlers>
</psalm>
8 changes: 6 additions & 2 deletions src/Assert/Assertion.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
*/
abstract class Assertion extends Beberlei\Assertion
{
/** @return bool */
public static function empty($value, $message = null, ?string $propertyPath = null): bool
/**
* @param mixed $value
* @param string|null $message
* @return bool
*/
public static function empty($value, ?string $message = null, ?string $propertyPath = null): bool
{
return parent::noContent($value, $message, $propertyPath);
}
Expand Down
19 changes: 9 additions & 10 deletions src/Behapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ final class Behapi implements Extension
{
const DEBUG_INTROSPECTION_TAG = 'behapi.debug.introspection';

/** {@inheritDoc} */
public function getConfigKey()
public function getConfigKey(): string
{
return 'behapi';
}

/** {@inheritDoc} */
public function configure(ArrayNodeDefinition $builder)
/**
* @psalm-suppress PossiblyUndefinedMethod
* @psalm-suppress PossiblyNullReference
*/
public function configure(ArrayNodeDefinition $builder): void
{
$builder
->children()
Expand Down Expand Up @@ -89,13 +91,11 @@ public function configure(ArrayNodeDefinition $builder)

}

/** {@inheritDoc} */
public function initialize(ExtensionManager $extensionManager)
public function initialize(ExtensionManager $extensionManager): void
{
}

/** {@inheritDoc} */
public function load(ContainerBuilder $container, array $config)
public function load(ContainerBuilder $container, array $config): void
{
$container->register(HttpHistory\History::class, HttpHistory\History::class)
->setPublic(false)
Expand All @@ -112,8 +112,7 @@ public function load(ContainerBuilder $container, array $config)
$this->loadContainer($container, $config);
}

/** {@inheritDoc} */
public function process(ContainerBuilder $container)
public function process(ContainerBuilder $container): void
{
$dumpers = [];

Expand Down
5 changes: 3 additions & 2 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ private function getPluginClientBuilder(): PluginClientBuilder
$uriFactory = Psr17FactoryDiscovery::findUrlFactory();

$baseUri = $uriFactory->createUri($this->baseUrl);
$httpHistory = $this->services[HttpHistory::class];

assert($this->services[HttpHistory::class] instanceof HttpHistory);
assert($httpHistory instanceof HttpHistory);

$builder = $builder->addPlugin(new ContentLengthPlugin);
$builder = $builder->addPlugin(new BaseUriPlugin($baseUri));
$builder = $builder->addPlugin(new HistoryPlugin($this->services[HttpHistory::class]));
$builder = $builder->addPlugin(new HistoryPlugin($httpHistory));

return $builder;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Debug/CliController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ public function __construct(Status $status)
$this->status = $status;
}

/** {@inheritDoc} */
public function configure(Command $command)
public function configure(Command $command): void
{
$command
->addOption('behapi-debug', null, InputOption::VALUE_NONE, 'Activates the debug mode for behapi');
}

/** {@inheritDoc} */
public function execute(InputInterface $input, OutputInterface $output)
{
$debug = $input->getOption('behapi-debug');
assert(is_bool($debug));

$this->status->setEnabled($debug);

return null;
}
}
8 changes: 6 additions & 2 deletions src/Debug/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public function __construct(Status $status, HttpHistory $history, array $adapter
$this->status = $status;
}

/** {@inheritDoc} */
public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return [
ExampleTested::AFTER => 'debugAfter',
Expand Down Expand Up @@ -101,6 +100,11 @@ private function debug(MessageInterface $message): void
}
}

/**
* @psalm-suppress InvalidReturnType
* @psalm-suppress InvalidReturnStatement
* @psalm-suppress UndefinedDocblockClass
*/
private function hasTag(ScenarioLikeTested $event, string $tag): bool
{
$node = $event->getNode();
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class Status
/** @var bool */
private $enabled = false;

public function setEnabled(bool $enabled)
public function setEnabled(bool $enabled): void
{
$this->enabled = $enabled;
}
Expand Down
1 change: 1 addition & 0 deletions src/HttpHistory/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function getLastResponse(): ResponseInterface
return $response;
}

/** @return Generator<int, Tuple, mixed, int> */
public function getTuples(): Generator
{
yield from $this->tuples;
Expand Down
3 changes: 1 addition & 2 deletions src/HttpHistory/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public function __construct(History $history)
$this->history = $history;
}

/** {@inheritDoc} */
public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return [
ExampleTested::AFTER => ['clear', -99],
Expand Down
24 changes: 21 additions & 3 deletions src/Json/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\PropertyAccess\PropertyAccessor;

use Behapi\Assert\Assert;
use Behapi\Assert\AssertionChain;
use Behapi\HttpHistory\History as HttpHistory;

use function sprintf;
Expand All @@ -32,12 +33,13 @@ class Context implements BehatContext
/** @var HttpHistory */
private $history;

/** @var string[] */
/** @var list<string> */
private $contentTypes;

/** @var PropertyAccessor */
private $accessor;

/** @param list<string> $contentTypes */
public function __construct(HttpHistory $history, array $contentTypes = ['application/json'])
{
$this->accessor = PropertyAccess::createPropertyAccessor();
Expand All @@ -63,13 +65,16 @@ final public function path_should_be_readable(string $path, ?string $not = null)
$assert = Assert::that($this->accessor->isReadable($this->getValue(null), $path));

if ($not !== null) {
assert($assert instanceof AssertionChain);
$assert = $assert->not();
}

$assert->same(true);
}

/**
* @param mixed $expected
*
* @Then in the json, :path should be equal to :expected
* @Then in the json, :path should :not be equal to :expected
*/
Expand All @@ -78,6 +83,7 @@ final public function the_json_path_should_be_equal_to(string $path, ?string $no
$assert = Assert::that($this->getValue($path));

if ($not !== null) {
assert($assert instanceof AssertionChain);
$assert = $assert->not();
}

Expand All @@ -93,6 +99,7 @@ final public function the_json_path_should_be_py_string(string $path, ?string $n
$assert = Assert::that($this->getValue($path));

if ($not !== null) {
assert($assert instanceof AssertionChain);
$assert = $assert->not();
}

Expand All @@ -108,6 +115,7 @@ final public function the_json_path_should_be(string $path, ?string $not = null,
$assert = Assert::that($this->getValue($path));

if ($not !== null) {
assert($assert instanceof AssertionChain);
$assert = $assert->not();
}

Expand All @@ -123,6 +131,7 @@ final public function the_json_path_should_be_null(string $path, ?string $not =
$assert = Assert::that($this->getValue($path));

if ($not !== null) {
assert($assert instanceof AssertionChain);
$assert = $assert->not();
}

Expand All @@ -136,6 +145,7 @@ final public function the_json_path_should_be_null(string $path, ?string $not =
final public function the_json_path_should_be_empty(string $path, ?string $not = null): void
{
$assert = Assert::that($this->getValue($path));
assert($assert instanceof AssertionChain);

if ($not !== null) {
$assert = $assert->not();
Expand All @@ -145,6 +155,8 @@ final public function the_json_path_should_be_empty(string $path, ?string $not =
}

/**
* @param mixed $expected
*
* @Then in the json, :path should contain :expected
* @Then in the json, :path should :not contain :expected
*/
Expand All @@ -153,13 +165,18 @@ final public function the_json_path_contains(string $path, ?string $not = null,
$assert = Assert::that($this->getValue($path));

if ($not !== null) {
assert($assert instanceof AssertionChain);
$assert = $assert->not();
}

$assert->contains($expected);
}

/** @Then in the json, :path collection should contain an element with :value equal to :expected */
/**
* @param mixed $expected
*
* @Then in the json, :path collection should contain an element with :value equal to :expected
*/
final public function the_json_path_collection_contains(string $path, string $value, $expected): void
{
$collection = $this->getValue($path);
Expand Down Expand Up @@ -215,7 +232,7 @@ final public function the_json_path_should_be_a_valid_json_encoded_string(string
* overwrite it if you want to add supplementary checks or use something
* else instead (such as Seldaek's JsonLint package).
*/
public function response_should_be_a_valid_json_response()
public function response_should_be_a_valid_json_response(): void
{
$this->getValue(null);

Expand All @@ -239,6 +256,7 @@ final public function the_json_path_should_match(string $path, ?string $not = nu
$assert = Assert::that($this->getValue($path));

if ($not !== null) {
assert($assert instanceof AssertionChain);
$assert = $assert->not();
}

Expand Down
Loading