updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -89,7 +89,7 @@ class Diff_SequenceMatcher
* @param string|array $junkCallback Either an array or string that references a callback function (if there is one) to determine 'junk' characters.
* @param array $options
*/
public function __construct($a, $b, $junkCallback=null, $options)
public function __construct($a, $b, $junkCallback=null, $options=[])
{
$this->a = null;
$this->b = null;

View File

@@ -10,14 +10,13 @@ cache:
matrix:
include:
- php: 7.0
- php: 7.1
env: COMPOSER_FLAGS='--prefer-lowest'
- php: 7.0
- php: 7.1
- php: 7.2
- php: 7.2
env: DEPENDENCIES='dev'
- php: 7.3
- php: nightly
env: DEPENDENCIES='dev'
env: COMPOSER_FLAGS='--ignore-platform-reqs'
allow_failures:
- php: nightly
@@ -51,5 +50,5 @@ deploy:
skip_cleanup: true
on:
tags: true
php: 7.0
php: 7.1
condition: COMPOSER_FLAGS != "--prefer-lowest"

33
vendor/phpspec/phpspec/CHANGES-v5.md vendored Normal file
View File

@@ -0,0 +1,33 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [5.1.0]
### Added
- PHP 7.3 compatibility (@ciaranmcnulty)
- Configure verbosity option in configuration file (@DonCallisto)
## [5.0.3]
### Fixed
- Error with scalarmatcher when type does not match (@DonCallisto)
## [5.0.2]
### Fixed
- Better error message when trying to call method on scalar return type (@ciaranmcnulty)
## [5.0.1]
### Fixed
- Type error when using Object State Matcher (@nightlinus)
## [5.0.0]
### Changed
- Bumped minimum PHP and Symfony dependences (@ciaranmcnulty)
- Added void type hints to codebase (@kix)
[5.1.0]: https://github.com/phpspec/phpspec/compare/5.0.3...5.1.0
[5.0.2]: https://github.com/phpspec/phpspec/compare/5.0.2...5.0.3
[5.0.2]: https://github.com/phpspec/phpspec/compare/5.0.1...5.0.2
[5.0.1]: https://github.com/phpspec/phpspec/compare/5.0.0...5.0.1
[5.0.0]: https://github.com/phpspec/phpspec/compare/4.3.1...5.0.0

View File

@@ -1 +1 @@
CHANGES-v4.md
CHANGES-v5.md

View File

@@ -24,4 +24,4 @@
(new PhpSpec\Console\Application($version))->run();
})('4.3.2');
})('5.1.0');

49
vendor/phpspec/phpspec/check-release.php vendored Executable file
View File

@@ -0,0 +1,49 @@
<?php
/**
* Sanity-checks a release for consistency
*/
// get the version reported by phpspec --version
if (!preg_match_all('/(?<major>[5-9])\.(?<minor>[0-9]+)\.(?<patch>[0-9]+)/', file_get_contents('bin/phpspec'), $matches) || count($matches[0])!=1) {
echo "👎 could not read version from binary file\n";
exit(1);
}
[
0 => [ 0 => $version],
'major' => [ 0 => $major],
'minor' => [ 0 => $minor],
'patch' => [ 0 => $patch]
] = $matches;
echo "Verifying version $version \n" ;
$composer = file_get_contents('composer.json');
if (!preg_match("/$major\.$minor\.x-dev/", $composer, $matches)) {
echo "👎 composer.json does not contain matching branch alias\n";
exit(1);
}
echo "👍 composer.json contains branch alias {$matches[0]}\n";
$changelog = file_get_contents('CHANGES.md');
if (!preg_match("/## \[$major.$minor.$patch\]/", $changelog, $matches)) {
echo "👎 CHANGES.md does not contain matching heading\n";
exit(1);
}
echo "👍 CHANGES.md contains heading '{$matches[0]}'\n";
if (!preg_match("/\[$major.$minor.$patch\]: https:\/\/github\.com.*$major.$minor.$patch/", $changelog, $matches)) {
echo "👎 CHANGES.md does not contain matching github diff\n";
exit(1);
}
echo "👍 CHANGES.md contains link '{$matches[0]}'\n";
exit(0);

View File

@@ -1,6 +1,6 @@
{
"name": "phpspec/phpspec",
"description": "Specification-oriented BDD framework for PHP 5.6+",
"description": "Specification-oriented BDD framework for PHP 7.1+",
"keywords": ["BDD", "SpecBDD", "TDD", "spec", "specification", "tests", "testing"],
"homepage": "http://phpspec.net/",
"type": "library",
@@ -22,23 +22,23 @@
],
"require": {
"php": "^7.0,<7.3",
"phpspec/prophecy": "^1.5",
"php": "^7.1, <7.4",
"phpspec/prophecy": "^1.7",
"phpspec/php-diff": "^1.0.0",
"sebastian/exporter": "^1.0 || ^2.0 || ^3.0",
"symfony/console": "^3.2 || ^4.0",
"symfony/event-dispatcher": "^3.2 || ^4.0",
"symfony/process": "^3.2 || ^4.0",
"symfony/finder": "^3.2 || ^4.0",
"symfony/yaml": "^3.2 || ^4.0",
"symfony/console": "^3.4 || ^4.0",
"symfony/event-dispatcher": "^3.4 || ^4.0",
"symfony/process": "^3.4 || ^4.0",
"symfony/finder": "^3.4 || ^4.0",
"symfony/yaml": "^3.4 || ^4.0",
"doctrine/instantiator": "^1.0.5",
"ext-tokenizer": "*"
},
"require-dev": {
"behat/behat": "^3.3",
"symfony/filesystem": "^3.2 || ^4.0",
"phpunit/phpunit": "^5.7|^6.0"
"symfony/filesystem": "^3.4 || ^4.0",
"phpunit/phpunit": "^5.7 || ^6.0"
},
"suggest": {
@@ -61,7 +61,7 @@
"extra": {
"branch-alias": {
"dev-master": "4.3.x-dev"
"dev-master": "5.1.x-dev"
}
}
}

View File

@@ -6,6 +6,7 @@ use Fake\Prompter;
use Fake\ReRunner;
use PhpSpec\Console\Application;
use PhpSpec\Loader\StreamWrapper;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\ApplicationTester;
/**
@@ -55,6 +56,7 @@ class ApplicationContext implements Context
$this->setupReRunner();
$this->setupPrompter();
$this->resetShellVerbosity();
}
private function setFixedTerminalDimensions()
@@ -76,6 +78,11 @@ class ApplicationContext implements Context
$this->application->getContainer()->set('process.rerunner.platformspecific', $this->reRunner);
}
private function resetShellVerbosity()
{
putenv(sprintf('SHELL_VERBOSITY=%d', OutputInterface::VERBOSITY_NORMAL));
}
/**
* @Given I have started describing the :class class
* @Given I start describing the :class class
@@ -427,4 +434,40 @@ class ApplicationContext implements Context
$this->checkApplicationOutput('name contains reserved keyword');
}
/**
* @Then The output should contain:
*/
public function outputShouldContain(PyStringNode $expectedOutputPart)
{
$this->checkApplicationOutput("$expectedOutputPart");
}
/**
* @Then Output should not be shown
*/
public function outputShouldNotBeShown()
{
$outputLen = strlen($this->normalize($this->tester->getDisplay(true)));
if ($outputLen) {
throw new \Exception(
'Output was shown when not expected.'
);
}
}
/**
* @Then The output should not contain:
*/
public function outputShouldNotContain(PyStringNode $expectedOutputPart)
{
$expected = $this->normalize($expectedOutputPart);
$actual = $this->normalize($this->tester->getDisplay(true));
if (strpos($actual, $expected) !== false) {
throw new \Exception(sprintf(
"Application output did contain not expected '%s'. Actual output:\n'%s'" ,
$expected,
$this->tester->getDisplay()
));
}
}
}

View File

@@ -16,7 +16,7 @@ class ReRunner implements BaseReRunner
return true;
}
public function reRunSuite()
public function reRunSuite() : void
{
$this->hasBeenReRun = true;
}

View File

@@ -25,6 +25,28 @@ Feature: Developer generates a spec
"""
@issue1210
Scenario: Generating a spec with alphabetised imports
When I start describing the "Zyzzyva/SpecExample/Example" class
Then a new spec should be generated in the "spec/Zyzzyva/SpecExample/ExampleSpec.php":
"""
<?php
namespace spec\Zyzzyva\SpecExample;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Zyzzyva\SpecExample\Example;
class ExampleSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(Example::class);
}
}
"""
@issue687
Scenario: Generating a spec with the same namespace as the source

View File

@@ -97,6 +97,60 @@ Feature: Developer is shown diffs
]
"""
Scenario: Array of object diffing
Given the spec file "spec/Diffs/DiffExample2/ClassWithArraysOfObjectsSpec.php" contains:
"""
<?php
namespace spec\Diffs\DiffExample2;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ClassWithArraysOfObjectsSpec extends ObjectBehavior
{
function it_is_equal()
{
$std = new \stdClass;
$std->test = 'anotherProperty';
$this->getArray()->shouldBeLike([$std]);
}
}
"""
And the class file "src/Diffs/DiffExample2/ClassWithArraysOfObjects.php" contains:
"""
<?php
namespace Diffs\DiffExample2;
class ClassWithArraysOfObjects
{
public function getArray()
{
$std = new \stdClass;
$std->property = 'testValue';
$std->hash = 'fooHash';
return [$std];
}
}
"""
When I run phpspec with the "verbose" option
Then I should see:
"""
- 'test' => 'anotherProperty'
"""
And I should see:
"""
+ 'property' => 'testValue'
"""
And I should see:
"""
+ 'hash' => 'fooHash'
"""
Scenario: Object diffing
Given the spec file "spec/Diffs/DiffExample3/ClassWithObjectsSpec.php" contains:
"""

View File

@@ -0,0 +1,183 @@
Feature: Developer chooses verbosity output
As a Developer
I want to set the verbose setting option
In order to specify how console output bheaves on failure
Scenario: config verbosity used if console verbosity not quiet
Given the config file contains:
"""
verbose: true
"""
Given the spec file "spec/Verbose/SpecExample1/ConfigVerbosityConsoleNotSetSpec.php" contains:
"""
<?php
namespace spec\Verbose\SpecExample1;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ConfigVerbosityConsoleNotSetSpec extends ObjectBehavior
{
function it_fails()
{
$this->getValue()->shouldReturn([0, 1]);
}
}
"""
And the class file "src/Verbose/SpecExample1/ConfigVerbosityConsoleNotSet.php" contains:
"""
<?php
namespace Verbose\SpecExample1;
class ConfigVerbosityConsoleNotSet
{
public function getValue()
{
return [0];
}
}
"""
When I run phpspec
Then The output should contain:
"""
expected [array:2], but got [array:1].
"""
And The output should contain:
"""
- 1 => 1,
"""
Scenario: config verbosity not set
Given the spec file "spec/Verbose/SpecExample2/ConfigVerbosityNotSetConsoleNotSetSpec.php" contains:
"""
<?php
namespace spec\Verbose\SpecExample2;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ConfigVerbosityNotSetConsoleNotSetSpec extends ObjectBehavior
{
function it_fails()
{
$this->getValue()->shouldReturn([0, 1]);
}
}
"""
And the class file "src/Verbose/SpecExample2/ConfigVerbosityNotSetConsoleNotSet.php" contains:
"""
<?php
namespace Verbose\SpecExample2;
class ConfigVerbosityNotSetConsoleNotSet
{
public function getValue()
{
return [0];
}
}
"""
When I run phpspec
Then The output should contain:
"""
expected [array:2], but got [array:1].
"""
And The output should not contain:
"""
- 1 => 1,
"""
Scenario: config verbosity set to true overriden if console verbosity is quiet
Given the config file contains:
"""
verbose: true
"""
Given the spec file "spec/Verbose/SpecExample3/ConsoleQuietVerbosityOverrideConfigVerbositySpec.php" contains:
"""
<?php
namespace spec\Verbose\SpecExample3;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ConsoleQuietVerbosityOverrideConfigVerbositySpec extends ObjectBehavior
{
function it_fails()
{
$this->getValue()->shouldReturn([0, 1]);
}
}
"""
And the class file "src/Verbose/SpecExample3/ConsoleQuietVerbosityOverrideConfigVerbosity.php" contains:
"""
<?php
namespace Verbose\SpecExample3;
class ConsoleQuitenessOverrideConfigVerbosity
{
public function getValue()
{
return [0];
}
}
"""
When I run phpspec with the "quiet" option
Then Output should not be shown
Scenario: config verbosity set to false overriden if console verbosity set
Given the config file contains:
"""
verbose: false
"""
Given the spec file "spec/Verbose/SpecExample4/ConsoleVerbosityOverrideConfigVerbosityFalseSpec.php" contains:
"""
<?php
namespace spec\Verbose\SpecExample4;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ConsoleVerbosityOverrideConfigVerbosityFalseSpec extends ObjectBehavior
{
function it_fails()
{
$this->getValue()->shouldReturn([0, 1]);
}
}
"""
And the class file "src/Verbose/SpecExample4/ConsoleVerbosityOverrideConfigVerbosityFalse.php" contains:
"""
<?php
namespace Verbose\SpecExample4;
class ConsoleVerbosityOverrideConfigVerbosityFalse
{
public function getValue()
{
return [0];
}
}
"""
When I run phpspec with the "verbose" option
Then The output should contain:
"""
- 1 => 1,
"""

View File

@@ -14,11 +14,15 @@ class TokenizedTypeHintRewriterSpec extends ObjectBehavior
{
$this->beConstructedWith($typeHintIndex, $namespaceResolver);
$namespaceResolver->resolve(Argument::cetera())->willReturn('someClass');
$namespaceResolver->analyse(Argument::any())->willReturn();
$namespaceResolver->analyse(Argument::any())->shouldBeCalled();
}
function it_is_a_typehint_rewriter()
function it_is_a_typehint_rewriter(TypeHintIndex $typeHintIndex, NamespaceResolver $namespaceResolver)
{
$this->beConstructedWith($typeHintIndex, $namespaceResolver);
$namespaceResolver->resolve(Argument::cetera())->willReturn('someClass');
$namespaceResolver->analyse(Argument::any())->shouldNotBeCalled();
$this->shouldHaveType('PhpSpec\CodeAnalysis\TypeHintRewriter');
}

View File

@@ -51,8 +51,9 @@ class SpecificationGeneratorSpec extends ObjectBehavior
'%filepath%' => '/project/spec/Acme/AppSpec.php',
'%name%' => 'AppSpec',
'%namespace%' => 'spec\Acme',
'%imports%' => "use Acme\App;\nuse PhpSpec\ObjectBehavior;\nuse Prophecy\Argument;",
'%subject%' => 'Acme\App',
'%subject_class%' => 'App'
'%subject_class%' => 'App',
);
$tpl->render('specification', $values)->willReturn('');
@@ -78,8 +79,9 @@ class SpecificationGeneratorSpec extends ObjectBehavior
'%filepath%' => '/project/spec/Acme/AppSpec.php',
'%name%' => 'AppSpec',
'%namespace%' => 'spec\Acme',
'%imports%' => "use Acme\App;\nuse PhpSpec\ObjectBehavior;\nuse Prophecy\Argument;",
'%subject%' => 'Acme\App',
'%subject_class%' => 'App'
'%subject_class%' => 'App',
);
$tpl->render('specification', $values)->willReturn('template code');

View File

@@ -3,49 +3,63 @@
namespace spec\PhpSpec\Config;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\Console\Output\OutputInterface;
class OptionsConfigSpec extends ObjectBehavior
{
function it_says_rerun_is_enabled_when_setting_is_true()
{
$this->beConstructedWith(false, false, true, false, false);
$this->beConstructedWith(false, false, true, false, false, false);
$this->isReRunEnabled()->shouldReturn(true);
}
function it_says_rerun_is_not_enabled_when_setting_is_false()
{
$this->beConstructedWith(false, false, false, false, false);
$this->beConstructedWith(false, false, false, false, false, false);
$this->isReRunEnabled()->shouldReturn(false);
}
function it_says_faking_is_enabled_when_setting_is_true()
{
$this->beConstructedWith(false, false, false, true, false);
$this->beConstructedWith(false, false, false, true, false, false);
$this->isFakingEnabled()->shouldReturn(true);
}
function it_says_faking_is_not_enabled_when_setting_is_false()
{
$this->beConstructedWith(false, false, false, false, false);
$this->beConstructedWith(false, false, false, false, false, false);
$this->isFakingEnabled()->shouldReturn(false);
}
function it_says_bootstrap_path_is_false_when_setting_is_false()
{
$this->beConstructedWith(false, false, false, false, false);
$this->beConstructedWith(false, false, false, false, false, false);
$this->getBootstrapPath()->shouldReturn(false);
}
function it_returns_bootstrap_path_when_one_is_specified()
{
$this->beConstructedWith(false, false, false, false, '/path/to/file');
$this->beConstructedWith(false, false, false, false, '/path/to/file', false);
$this->getBootstrapPath()->shouldReturn('/path/to/file');
}
function it_returns_verbose_when_setting_is_true()
{
$this->beConstructedWith(false, false, false, false, false, true);
$this->isVerbose()->shouldReturn(true);
}
function it_returns_verbose_when_setting_is_false()
{
$this->beConstructedWith(false, false, false, false, false, false);
$this->isVerbose()->shouldReturn(false);
}
}

View File

@@ -212,4 +212,72 @@ class ConsoleIOSpec extends ObjectBehavior
$this->writeBrokenCodeBlock($message, 2);
}
function it_will_report_verbose_if_config_flag_is_set_and_console_setted_to_quiet(OutputInterface $output, OptionsConfig $config)
{
$output->getVerbosity()->willReturn(OutputInterface::VERBOSITY_QUIET);
$config->isVerbose()->willReturn(true);
$this->isVerbose()->shouldReturn(true);
}
function it_will_report_verbose_if_config_flag_is_set_and_console_setted_to_normal(
OutputInterface $output,
OptionsConfig $config
) {
$output->getVerbosity()->willReturn(OutputInterface::VERBOSITY_NORMAL);
$config->isVerbose()->willReturn(true);
$this->isVerbose()->shouldReturn(true);
}
function it_will_not_report_verbose_if_config_flag_is_not_set_and_console_setted_to_quiet(
OutputInterface $output,
OptionsConfig $config
) {
$output->getVerbosity()->willReturn(OutputInterface::VERBOSITY_QUIET);
$config->isVerbose()->willReturn(false);
$this->isVerbose()->shouldReturn(false);
}
function it_will_not_report_verbose_if_config_flag_is_not_set_and_console_setted_to_normal(
OutputInterface $output,
OptionsConfig $config
) {
$output->getVerbosity()->willReturn(OutputInterface::VERBOSITY_NORMAL);
$config->isVerbose()->willReturn(false);
$this->isVerbose()->shouldReturn(false);
}
function it_will_report_verbose_if_config_flag_is_not_set_but_console_setted_to_verbose(
OutputInterface $output,
OptionsConfig $config
) {
$output->getVerbosity()->willReturn(OutputInterface::VERBOSITY_VERBOSE);
$config->isVerbose()->willReturn(false);
$this->isVerbose()->shouldReturn(true);
}
function it_will_report_verbose_if_config_flag_is_not_set_but_console_setted_to_very_verbose(
OutputInterface $output,
OptionsConfig $config
) {
$output->getVerbosity()->willReturn(OutputInterface::VERBOSITY_VERY_VERBOSE);
$config->isVerbose()->willReturn(false);
$this->isVerbose()->shouldReturn(true);
}
function it_will_report_verbose_if_config_flag_is_not_set_but_console_setted_to_debug(
OutputInterface $output,
OptionsConfig $config
) {
$output->getVerbosity()->willReturn(OutputInterface::VERBOSITY_DEBUG);
$config->isVerbose()->willReturn(false);
$this->isVerbose()->shouldReturn(true);
}
}

View File

@@ -9,6 +9,7 @@ class InvalidCollaboratorTypeExceptionSpec extends ObjectBehavior
{
function let(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function)
{
$function->getName()->willReturn('bar');
$this->beConstructedWith($parameter, $function);
}

View File

@@ -13,6 +13,8 @@ use PhpSpec\Exception\Example\PendingException;
use PhpSpec\Loader\Node\SpecificationNode;
use PhpSpec\Loader\Node\ExampleNode;
use Prophecy\Argument;
use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy;
use ReflectionFunctionAbstract;
class DotFormatterSpec extends ObjectBehavior
@@ -27,10 +29,13 @@ class DotFormatterSpec extends ObjectBehavior
$this->beConstructedWith($presenter, $io, $stats);
$presenter->presentString(Argument::cetera())->willReturn('presented string');
$presenter->presentException(Argument::cetera())->willReturn('presented exception');
$io->isVerbose()->willReturn(false);
$io->askConfirmation(Argument::any())->willReturn(false);
$io->write(Argument::any())->willReturn(null);
$io->writeln(Argument::cetera())->willReturn(null);
$io->write(Argument::any())->should(function() {
return;
});
$io->writeln(Argument::cetera())->should(function() {
return;
});
$io->getBlockWidth()->willReturn(80);
$event->getTime()->willReturn(10.0);
}
@@ -46,6 +51,7 @@ class DotFormatterSpec extends ObjectBehavior
StatisticsCollector $stats
) {
$event->getResult()->willReturn(ExampleEvent::PASSED);
$stats->getEventsCount()->willReturn(1);
$this->afterExample($event);
@@ -58,6 +64,7 @@ class DotFormatterSpec extends ObjectBehavior
StatisticsCollector $stats
) {
$event->getResult()->willReturn(ExampleEvent::PENDING);
$stats->getEventsCount()->willReturn(1);
$this->afterExample($event);
@@ -70,6 +77,7 @@ class DotFormatterSpec extends ObjectBehavior
StatisticsCollector $stats
) {
$event->getResult()->willReturn(ExampleEvent::SKIPPED);
$stats->getEventsCount()->willReturn(1);
$this->afterExample($event);
@@ -82,6 +90,7 @@ class DotFormatterSpec extends ObjectBehavior
StatisticsCollector $stats
) {
$event->getResult()->willReturn(ExampleEvent::FAILED);
$stats->getEventsCount()->willReturn(1);
$this->afterExample($event);
@@ -94,6 +103,7 @@ class DotFormatterSpec extends ObjectBehavior
StatisticsCollector $stats
) {
$event->getResult()->willReturn(ExampleEvent::BROKEN);
$stats->getEventsCount()->willReturn(1);
$this->afterExample($event);
@@ -139,8 +149,8 @@ class DotFormatterSpec extends ObjectBehavior
$io->isVerbose()->willReturn(false);
$io->getBlockWidth()->willReturn(10);
$io->write(Argument::type('string'))->willReturn();
$io->writeln(Argument::cetera())->willReturn();
$io->write(Argument::type('string'))->should(function () {});
$io->writeln(Argument::cetera())->should(function () {});
$stats->getEventsCount()->willReturn(1);
$stats->getFailedEvents()->willReturn(array());

View File

@@ -2,23 +2,52 @@
namespace spec\PhpSpec\Formatter\Presenter\Differ;
use PhpSpec\Formatter\Presenter\Differ\DifferEngine;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use SebastianBergmann\Exporter\Exporter;
use stdClass;
use function var_dump;
class ArrayEngineSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedWith(new Exporter());
}
function it_is_a_diff_engine()
{
$this->shouldBeAnInstanceOf('PhpSpec\Formatter\Presenter\Differ\DifferEngine');
$this->shouldBeAnInstanceOf(DifferEngine::class);
}
function it_supports_arrays()
{
$this->supports(array(), array(1, 2, 3))->shouldReturn(true);
$this->supports([], [ 1, 2, 3 ])->shouldReturn(true);
}
function it_does_not_support_anything_else()
{
$this->supports('str', 2)->shouldReturn(false);
}
function it_compare_equal_arrays()
{
$result = $this->compare([ 1 ], [ 1 ]);
$result->shouldBeString();
$result->shouldNotContain('1');
}
function it_compare_array_of_objects_to_and_displays_its_properties()
{
$obj1 = new stdClass();
$obj1->hash = '123#';
$obj2 = new stdClass();
$obj2->trash = '12345f';
$diff = $this->compare([ $obj1 ], [ $obj2 ]);
$diff->shouldContain('hash');
$diff->shouldContain('123#');
$diff->shouldContain('trash');
$diff->shouldContain('12345f');
}
}

View File

@@ -30,7 +30,7 @@ DIFF;
$this->compare('string1', 'string2')->shouldBeEqualRegardlessOfLineEndings($expected);
}
public function getMatchers() : array
public function getMatchers(): array
{
return [
'beEqualRegardlessOfLineEndings' => function ($actual, $expected) {

View File

@@ -16,7 +16,7 @@ class ProgressFormatterSpec extends ObjectBehavior
$this->beConstructedWith($presenter, $io, $stats);
$io->getBlockWidth()->willReturn(80);
$io->isDecorated()->willReturn(false);
$io->writeTemp(Argument::cetera())->willReturn();
$io->writeTemp(Argument::cetera())->should(function () {});
}
function it_is_an_event_subscriber()
@@ -105,7 +105,6 @@ class ProgressFormatterSpec extends ObjectBehavior
$io->isDecorated()->willReturn(false);
$io->getBlockWidth()->willReturn(0);
$io->isVerbose()->willReturn(false);
$expected = '/ skipped: 0% / pending: 0% / passed: 33% / failed: 66% / broken: 0% / 3 examples';
$io->writeTemp($expected)->shouldBeCalled();

View File

@@ -26,7 +26,7 @@ class ClassNotFoundListenerSpec extends ObjectBehavior
Resource $resource
)
{
$io->writeln(Argument::any())->willReturn();
$io->writeln(Argument::any())->should(function () {});
$io->askConfirmation(Argument::any())->willReturn(false);
$exception->getClassname()->willReturn('SomeClass');

View File

@@ -29,7 +29,7 @@ class CollaboratorNotFoundListenerSpec extends ObjectBehavior
$io->isCodeGenerationEnabled()->willReturn(true);
$io->askConfirmation(Argument::any())->willReturn(false);
$io->writeln(Argument::any())->willReturn(null);
$io->writeln(Argument::any())->should(function() {});
}
function it_listens_to_afterexample_and_aftersuite_events()

View File

@@ -25,7 +25,7 @@ class MethodNotFoundListenerSpec extends ObjectBehavior
ExampleEvent $exampleEvent,
NameChecker $nameChecker
) {
$io->writeln(Argument::any())->willReturn();
$io->writeln(Argument::any())->should(function() {});
$io->askConfirmation(Argument::any())->willReturn(false);
$this->beConstructedWith($io, $resourceManager, $generatorManager, $nameChecker);

View File

@@ -23,7 +23,7 @@ class NamedConstructorNotFoundListenerSpec extends ObjectBehavior
ExampleEvent $exampleEvent,
NamedConstructorNotFoundException $exception)
{
$io->writeln(Argument::any())->willReturn();
$io->writeln(Argument::any())->should(function() {});;
$io->askConfirmation(Argument::any())->willReturn(false);
$this->beConstructedWith($io, $resourceManager, $generatorManager);

View File

@@ -68,11 +68,7 @@ final class IterateLikeMatcherSpec extends ObjectBehavior
$second->foo = 'bar';
$this
->shouldThrow(new SubjectElementDoesNotMatchException(0, '"0"', '"stdClass::__set_state(array(
\'foo\' => \'foo\',
))"', '"0"', '"stdClass::__set_state(array(
\'foo\' => \'bar\',
))"'))
->shouldThrow(SubjectElementDoesNotMatchException::class)
->during('positiveMatch', [
'iterateLike',
$this->createGeneratorReturningArray([$first]),

View File

@@ -1,12 +1,12 @@
<?php
declare(strict_types = 1);
namespace spec\PhpSpec\Matcher;
use PhpSpec\Formatter\Presenter\Presenter;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use PhpSpec\Formatter\Presenter\Presenter;
class ObjectStateMatcherSpec extends ObjectBehavior
{
function let(Presenter $presenter)
@@ -90,4 +90,30 @@ class ObjectStateMatcherSpec extends ObjectBehavior
$this->supports('beCallable', $subject, array())->shouldReturn(false);
}
function it_does_not_throw_when_positive_match_true()
{
$subject = new class
{
public function isMatched()
{
return true;
}
};
$this->positiveMatch('beMatched', $subject, [])->shouldBe(null);
}
function it_does_not_throw_when_negative_match_false()
{
$subject = new class
{
public function isMatched()
{
return false;
}
};
$this->negativeMatch('beMatched', $subject, [])->shouldBe(null);
}
}

View File

@@ -0,0 +1,470 @@
<?php
namespace spec\PhpSpec\Matcher;
use PhpSpec\Formatter\Presenter\Presenter;
use PhpSpec\Matcher\Matcher;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ScalarMatcherSpec extends ObjectBehavior
{
function let(Presenter $presenter)
{
$presenter->presentValue(Argument::any())->willReturn('val1', 'val2');
$this->beConstructedWith($presenter);
}
function it_is_a_matcher()
{
$this->shouldBeAnInstanceOf(Matcher::class);
}
function it_responds_to_be_array()
{
$this->supports('beArray', '', [''])->shouldReturn(true);
}
function it_matches_array()
{
$this->shouldNotThrow()->duringPositiveMatch('beArray', [], ['']);
}
function it_does_not_match_not_array_with_be_array_matcher()
{
$this->shouldThrow()->duringPositiveMatch('beArray', Argument::not([]), ['']);
}
function it_mismatches_not_array()
{
$this->shouldNotThrow()->duringNegativeMatch('beArray', Argument::not([]), ['']);
}
function it_does_not_mismatch_array()
{
$this->shouldThrow()->duringNegativeMatch('beArray', [], ['']);
}
function it_responds_to_be_bool()
{
$this->supports('beBool', '', [''])->shouldReturn(true);
}
function it_matches_bool()
{
$this->shouldNotThrow()->duringPositiveMatch('beBool', false, ['']);
}
function it_does_not_match_not_bool_with_be_bool_matcher()
{
$this->shouldThrow()->duringPositiveMatch('beBool', Argument::not(false), ['']);
}
function it_mismatches_not_bool()
{
$this->shouldNotThrow()->duringNegativeMatch('beBool', Argument::not(false), ['']);
}
function it_does_not_mismatch_bool()
{
$this->shouldThrow()->duringNegativeMatch('beBool', false, ['']);
}
function it_responds_to_be_boolean()
{
$this->supports('beBoolean', '', [''])->shouldReturn(true);
}
function it_matches_boolean()
{
$this->shouldNotThrow()->duringPositiveMatch('beBoolean', false, ['']);
}
function it_does_not_match_not_boolean()
{
$this->shouldThrow()->duringPositiveMatch('beBoolean', Argument::not(false), ['']);
}
function it_mismatches_not_boolean()
{
$this->shouldNotThrow()->duringNegativeMatch('beBoolean', Argument::not(false), ['']);
}
function it_does_not_mismatch_boolean()
{
$this->shouldThrow()->duringNegativeMatch('beBoolean', false, ['']);
}
function it_responds_to_be_callable()
{
$this->supports('beCallable', '', [''])->shouldReturn(true);
}
function it_matches_callable()
{
$this->shouldNotThrow()->duringPositiveMatch('beCallable', function () { return true; }, ['']);
}
function it_does_not_match_not_callable()
{
$this->shouldThrow()->duringPositiveMatch('beCallable', Argument::not(function () { return true; }), ['']);
}
function it_mismatches_not_callable()
{
$this->shouldNotThrow()->duringNegativeMatch('beCallable', Argument::not(function () { return true; }), ['']);
}
function it_does_not_mismatch_callable()
{
$this->shouldThrow()->duringNegativeMatch('beCallable', function () { return true; }, ['']);
}
// FROM PHP 7.3 - Implement also positive match and negative match
// function it_responds_to_be_countable()
// {
// $this->supports('beCountable', '', [''])->shouldReturn(true);
// }
function it_responds_to_be_double()
{
$this->supports('beDouble', '', [''])->shouldReturn(true);
}
function it_matches_double()
{
$this->shouldNotThrow()->duringPositiveMatch('beDouble', doubleval(10.5), ['']);
}
function it_does_not_match_not_double()
{
$this->shouldThrow()->duringPositiveMatch('beDouble', Argument::not(doubleval(10.5)), ['']);
}
function it_mismatches_not_double()
{
$this->shouldNotThrow()->duringNegativeMatch('beDouble', Argument::not(doubleval(10.5)), ['']);
}
function it_does_not_mismatches_double()
{
$this->shouldThrow()->duringNegativeMatch('beDouble', doubleval(10.5), ['']);
}
function it_responds_to_be_float()
{
$this->supports('beFloat', '', [''])->shouldReturn(true);
}
function it_matches_float()
{
$this->shouldNotThrow()->duringPositiveMatch('beFloat', 10.5, ['']);
}
function it_does_not_match_not_float()
{
$this->shouldThrow()->duringPositiveMatch('beFloat', Argument::not(10.5), ['']);
}
function it_mismatches_not_float()
{
$this->shouldNotThrow()->duringNegativeMatch('beFloat', Argument::not(10.5), ['']);
}
function it_does_not_mismatches_float()
{
$this->shouldThrow()->duringNegativeMatch('beFloat', 10.5, ['']);
}
function it_responds_to_be_int()
{
$this->supports('beInt', '', [''])->shouldReturn(true);
}
function it_matches_int()
{
$this->shouldNotThrow()->duringPositiveMatch('beInt', 1, ['']);
}
function it_does_not_match_not_int()
{
$this->shouldThrow()->duringPositiveMatch('beInt', Argument::not(1), ['']);
}
function it_mismatches_not_int()
{
$this->shouldNotThrow()->duringNegativeMatch('beInt', Argument::not(1), ['']);
}
function it_does_not_mismatches_int()
{
$this->shouldThrow()->duringNegativeMatch('beInt', 1, ['']);
}
function it_responds_to_be_integer()
{
$this->supports('beInteger', '', [''])->shouldReturn(true);
}
function it_matches_int_with_integer_matcher()
{
$this->shouldNotThrow()->duringPositiveMatch('beInteger', 1, ['']);
}
function it_does_not_match_not_integer_match()
{
$this->shouldThrow()->duringPositiveMatch('beInteger', Argument::not(1), ['']);
}
function it_mismatches_not_integer()
{
$this->shouldNotThrow()->duringNegativeMatch('beInteger', Argument::not(1), ['']);
}
function it_does_not_mismatches_integer()
{
$this->shouldThrow()->duringNegativeMatch('beInteger', 1, ['']);
}
function it_responds_to_be_iterable()
{
$this->supports('beIterable', '', [''])->shouldReturn(true);
}
function it_matches_iterable()
{
$this->shouldNotThrow()->duringPositiveMatch('beIterable', [], ['']);
}
function it_does_not_match_not_iterable()
{
$this->shouldThrow()->duringPositiveMatch('beIterable', Argument::not([]), ['']);
}
function it_mismatches_not_iterable()
{
$this->shouldNotThrow()->duringNegativeMatch('beIterable', Argument::not([]), ['']);
}
function it_does_not_mismatches_iterable()
{
$this->shouldThrow()->duringNegativeMatch('beIterable', [], ['']);
}
function it_responds_to_be_long()
{
$this->supports('beLong', '', [''])->shouldReturn(true);
}
function it_matches_long()
{
$this->shouldNotThrow()->duringPositiveMatch('beLong', PHP_INT_MAX, ['']);
}
function it_does_not_match_not_long()
{
$this->shouldThrow()->duringPositiveMatch('beLong', Argument::not(PHP_INT_MAX), ['']);
}
function it_mismatches_not_long()
{
$this->shouldNotThrow()->duringNegativeMatch('beLong', Argument::not(PHP_INT_MAX), ['']);
}
function it_does_not_mismatches_long()
{
$this->shouldThrow()->duringNegativeMatch('beLong', PHP_INT_MAX, ['']);
}
function it_responds_to_be_null()
{
$this->supports('beNull', '', [''])->shouldReturn(true);
}
function it_matches_null()
{
$this->shouldNotThrow()->duringPositiveMatch('beNull', null, ['']);
}
function it_does_not_match_not_null()
{
$this->shouldThrow()->duringPositiveMatch('beNull', Argument::not(null), ['']);
}
function it_mismatches_not_null()
{
$this->shouldNotThrow()->duringNegativeMatch('beNull', Argument::not(null), ['']);
}
function it_does_not_mismatches_null()
{
$this->shouldThrow()->duringNegativeMatch('beNull', null, ['']);
}
function it_responds_to_be_numeric()
{
$this->supports('beNumeric', '', [''])->shouldReturn(true);
}
function it_matches_numeric_string()
{
$this->shouldNotThrow()->duringPositiveMatch('beNumeric', '123', ['']);
}
function it_matches_numeric_number()
{
$this->shouldNotThrow()->duringPositiveMatch('beNumeric', 123, ['']);
}
function it_does_not_match_not_numeric_string()
{
$this->shouldThrow()->duringPositiveMatch('beNumeric', Argument::not('123'), ['']);
}
function it_does_not_match_not_numeric()
{
$this->shouldThrow()->duringPositiveMatch('beNumeric', Argument::not(123), ['']);
}
function it_mismatches_not_number()
{
$this->shouldNotThrow()->duringNegativeMatch('beNumeric', Argument::not(123), ['']);
}
function it_does_not_mismatches_number()
{
$this->shouldThrow()->duringNegativeMatch('beNumeric', 123, ['']);
}
function it_responds_to_be_object()
{
$this->supports('beObject', '', [''])->shouldReturn(true);
}
function it_matches_object()
{
$this->shouldNotThrow()->duringPositiveMatch('beObject', new \stdClass(), ['']);
}
function it_does_not_match_not_object()
{
$this->shouldThrow()->duringPositiveMatch('beObject', null, ['']);
}
function it_mismatches_not_object()
{
$this->shouldNotThrow()->duringNegativeMatch('beObject', null, ['']);
}
function it_does_not_mismatches_object()
{
$this->shouldThrow()->duringNegativeMatch('beObject', new \stdClass(), ['']);
}
function it_responds_to_be_real()
{
$this->supports('beReal', '', [''])->shouldReturn(true);
}
function it_matches_real()
{
$this->shouldNotThrow()->duringPositiveMatch('beReal', 10.5, ['']);
}
function it_does_not_match_not_real()
{
$this->shouldThrow()->duringPositiveMatch('beReal', Argument::not(10.5), ['']);
}
function it_mismatches_not_real()
{
$this->shouldNotThrow()->duringNegativeMatch('beReal', Argument::not(10.5), ['']);
}
function it_does_not_mismatches_real()
{
$this->shouldThrow()->duringNegativeMatch('beReal', 10.5, ['']);
}
function it_responds_to_be_resource()
{
$this->supports('beResource', '', [''])->shouldReturn(true);
}
function it_matches_a_resource()
{
$fp = fopen(__FILE__, 'r');
$this->shouldNotThrow()->duringPositiveMatch('beResource', $fp, ['']);
fclose($fp);
}
function it_does_not_match_not_resource()
{
$this->shouldThrow()->duringPositiveMatch('beResource', null, ['']);
}
function it_mismatches_not_resource()
{
$this->shouldNotThrow()->duringNegativeMatch('beResource', null, ['']);
}
function it_does_not_mismatches_resource()
{
$fp = fopen(__FILE__, 'r');
$this->shouldThrow()->duringNegativeMatch('beResource', $fp, ['']);
fclose($fp);
}
function it_responds_to_be_scalar()
{
$this->supports('beScalar', '', [''])->shouldReturn(true);
}
function it_matches_scalar()
{
$this->shouldNotThrow()->duringPositiveMatch('beScalar', 'foo', ['']);
}
function it_does_not_match_not_scalar()
{
$this->shouldThrow()->duringPositiveMatch('beResource', null, ['']);
}
function it_mismatches_not_scalar()
{
$this->shouldNotThrow()->duringNegativeMatch('beResource', null, ['']);
}
function it_does_not_mismatches_scalar()
{
$this->shouldThrow()->duringNegativeMatch('beScalar', 'foo', ['']);
}
function it_responds_to_be_string()
{
$this->supports('beString', '', [''])->shouldReturn(true);
}
function it_matches_string()
{
$this->shouldNotThrow()->duringPositiveMatch('beString', 'foo', ['']);
}
function it_does_not_match_not_string()
{
$this->shouldThrow()->duringPositiveMatch('beString', Argument::not('foo'), ['']);
}
function it_mismatches_not_stringt()
{
$this->shouldNotThrow()->duringNegativeMatch('beString', Argument::not('foo'), ['']);
}
function it_does_not_mismatches_string()
{
$this->shouldThrow()->duringNegativeMatch('beString', 'foo', ['']);
}
}

View File

@@ -30,7 +30,7 @@ class ComposerPsrNamespaceProviderSpec extends ObjectBehavior
);
}
public function getMatchers() : array
public function getMatchers(): array
{
return array(
'haveNamespaceLocation' => function ($subject, $namespace, $location, $standard) {

View File

@@ -47,7 +47,7 @@ class CompositeReRunnerSpec extends ObjectBehavior
$reRunner1->isSupported()->willReturn(false);
$reRunner2->isSupported()->willReturn(true);
$reRunner2->reRunSuite()->willReturn();
$reRunner2->reRunSuite()->should(function() {});;
$this->reRunSuite();

View File

@@ -19,11 +19,13 @@ class SuiteRunnerSpec extends ObjectBehavior
SpecificationNode $spec1, SpecificationNode $spec2)
{
$this->beConstructedWith($dispatcher, $specRunner);
$suite->getSpecifications()->willReturn( array($spec1, $spec2));
$suite->getSpecifications()->willReturn(array($spec1, $spec2));
}
function it_runs_all_specs_in_the_suite_through_the_specrunner($suite, $specRunner, $spec1, $spec2)
{
$specRunner->run($spec1)->willReturn(ExampleEvent::PASSED);
$specRunner->run($spec2)->willReturn(ExampleEvent::PASSED);
$this->run($suite);
$specRunner->run($spec1)->shouldHaveBeenCalled();
@@ -63,8 +65,11 @@ class SuiteRunnerSpec extends ObjectBehavior
$this->run($suite)->shouldReturn(ExampleEvent::FAILED);
}
function it_dispatches_events_before_and_after_the_suite($suite, $dispatcher)
function it_dispatches_events_before_and_after_the_suite($suite, $specRunner, $spec1, $spec2, $dispatcher)
{
$specRunner->run($spec1)->willReturn(ExampleEvent::PASSED);
$specRunner->run($spec2)->willReturn(ExampleEvent::PASSED);
$this->run($suite);
$dispatcher->dispatch('beforeSuite',

View File

@@ -3,7 +3,9 @@
namespace spec\PhpSpec\Wrapper\Subject;
use Phpspec\CodeAnalysis\AccessInspector;
use PhpSpec\Exception\Example\FailureException;
use PhpSpec\Exception\ExceptionFactory;
use PhpSpec\Exception\Fracture\PropertyNotFoundException;
use PhpSpec\Wrapper\Subject\WrappedObject;
use PhpSpec\Wrapper\Wrapper;
use PhpSpec\Wrapper\Subject;
@@ -27,6 +29,7 @@ class CallerSpec extends ObjectBehavior
$wrappedObject->isInstantiated()->willReturn(false);
$wrappedObject->getClassName()->willReturn(null);
$wrappedObject->getInstance()->willReturn(null);
$exceptions->propertyNotFound(Argument::cetera())->willReturn(new PropertyNotFoundException('Message', 'subject', 'prop'));
$accessInspector->isMethodCallable(Argument::cetera())->willReturn(false);
}
@@ -52,8 +55,10 @@ class CallerSpec extends ObjectBehavior
$this->call('count');
}
function it_sets_a_property_on_the_wrapped_object(WrappedObject $wrappedObject,
AccessInspector $accessInspector)
function it_sets_a_property_on_the_wrapped_object(
WrappedObject $wrappedObject,
AccessInspector $accessInspector,
Wrapper $wrapper)
{
$obj = new \stdClass();
$obj->id = 1;
@@ -62,10 +67,19 @@ class CallerSpec extends ObjectBehavior
Argument::type('stdClass'), 'id'
)->willReturn('true');
$accessInspector->isPropertyReadable(
Argument::type('stdClass'), 'id'
)->willReturn('true');
$wrappedObject->isInstantiated()->willReturn(true);
$wrappedObject->getInstance()->willReturn($obj);
$this->set('id', 2)->shouldReturn(2);
$wrapper->wrap(2)->willReturn(2);
$this->set('id', 2);
if ($obj->id !== 2) {
throw new FailureException();
}
}
function it_proxies_method_calls_to_wrapped_object(\ArrayObject $obj, WrappedObject $wrappedObject,

View File

@@ -18,15 +18,15 @@ interface AccessInspector
/**
* @param object $object
*/
public function isPropertyReadable($object, string $property) : bool;
public function isPropertyReadable($object, string $property): bool;
/**
* @param object $object
*/
public function isPropertyWritable($object, string $property) : bool;
public function isPropertyWritable($object, string $property): bool;
/**
* @param object $object
*/
public function isMethodCallable($object, string $method) : bool;
public function isMethodCallable($object, string $method): bool;
}

View File

@@ -31,7 +31,7 @@ final class MagicAwareAccessInspector implements AccessInspector
/**
* @param object $object
*/
public function isPropertyReadable($object, string $property) : bool
public function isPropertyReadable($object, string $property): bool
{
return method_exists($object, '__get') || $this->accessInspector->isPropertyReadable($object, $property);
}
@@ -39,7 +39,7 @@ final class MagicAwareAccessInspector implements AccessInspector
/**
* @param object $object
*/
public function isPropertyWritable($object, string $property) : bool
public function isPropertyWritable($object, string $property): bool
{
return method_exists($object, '__set') || $this->accessInspector->isPropertyWritable($object, $property);
}
@@ -47,7 +47,7 @@ final class MagicAwareAccessInspector implements AccessInspector
/**
* @param object $object
*/
public function isMethodCallable($object, string $method) : bool
public function isMethodCallable($object, string $method): bool
{
return method_exists($object, '__call') || $this->accessInspector->isMethodCallable($object, $method);
}

View File

@@ -15,7 +15,7 @@ namespace PhpSpec\CodeAnalysis;
interface NamespaceResolver
{
public function analyse(string $code);
public function analyse(string $code): void;
public function resolve(string $typeAlias) : string;
public function resolve(string $typeAlias): string;
}

View File

@@ -25,12 +25,12 @@ final class StaticRejectingNamespaceResolver implements NamespaceResolver
$this->namespaceResolver = $namespaceResolver;
}
public function analyse(string $code)
public function analyse(string $code): void
{
$this->namespaceResolver->analyse($code);
}
public function resolve(string $typeAlias) : string
public function resolve(string $typeAlias): string
{
$this->guardNonObjectTypeHints($typeAlias);

View File

@@ -30,7 +30,7 @@ final class TokenizedNamespaceResolver implements NamespaceResolver
/**
* @param string $code
*/
public function analyse(string $code)
public function analyse(string $code): void
{
$this->state = self::STATE_DEFAULT;
$this->currentUse = null;
@@ -95,7 +95,7 @@ final class TokenizedNamespaceResolver implements NamespaceResolver
}
}
public function resolve(string $typeAlias) : string
public function resolve(string $typeAlias): string
{
if (strpos($typeAlias, '\\') === 0) {
return substr($typeAlias, 1);

View File

@@ -52,7 +52,7 @@ final class TokenizedTypeHintRewriter implements TypeHintRewriter
$this->namespaceResolver = $namespaceResolver;
}
public function rewrite(string $classDefinition) : string
public function rewrite(string $classDefinition): string
{
$this->namespaceResolver->analyse($classDefinition);
@@ -63,14 +63,14 @@ final class TokenizedTypeHintRewriter implements TypeHintRewriter
return $tokensToString;
}
private function reset()
private function reset(): void
{
$this->state = self::STATE_DEFAULT;
$this->currentClass = '';
$this->currentFunction = '';
}
private function stripTypeHints(array $tokens) : array
private function stripTypeHints(array $tokens): array
{
foreach ($tokens as $index => $token) {
if ($this->isToken($token, '{')) {
@@ -134,14 +134,14 @@ final class TokenizedTypeHintRewriter implements TypeHintRewriter
* @param array $tokens
* @return string
*/
private function tokensToString(array $tokens) : string
private function tokensToString(array $tokens): string
{
return join('', array_map(function ($token) {
return \is_array($token) ? $token[1] : $token;
}, $tokens));
}
private function extractTypehints(array &$tokens, int $index, array $token)
private function extractTypehints(array &$tokens, int $index, array $token): void
{
$typehint = '';
for ($i = $index - 1; \in_array($tokens[$i][0], $this->typehintTokens); $i--) {
@@ -176,12 +176,12 @@ final class TokenizedTypeHintRewriter implements TypeHintRewriter
/**
* @param array|string $token
*/
private function tokenHasType($token, string $type) : bool
private function tokenHasType($token, string $type): bool
{
return \is_array($token) && $type == $token[0];
}
private function shouldExtractTokensOfClass(string $className) : bool
private function shouldExtractTokensOfClass(string $className): bool
{
return substr($className, -4) == 'Spec';
}
@@ -189,7 +189,7 @@ final class TokenizedTypeHintRewriter implements TypeHintRewriter
/**
* @param array|string $token
*/
private function isToken($token, string $string) : bool
private function isToken($token, string $string): bool
{
return $token == $string || (\is_array($token) && $token[1] == $string);
}

View File

@@ -20,5 +20,5 @@ interface TypeHintRewriter
*
* @return string
*/
public function rewrite(string $classDefinition) : string;
public function rewrite(string $classDefinition): string;
}

View File

@@ -21,7 +21,7 @@ final class VisibilityAccessInspector implements AccessInspector
/**
* @param object $object
*/
public function isPropertyReadable($object, string $property) : bool
public function isPropertyReadable($object, string $property): bool
{
return $this->isExistingPublicProperty($object, $property);
}
@@ -29,7 +29,7 @@ final class VisibilityAccessInspector implements AccessInspector
/**
* @param object $object
*/
public function isPropertyWritable($object, string $property) : bool
public function isPropertyWritable($object, string $property): bool
{
return $this->isExistingPublicProperty($object, $property);
}
@@ -37,7 +37,7 @@ final class VisibilityAccessInspector implements AccessInspector
/**
* @param object $object
*/
private function isExistingPublicProperty($object, string $property) : bool
private function isExistingPublicProperty($object, string $property): bool
{
if (!property_exists($object, $property)) {
return false;
@@ -51,7 +51,7 @@ final class VisibilityAccessInspector implements AccessInspector
/**
* @param object $object
*/
public function isMethodCallable($object, string $method) : bool
public function isMethodCallable($object, string $method): bool
{
return $this->isExistingPublicMethod($object, $method);
}
@@ -59,7 +59,7 @@ final class VisibilityAccessInspector implements AccessInspector
/**
* @param object $object
*/
private function isExistingPublicMethod($object, string $method) : bool
private function isExistingPublicMethod($object, string $method): bool
{
if (!method_exists($object, $method)) {
return false;

View File

@@ -28,17 +28,17 @@ final class ClassGenerator extends PromptingGenerator
*
* @return bool
*/
public function supports(Resource $resource, string $generation, array $data) : bool
public function supports(Resource $resource, string $generation, array $data): bool
{
return 'class' === $generation;
}
public function getPriority() : int
public function getPriority(): int
{
return 0;
}
protected function renderTemplate(Resource $resource, string $filepath) : string
protected function renderTemplate(Resource $resource, string $filepath): string
{
$values = array(
'%filepath%' => $filepath,
@@ -59,17 +59,17 @@ final class ClassGenerator extends PromptingGenerator
return $content;
}
protected function getTemplate() : string
protected function getTemplate(): string
{
return file_get_contents(__DIR__.'/templates/class.template');
}
protected function getFilePath(Resource $resource) : string
protected function getFilePath(Resource $resource): string
{
return $resource->getSrcFilename();
}
protected function getGeneratedMessage(Resource $resource, string $filepath) : string
protected function getGeneratedMessage(Resource $resource, string $filepath): string
{
return sprintf(
"<info>Class <value>%s</value> created in <value>%s</value>.</info>\n",

View File

@@ -40,7 +40,7 @@ final class ConfirmingGenerator implements Generator
$this->generator = $generator;
}
public function supports(Resource $resource, string $generation, array $data) : bool
public function supports(Resource $resource, string $generation, array $data): bool
{
return $this->generator->supports($resource, $generation, $data);
}
@@ -48,19 +48,19 @@ final class ConfirmingGenerator implements Generator
/**
* {@inheritdoc}
*/
public function generate(Resource $resource, array $data)
public function generate(Resource $resource, array $data): void
{
if ($this->io->askConfirmation($this->composeMessage($resource))) {
$this->generator->generate($resource, $data);
}
}
private function composeMessage(Resource $resource) : string
private function composeMessage(Resource $resource): string
{
return str_replace('{CLASSNAME}', $resource->getSrcClassname(), $this->message);
}
public function getPriority() : int
public function getPriority(): int
{
return $this->generator->getPriority();
}

View File

@@ -30,7 +30,7 @@ class CreateObjectTemplate
$this->className = $className;
}
public function getContent()
public function getContent(): string
{
$values = $this->getValues();
@@ -44,7 +44,7 @@ class CreateObjectTemplate
return $content;
}
private function getTemplate() : string
private function getTemplate(): string
{
return file_get_contents(__DIR__.'/templates/named_constructor_create_object.template');
}
@@ -52,7 +52,7 @@ class CreateObjectTemplate
/**
* @return string[]
*/
private function getValues() : array
private function getValues(): array
{
$argString = \count($this->arguments)
? '$argument'.implode(', $argument', range(1, \count($this->arguments)))

View File

@@ -33,7 +33,7 @@ class ExistingConstructorTemplate
$this->methodName = $methodName;
}
public function getContent() : string
public function getContent(): string
{
if (!$this->numberOfConstructorArgumentsMatchMethod()) {
return $this->getExceptionContent();
@@ -42,7 +42,7 @@ class ExistingConstructorTemplate
return $this->getCreateObjectContent();
}
private function numberOfConstructorArgumentsMatchMethod() : bool
private function numberOfConstructorArgumentsMatchMethod(): bool
{
$constructorArguments = 0;
@@ -58,7 +58,7 @@ class ExistingConstructorTemplate
return $constructorArguments == \count($this->arguments);
}
private function getExceptionContent() : string
private function getExceptionContent(): string
{
$values = $this->getValues();
@@ -72,7 +72,7 @@ class ExistingConstructorTemplate
return $content;
}
private function getCreateObjectContent() : string
private function getCreateObjectContent(): string
{
$values = $this->getValues(true);
@@ -89,7 +89,7 @@ class ExistingConstructorTemplate
/**
* @return string[]
*/
private function getValues(bool $constructorArguments = false) : array
private function getValues(bool $constructorArguments = false): array
{
$argString = \count($this->arguments)
? '$argument'.implode(', $argument', range(1, \count($this->arguments)))

View File

@@ -20,9 +20,9 @@ use PhpSpec\Locator\Resource;
*/
interface Generator
{
public function supports(Resource $resource, string $generation, array $data) : bool;
public function supports(Resource $resource, string $generation, array $data): bool;
public function generate(Resource $resource, array $data);
public function generate(Resource $resource, array $data): void;
public function getPriority() : int;
public function getPriority(): int;
}

View File

@@ -21,17 +21,17 @@ use PhpSpec\Locator\Resource;
*/
final class InterfaceGenerator extends PromptingGenerator
{
public function supports(Resource $resource, string $generation, array $data) : bool
public function supports(Resource $resource, string $generation, array $data): bool
{
return 'interface' === $generation;
}
public function getPriority() : int
public function getPriority(): int
{
return 0;
}
protected function renderTemplate(Resource $resource, string $filepath) : string
protected function renderTemplate(Resource $resource, string $filepath): string
{
$values = array(
'%filepath%' => $filepath,
@@ -51,17 +51,17 @@ final class InterfaceGenerator extends PromptingGenerator
return $content;
}
protected function getTemplate() : string
protected function getTemplate(): string
{
return file_get_contents(__DIR__.'/templates/interface.template');
}
protected function getFilePath(Resource $resource) : string
protected function getFilePath(Resource $resource): string
{
return $resource->getSrcFilename();
}
protected function getGeneratedMessage(Resource $resource, string $filepath) : string
protected function getGeneratedMessage(Resource $resource, string $filepath): string
{
return sprintf(
"<info>Interface <value>%s</value> created in <value>%s</value>.</info>\n",

View File

@@ -58,7 +58,7 @@ final class MethodGenerator implements Generator
$this->codeWriter = $codeWriter;
}
public function supports(Resource $resource, string $generation, array $data) : bool
public function supports(Resource $resource, string $generation, array $data): bool
{
return 'method' === $generation;
}
@@ -67,7 +67,7 @@ final class MethodGenerator implements Generator
* @param Resource $resource
* @param array $data
*/
public function generate(Resource $resource, array $data = array())
public function generate(Resource $resource, array $data = array()): void
{
$filepath = $resource->getSrcFilename();
$name = $data['name'];
@@ -96,17 +96,17 @@ final class MethodGenerator implements Generator
), 2);
}
public function getPriority() : int
public function getPriority(): int
{
return 0;
}
protected function getTemplate() : string
protected function getTemplate(): string
{
return file_get_contents(__DIR__.'/templates/method.template');
}
private function getUpdatedCode(string $methodName, string $snippetToInsert, string $code) : string
private function getUpdatedCode(string $methodName, string $snippetToInsert, string $code): string
{
if ('__construct' === $methodName) {
return $this->codeWriter->insertMethodFirstInClass($code, $snippetToInsert);

View File

@@ -50,12 +50,12 @@ final class MethodSignatureGenerator implements Generator
$this->filesystem = $filesystem;
}
public function supports(Resource $resource, string $generation, array $data) : bool
public function supports(Resource $resource, string $generation, array $data): bool
{
return 'method-signature' === $generation;
}
public function generate(Resource $resource, array $data = array())
public function generate(Resource $resource, array $data = array()): void
{
$filepath = $resource->getSrcFilename();
$name = $data['name'];
@@ -78,12 +78,12 @@ final class MethodSignatureGenerator implements Generator
), 2);
}
public function getPriority() : int
public function getPriority(): int
{
return 0;
}
protected function getTemplate() : string
protected function getTemplate(): string
{
return file_get_contents(__DIR__.'/templates/interface_method_signature.template');
}
@@ -95,7 +95,7 @@ final class MethodSignatureGenerator implements Generator
$this->filesystem->putFileContents($filepath, $code);
}
private function buildArgumentString(array $arguments) : string
private function buildArgumentString(array $arguments): string
{
$argString = \count($arguments)
? '$argument' . implode(', $argument', range(1, \count($arguments)))

View File

@@ -55,7 +55,7 @@ final class NamedConstructorGenerator implements Generator
$this->codeWriter = $codeWriter;
}
public function supports(Resource $resource, string $generation, array $data) : bool
public function supports(Resource $resource, string $generation, array $data): bool
{
return 'named_constructor' === $generation;
}
@@ -64,7 +64,7 @@ final class NamedConstructorGenerator implements Generator
* @param Resource $resource
* @param array $data
*/
public function generate(Resource $resource, array $data = array())
public function generate(Resource $resource, array $data = array()): void
{
$filepath = $resource->getSrcFilename();
$methodName = $data['name'];
@@ -86,12 +86,12 @@ final class NamedConstructorGenerator implements Generator
), 2);
}
public function getPriority() : int
public function getPriority(): int
{
return 0;
}
private function getContent(Resource $resource, string $methodName, array $arguments) : string
private function getContent(Resource $resource, string $methodName, array $arguments): string
{
$className = $resource->getName();
$class = $resource->getSrcClassname();
@@ -111,7 +111,7 @@ final class NamedConstructorGenerator implements Generator
return $template->getContent();
}
private function appendMethodToCode(string $code, string $method) : string
private function appendMethodToCode(string $code, string $method): string
{
try {
return $this->codeWriter->insertAfterMethod($code, '__construct', $method);

View File

@@ -36,12 +36,12 @@ final class NewFileNotifyingGenerator implements Generator
$this->filesystem = $filesystem;
}
public function supports(Resource $resource, string $generation, array $data) : bool
public function supports(Resource $resource, string $generation, array $data): bool
{
return $this->generator->supports($resource, $generation, $data);
}
public function generate(Resource $resource, array $data)
public function generate(Resource $resource, array $data): void
{
$filePath = $this->getFilePath($resource);
@@ -52,12 +52,12 @@ final class NewFileNotifyingGenerator implements Generator
$this->dispatchEventIfFileWasCreated($fileExisted, $filePath);
}
public function getPriority() : int
public function getPriority(): int
{
return $this->generator->getPriority();
}
private function getFilePath(Resource $resource) : string
private function getFilePath(Resource $resource): string
{
if ($this->generator->supports($resource, 'specification', array())) {
return $resource->getSpecFilename();
@@ -66,12 +66,12 @@ final class NewFileNotifyingGenerator implements Generator
return $resource->getSrcFilename();
}
private function fileExists(string $filePath) : bool
private function fileExists(string $filePath): bool
{
return $this->filesystem->pathExists($filePath);
}
private function dispatchEventIfFileWasCreated(bool $fileExisted, string $filePath)
private function dispatchEventIfFileWasCreated(bool $fileExisted, string $filePath): void
{
if (!$fileExisted && $this->fileExists($filePath)) {
$event = new FileCreationEvent($filePath);

View File

@@ -35,7 +35,7 @@ final class OneTimeGenerator implements Generator
$this->generator = $generator;
}
public function supports(Resource $resource, string $generation, array $data) : bool
public function supports(Resource $resource, string $generation, array $data): bool
{
return $this->generator->supports($resource, $generation, $data);
}
@@ -43,7 +43,7 @@ final class OneTimeGenerator implements Generator
/**
* {@inheritdoc}
*/
public function generate(Resource $resource, array $data)
public function generate(Resource $resource, array $data): void
{
$classname = $resource->getSrcClassname();
if (\in_array($classname, $this->alreadyGenerated)) {
@@ -54,7 +54,7 @@ final class OneTimeGenerator implements Generator
$this->alreadyGenerated[] = $classname;
}
public function getPriority() : int
public function getPriority(): int
{
return $this->generator->getPriority();
}

View File

@@ -56,7 +56,7 @@ final class PrivateConstructorGenerator implements Generator
$this->codeWriter = $codeWriter;
}
public function supports(Resource $resource, string $generation, array $data) : bool
public function supports(Resource $resource, string $generation, array $data): bool
{
return 'private-constructor' === $generation;
}
@@ -65,7 +65,7 @@ final class PrivateConstructorGenerator implements Generator
* @param Resource $resource
* @param array $data
*/
public function generate(Resource $resource, array $data)
public function generate(Resource $resource, array $data): void
{
$filepath = $resource->getSrcFilename();
@@ -83,12 +83,12 @@ final class PrivateConstructorGenerator implements Generator
$this->io->writeln("<info>Private constructor has been created.</info>\n", 2);
}
public function getPriority() : int
public function getPriority(): int
{
return 0;
}
protected function getTemplate() : string
protected function getTemplate(): string
{
return file_get_contents(__DIR__.'/templates/private-constructor.template');
}

View File

@@ -62,7 +62,7 @@ abstract class PromptingGenerator implements Generator
* @param Resource $resource
* @param array $data
*/
public function generate(Resource $resource, array $data = array())
public function generate(Resource $resource, array $data = array()): void
{
$filepath = $this->getFilePath($resource);
@@ -79,14 +79,14 @@ abstract class PromptingGenerator implements Generator
$this->executionContext->addGeneratedType($resource->getSrcClassname());
}
protected function getTemplateRenderer() : TemplateRenderer
protected function getTemplateRenderer(): TemplateRenderer
{
return $this->templates;
}
abstract protected function getFilePath(Resource $resource) : string;
abstract protected function getFilePath(Resource $resource): string;
abstract protected function renderTemplate(Resource $resource, string $filepath) : string;
abstract protected function renderTemplate(Resource $resource, string $filepath): string;
/**
* @param Resource $resource
@@ -94,14 +94,14 @@ abstract class PromptingGenerator implements Generator
*
* @return string
*/
abstract protected function getGeneratedMessage(Resource $resource, string $filepath) : string;
abstract protected function getGeneratedMessage(Resource $resource, string $filepath): string;
private function fileAlreadyExists(string $filepath) : bool
private function fileAlreadyExists(string $filepath): bool
{
return $this->filesystem->pathExists($filepath);
}
private function userAborts(string $filepath) : bool
private function userAborts(string $filepath): bool
{
$message = sprintf('File "%s" already exists. Overwrite?', basename($filepath));

View File

@@ -45,7 +45,7 @@ final class ReturnConstantGenerator implements Generator
$this->filesystem = $filesystem;
}
public function supports(Resource $resource, string $generation, array $data) : bool
public function supports(Resource $resource, string $generation, array $data): bool
{
return 'returnConstant' == $generation;
}
@@ -54,7 +54,7 @@ final class ReturnConstantGenerator implements Generator
* @param Resource $resource
* @param array $data
*/
public function generate(Resource $resource, array $data)
public function generate(Resource $resource, array $data): void
{
$method = $data['method'];
$expected = $data['expected'];
@@ -83,12 +83,12 @@ final class ReturnConstantGenerator implements Generator
), 2);
}
public function getPriority() : int
public function getPriority(): int
{
return 0;
}
protected function getTemplate() : string
protected function getTemplate(): string
{
return file_get_contents(__DIR__.'/templates/returnconstant.template');
}

View File

@@ -14,6 +14,8 @@
namespace PhpSpec\CodeGenerator\Generator;
use PhpSpec\Locator\Resource;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
/**
* Generates spec classes from resources and puts them into the appropriate
@@ -21,12 +23,12 @@ use PhpSpec\Locator\Resource;
*/
final class SpecificationGenerator extends PromptingGenerator
{
public function supports(Resource $resource, string $generation, array $data) : bool
public function supports(Resource $resource, string $generation, array $data): bool
{
return 'specification' === $generation;
}
public function getPriority() : int
public function getPriority(): int
{
return 0;
}
@@ -37,14 +39,15 @@ final class SpecificationGenerator extends PromptingGenerator
*
* @return string
*/
protected function renderTemplate(Resource $resource, string $filepath) : string
protected function renderTemplate(Resource $resource, string $filepath): string
{
$values = array(
'%filepath%' => $filepath,
'%name%' => $resource->getSpecName(),
'%namespace%' => $resource->getSpecNamespace(),
'%imports%' => $this->getImports($resource),
'%subject%' => $resource->getSrcClassname(),
'%subject_class%' => $resource->getName()
'%subject_class%' => $resource->getName(),
);
if (!$content = $this->getTemplateRenderer()->render('specification', $values)) {
@@ -54,17 +57,17 @@ final class SpecificationGenerator extends PromptingGenerator
return $content;
}
protected function getTemplate() : string
protected function getTemplate(): string
{
return file_get_contents(__DIR__.'/templates/specification.template');
}
protected function getFilePath(Resource $resource) : string
protected function getFilePath(Resource $resource): string
{
return $resource->getSpecFilename();
}
protected function getGeneratedMessage(Resource $resource, string $filepath) : string
protected function getGeneratedMessage(Resource $resource, string $filepath): string
{
return sprintf(
"<info>Specification for <value>%s</value> created in <value>%s</value>.</info>\n",
@@ -72,4 +75,16 @@ final class SpecificationGenerator extends PromptingGenerator
$filepath
);
}
protected function getImports(Resource $resource): string
{
$imports = [$resource->getSrcClassname(), ObjectBehavior::class, Argument::class];
asort($imports);
foreach ($imports as &$import) {
$import = sprintf('use %s;', $import);
}
return implode("\n", $imports);
}
}

View File

@@ -37,7 +37,7 @@ final class ValidateClassNameSpecificationGenerator implements Generator
return $this->originalGenerator->supports($resource, $generation, $data);
}
public function generate(Resource $resource, array $data)
public function generate(Resource $resource, array $data): void
{
$className = $resource->getSrcClassname();
@@ -49,7 +49,7 @@ final class ValidateClassNameSpecificationGenerator implements Generator
$this->originalGenerator->generate($resource, $data);
}
private function writeInvalidClassNameError(string $className)
private function writeInvalidClassNameError(string $className): void
{
$error = "I cannot generate spec for '$className' because class name contains reserved keyword";
$this->io->writeBrokenCodeBlock($error, 2);

View File

@@ -2,9 +2,7 @@
namespace %namespace%;
use %subject%;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
%imports%
class %name% extends ObjectBehavior
{

View File

@@ -30,7 +30,7 @@ class GeneratorManager
/**
* @param Generator $generator
*/
public function registerGenerator(Generator $generator)
public function registerGenerator(Generator $generator): void
{
$this->generators[] = $generator;
@usort($this->generators, function (Generator $generator1, Generator $generator2) {
@@ -42,11 +42,13 @@ class GeneratorManager
* @return mixed
* @throws \InvalidArgumentException
*/
public function generate(Resource $resource, string $name, array $data = array())
public function generate(Resource $resource, string $name, array $data = array()): void
{
foreach ($this->generators as $generator) {
if ($generator->supports($resource, $name, $data)) {
return $generator->generate($resource, $data);
$generator->generate($resource, $data);
return;
}
}

View File

@@ -42,27 +42,27 @@ class TemplateRenderer
/**
* @param array $locations
*/
public function setLocations(array $locations)
public function setLocations(array $locations): void
{
$this->locations = array_map(array($this, 'normalizeLocation'), $locations);
}
public function prependLocation(string $location)
public function prependLocation(string $location): void
{
array_unshift($this->locations, $this->normalizeLocation($location));
}
public function appendLocation(string $location)
public function appendLocation(string $location): void
{
array_push($this->locations, $this->normalizeLocation($location));
}
public function getLocations() : array
public function getLocations(): array
{
return $this->locations;
}
public function render(string $name, array $values = array()) : string
public function render(string $name, array $values = array()): string
{
foreach ($this->locations as $location) {
$path = $location.DIRECTORY_SEPARATOR.$this->normalizeLocation($name, true).'.tpl';
@@ -74,12 +74,12 @@ class TemplateRenderer
return '';
}
public function renderString(string $template, array $values = array()) : string
public function renderString(string $template, array $values = array()): string
{
return strtr($template, $values);
}
private function normalizeLocation(string $location, bool $trimLeft = false) : string
private function normalizeLocation(string $location, bool $trimLeft = false): string
{
$location = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $location);
$location = rtrim($location, DIRECTORY_SEPARATOR);

View File

@@ -15,9 +15,9 @@ namespace PhpSpec\CodeGenerator\Writer;
interface CodeWriter
{
public function insertMethodFirstInClass(string $class, string $method) : string;
public function insertMethodFirstInClass(string $class, string $method): string;
public function insertMethodLastInClass(string $class, string $method) : string;
public function insertMethodLastInClass(string $class, string $method): string;
public function insertAfterMethod(string $class, string $methodName, string $method) : string;
public function insertAfterMethod(string $class, string $methodName, string $method): string;
}

View File

@@ -30,7 +30,7 @@ final class TokenizedCodeWriter implements CodeWriter
$this->analyser = $analyser;
}
public function insertMethodFirstInClass(string $class, string $method) : string
public function insertMethodFirstInClass(string $class, string $method): string
{
if (!$this->analyser->classHasMethods($class)) {
return $this->writeAtEndOfClass($class, $method);
@@ -41,7 +41,7 @@ final class TokenizedCodeWriter implements CodeWriter
return $this->insertStringBeforeLine($class, $method, $line);
}
public function insertMethodLastInClass(string $class, string $method) : string
public function insertMethodLastInClass(string $class, string $method): string
{
if ($this->analyser->classHasMethods($class)) {
$line = $this->analyser->getEndLineOfLastMethod($class);
@@ -51,14 +51,14 @@ final class TokenizedCodeWriter implements CodeWriter
return $this->writeAtEndOfClass($class, $method);
}
public function insertAfterMethod(string $class, string $methodName, string $method) : string
public function insertAfterMethod(string $class, string $methodName, string $method): string
{
$line = $this->analyser->getEndLineOfNamedMethod($class, $methodName);
return $this->insertStringAfterLine($class, $method, $line);
}
private function insertStringAfterLine(string $target, string $toInsert, int $line, bool $leadingNewline = true) : string
private function insertStringAfterLine(string $target, string $toInsert, int $line, bool $leadingNewline = true): string
{
$lines = explode("\n", $target);
$lastLines = \array_slice($lines, $line);
@@ -72,7 +72,7 @@ final class TokenizedCodeWriter implements CodeWriter
return implode("\n", $lines);
}
private function insertStringBeforeLine(string $target, string $toInsert, int $line) : string
private function insertStringBeforeLine(string $target, string $toInsert, int $line): string
{
$line--;
$lines = explode("\n", $target);
@@ -83,7 +83,7 @@ final class TokenizedCodeWriter implements CodeWriter
return implode("\n", $lines);
}
private function writeAtEndOfClass(string $class, string $method, bool $prependNewLine = false) : string
private function writeAtEndOfClass(string $class, string $method, bool $prependNewLine = false): string
{
$tokens = token_get_all($class);
$searching = false;
@@ -126,7 +126,7 @@ final class TokenizedCodeWriter implements CodeWriter
/**
* @param $token
*/
private function isWritePoint($token) : bool
private function isWritePoint($token): bool
{
return \is_array($token) && ($token[1] === "\n" || $token[0] === T_COMMENT);
}

View File

@@ -13,6 +13,8 @@
namespace PhpSpec\Config;
use Symfony\Component\Console\Output\OutputInterface;
class OptionsConfig
{
/**
@@ -34,30 +36,39 @@ class OptionsConfig
* @var bool
*/
private $fakingEnabled;
/**
* @var string|bool
*/
private $bootstrapPath;
/**
* @var string
*/
private $isVerbose;
/**
* @param bool $stopOnFailureEnabled
* @param bool $codeGenerationEnabled
* @param bool $reRunEnabled
* @param bool $fakingEnabled
* @param string|bool $bootstrapPath
* @param bool $isVerbose
*/
public function __construct(
bool $stopOnFailureEnabled,
bool $codeGenerationEnabled,
bool $reRunEnabled,
bool $fakingEnabled,
$bootstrapPath
$bootstrapPath,
$isVerbose
) {
$this->stopOnFailureEnabled = $stopOnFailureEnabled;
$this->codeGenerationEnabled = $codeGenerationEnabled;
$this->reRunEnabled = $reRunEnabled;
$this->fakingEnabled = $fakingEnabled;
$this->bootstrapPath = $bootstrapPath;
$this->isVerbose = $isVerbose;
}
/**
@@ -76,12 +87,12 @@ class OptionsConfig
return $this->codeGenerationEnabled;
}
public function isReRunEnabled()
public function isReRunEnabled(): bool
{
return $this->reRunEnabled;
}
public function isFakingEnabled()
public function isFakingEnabled(): bool
{
return $this->fakingEnabled;
}
@@ -90,4 +101,9 @@ class OptionsConfig
{
return $this->bootstrapPath;
}
public function isVerbose(): bool
{
return $this->isVerbose;
}
}

View File

@@ -222,7 +222,7 @@ final class Application extends BaseApplication
return $config;
}
private function extractConfigFromFirstParsablePath(array $paths) : array
private function extractConfigFromFirstParsablePath(array $paths): array
{
foreach ($paths as $path) {
if (!file_exists($path)) {
@@ -242,7 +242,7 @@ final class Application extends BaseApplication
*
* @return array
*/
private function parseConfigFromExistingPath(string $path) : array
private function parseConfigFromExistingPath(string $path): array
{
if (!file_exists($path)) {
return array();
@@ -251,7 +251,7 @@ final class Application extends BaseApplication
return Yaml::parse(file_get_contents($path)) ?: [];
}
private function addPathsToEachSuiteConfig(string $configDir, array $config) : array
private function addPathsToEachSuiteConfig(string $configDir, array $config): array
{
if (isset($config['suites']) && \is_array($config['suites'])) {
foreach ($config['suites'] as $suiteKey => $suiteConfig) {

View File

@@ -72,7 +72,7 @@ final class PresenterAssembler
}, ['formatter.presenter.differ.engines']);
$container->define('formatter.presenter.differ.engines.array', function () {
return new ArrayEngine();
return new ArrayEngine(new Exporter());
}, ['formatter.presenter.differ.engines']);
$container->define('formatter.presenter.differ.engines.object', function (IndexedServiceContainer $c) {

View File

@@ -27,7 +27,7 @@ use Symfony\Component\Console\Question\Question;
*/
final class DescribeCommand extends Command
{
protected function configure()
protected function configure(): void
{
$this
->setName('describe')
@@ -93,7 +93,7 @@ EOF
/**
* Make path safe to echo to the terminal (to get around symfony/console issue #24652)
*/
private function escapePathForTerminal(string $path) : string
private function escapePathForTerminal(string $path): string
{
return str_replace('\\', '/', $path);
}

View File

@@ -74,17 +74,17 @@ class ConsoleIO implements IO
$this->prompter = $prompter;
}
public function isInteractive() : bool
public function isInteractive(): bool
{
return $this->input->isInteractive();
}
public function isDecorated() : bool
public function isDecorated(): bool
{
return $this->output->isDecorated();
}
public function isCodeGenerationEnabled() : bool
public function isCodeGenerationEnabled(): bool
{
if (!$this->isInteractive()) {
return false;
@@ -94,35 +94,36 @@ class ConsoleIO implements IO
&& !$this->input->getOption('no-code-generation');
}
public function isStopOnFailureEnabled() : bool
public function isStopOnFailureEnabled(): bool
{
return $this->config->isStopOnFailureEnabled()
|| $this->input->getOption('stop-on-failure');
}
public function isVerbose() : bool
public function isVerbose(): bool
{
return OutputInterface::VERBOSITY_VERBOSE <= $this->output->getVerbosity();
return $this->config->isVerbose()
|| OutputInterface::VERBOSITY_VERBOSE <= $this->output->getVerbosity();
}
public function getLastWrittenMessage() : string
public function getLastWrittenMessage(): string
{
return $this->lastMessage;
}
public function writeln(string $message = '', int $indent = null)
public function writeln(string $message = '', int $indent = null): void
{
$this->write($message, $indent, true);
}
public function writeTemp(string $message, int $indent = null)
public function writeTemp(string $message, int $indent = null): void
{
$this->write($message, $indent);
$this->hasTempString = true;
}
/**
* @return null|string
* @return ?string
*/
public function cutTemp()
{
@@ -136,12 +137,12 @@ class ConsoleIO implements IO
return $message;
}
public function freezeTemp()
public function freezeTemp(): void
{
$this->write($this->lastMessage);
}
public function write(string $message, int $indent = null, bool $newline = false)
public function write(string $message, int $indent = null, bool $newline = false): void
{
if ($this->hasTempString) {
$this->hasTempString = false;
@@ -158,12 +159,12 @@ class ConsoleIO implements IO
$this->lastMessage = $message.($newline ? "\n" : '');
}
public function overwriteln(string $message = '', int $indent = null)
public function overwriteln(string $message = '', int $indent = null): void
{
$this->overwrite($message, $indent, true);
}
public function overwrite(string $message, int $indent = null, bool $newline = false)
public function overwrite(string $message, int $indent = null, bool $newline = false): void
{
if (null !== $indent) {
$message = $this->indentText($message, $indent);
@@ -195,7 +196,7 @@ class ConsoleIO implements IO
$this->lastMessage = $message.($newline ? "\n" : '');
}
private function getCommonPrefix(string $stringA, string $stringB)
private function getCommonPrefix(string $stringA, string $stringB): string
{
for ($i = 0, $len = min(\strlen($stringA), \strlen($stringB)); $i<$len; $i++) {
if ($stringA[$i] != $stringB[$i]) {
@@ -212,7 +213,7 @@ class ConsoleIO implements IO
return $common;
}
public function askConfirmation(string $question, bool $default = true) : bool
public function askConfirmation(string $question, bool $default = true): bool
{
$lines = array();
$lines[] = '<question>'.str_repeat(' ', $this->getBlockWidth())."</question>";
@@ -227,7 +228,7 @@ class ConsoleIO implements IO
return $this->prompter->askConfirmation($formattedQuestion, $default);
}
private function indentText(string $text, int $indent) : string
private function indentText(string $text, int $indent): string
{
return implode("\n", array_map(
function ($line) use ($indent) {
@@ -237,20 +238,20 @@ class ConsoleIO implements IO
));
}
public function isRerunEnabled() : bool
public function isRerunEnabled(): bool
{
return !$this->input->getOption('no-rerun') && $this->config->isReRunEnabled();
}
public function isFakingEnabled() : bool
public function isFakingEnabled(): bool
{
return $this->input->getOption('fake') || $this->config->isFakingEnabled();
}
/**
* @return string|null
* @return ?string
*/
public function getBootstrapPath()
public function getBootstrapPath(): ?string
{
if ($path = $this->input->getOption('bootstrap')) {
return $path;
@@ -262,12 +263,12 @@ class ConsoleIO implements IO
return null;
}
public function setConsoleWidth(int $width)
public function setConsoleWidth(int $width): void
{
$this->consoleWidth = $width;
}
public function getBlockWidth() : int
public function getBlockWidth(): int
{
$width = self::COL_DEFAULT_WIDTH;
if ($this->consoleWidth && ($this->consoleWidth - 10) > self::COL_MIN_WIDTH) {
@@ -283,7 +284,7 @@ class ConsoleIO implements IO
* @param string $message
* @param int $indent
*/
public function writeBrokenCodeBlock(string $message, int $indent = 0)
public function writeBrokenCodeBlock(string $message, int $indent = 0): void
{
$message = wordwrap($message, $this->getBlockWidth() - ($indent * 2), "\n", true);

View File

@@ -55,7 +55,7 @@ final class ContainerAssembler
/**
* @param IndexedServiceContainer $container
*/
public function build(IndexedServiceContainer $container)
public function build(IndexedServiceContainer $container): void
{
$this->setupParameters($container);
$this->setupIO($container);
@@ -76,7 +76,7 @@ final class ContainerAssembler
$this->setupShutdown($container);
}
private function setupParameters(IndexedServiceContainer $container)
private function setupParameters(IndexedServiceContainer $container): void
{
$container->setParam(
'generator.private-constructor.message',
@@ -84,7 +84,7 @@ final class ContainerAssembler
);
}
private function setupIO(IndexedServiceContainer $container)
private function setupIO(IndexedServiceContainer $container): void
{
if (!$container->has('console.prompter')) {
$container->define('console.prompter', function ($c) {
@@ -104,7 +104,8 @@ final class ContainerAssembler
$c->getParam('code_generation', true),
$c->getParam('rerun', true),
$c->getParam('fake', false),
$c->getParam('bootstrap', false)
$c->getParam('bootstrap', false),
$c->getParam('verbose', false)
),
$c->get('console.prompter')
);
@@ -120,14 +121,14 @@ final class ContainerAssembler
});
}
private function setupResultConverter(IndexedServiceContainer $container)
private function setupResultConverter(IndexedServiceContainer $container): void
{
$container->define('console.result_converter', function () {
return new ResultConverter();
});
}
private function setupCommands(IndexedServiceContainer $container)
private function setupCommands(IndexedServiceContainer $container): void
{
$container->define('console.commands.run', function () {
return new Command\RunCommand();
@@ -141,7 +142,7 @@ final class ContainerAssembler
/**
* @param IndexedServiceContainer $container
*/
private function setupConsoleEventDispatcher(IndexedServiceContainer $container)
private function setupConsoleEventDispatcher(IndexedServiceContainer $container): void
{
$container->define('console_event_dispatcher', function (IndexedServiceContainer $c) {
$dispatcher = new EventDispatcher();
@@ -158,7 +159,7 @@ final class ContainerAssembler
/**
* @param IndexedServiceContainer $container
*/
private function setupEventDispatcher(IndexedServiceContainer $container)
private function setupEventDispatcher(IndexedServiceContainer $container): void
{
$container->define('event_dispatcher', function () {
return new EventDispatcher();
@@ -252,7 +253,7 @@ final class ContainerAssembler
/**
* @param IndexedServiceContainer $container
*/
private function setupGenerators(IndexedServiceContainer $container)
private function setupGenerators(IndexedServiceContainer $container): void
{
$container->define('code_generator', function (IndexedServiceContainer $c) {
$generator = new CodeGenerator\GeneratorManager();
@@ -388,7 +389,7 @@ final class ContainerAssembler
/**
* @param IndexedServiceContainer $container
*/
private function setupPresenter(IndexedServiceContainer $container)
private function setupPresenter(IndexedServiceContainer $container): void
{
$presenterAssembler = new PresenterAssembler();
$presenterAssembler->assemble($container);
@@ -397,7 +398,7 @@ final class ContainerAssembler
/**
* @param IndexedServiceContainer $container
*/
private function setupLocator(IndexedServiceContainer $container)
private function setupLocator(IndexedServiceContainer $container): void
{
$container->define('locator.resource_manager', function (IndexedServiceContainer $c) {
$manager = new Locator\PrioritizedResourceManager();
@@ -489,7 +490,7 @@ final class ContainerAssembler
/**
* @param IndexedServiceContainer $container
*/
private function setupLoader(IndexedServiceContainer $container)
private function setupLoader(IndexedServiceContainer $container): void
{
$container->define('loader.resource_loader', function (IndexedServiceContainer $c) {
return new Loader\ResourceLoader(
@@ -524,7 +525,7 @@ final class ContainerAssembler
*
* @throws \RuntimeException
*/
protected function setupFormatter(IndexedServiceContainer $container)
protected function setupFormatter(IndexedServiceContainer $container): void
{
$container->define(
'formatter.formatters.progress',
@@ -618,7 +619,7 @@ final class ContainerAssembler
/**
* @param IndexedServiceContainer $container
*/
private function setupRunner(IndexedServiceContainer $container)
private function setupRunner(IndexedServiceContainer $container): void
{
$container->define('runner.suite', function (IndexedServiceContainer $c) {
return new Runner\SuiteRunner(
@@ -700,7 +701,7 @@ final class ContainerAssembler
/**
* @param IndexedServiceContainer $container
*/
private function setupMatchers(IndexedServiceContainer $container)
private function setupMatchers(IndexedServiceContainer $container): void
{
$container->define('matchers.identity', function (IndexedServiceContainer $c) {
return new Matcher\IdentityMatcher($c->get('formatter.presenter'));
@@ -776,7 +777,7 @@ final class ContainerAssembler
/**
* @param IndexedServiceContainer $container
*/
private function setupRerunner(IndexedServiceContainer $container)
private function setupRerunner(IndexedServiceContainer $container): void
{
$container->define('process.rerunner', function (IndexedServiceContainer $c) {
return new ReRunner\OptionalReRunner(
@@ -820,7 +821,7 @@ final class ContainerAssembler
/**
* @param IndexedServiceContainer $container
*/
private function setupSubscribers(IndexedServiceContainer $container)
private function setupSubscribers(IndexedServiceContainer $container): void
{
$container->addConfigurator(function (IndexedServiceContainer $c) {
array_map(
@@ -833,7 +834,7 @@ final class ContainerAssembler
/**
* @param IndexedServiceContainer $container
*/
private function setupCurrentExample(IndexedServiceContainer $container)
private function setupCurrentExample(IndexedServiceContainer $container): void
{
$container->define('current_example', function () {
return new CurrentExampleTracker();
@@ -843,7 +844,7 @@ final class ContainerAssembler
/**
* @param IndexedServiceContainer $container
*/
private function setupShutdown(IndexedServiceContainer $container)
private function setupShutdown(IndexedServiceContainer $container): void
{
$container->define('process.shutdown', function () {
return new Shutdown();

View File

@@ -15,5 +15,5 @@ namespace PhpSpec\Console;
interface Prompter
{
public function askConfirmation(string $question, bool $default = true) : bool;
public function askConfirmation(string $question, bool $default = true): bool;
}

View File

@@ -48,7 +48,7 @@ final class Question implements Prompter
* @param boolean $default
* @return boolean
*/
public function askConfirmation(string $question, bool $default = true) : bool
public function askConfirmation(string $question, bool $default = true): bool
{
return (bool)$this->helper->ask($this->input, $this->output, new ConfirmationQuestion($question, $default));
}

View File

@@ -85,12 +85,12 @@ class SuiteEvent extends Event implements PhpSpecEvent
return $this->worthRerunning;
}
public function markAsWorthRerunning()
public function markAsWorthRerunning(): void
{
$this->worthRerunning = true;
}
public function markAsNotWorthRerunning()
public function markAsNotWorthRerunning(): void
{
$this->worthRerunning = false;
}

View File

@@ -36,7 +36,7 @@ class Exception extends \Exception
/**
* @param ReflectionFunctionAbstract $cause
*/
public function setCause(ReflectionFunctionAbstract $cause)
public function setCause(ReflectionFunctionAbstract $cause): void
{
$this->cause = $cause;
}

View File

@@ -30,7 +30,7 @@ class InvalidCollaboratorTypeException extends CollaboratorException
parent::__construct($message);
}
private function fetchFunctionIdentifier(\ReflectionFunctionAbstract $function)
private function fetchFunctionIdentifier(\ReflectionFunctionAbstract $function) : string
{
$functionIdentifier = $function->getName();
if ($function instanceof \ReflectionMethod) {

View File

@@ -51,7 +51,7 @@ abstract class ConsoleFormatter extends BasicFormatter implements FatalPresenter
/**
* @param ExampleEvent $event
*/
protected function printException(ExampleEvent $event)
protected function printException(ExampleEvent $event): void
{
if (null === $exception = $event->getException()) {
return;
@@ -74,7 +74,7 @@ abstract class ConsoleFormatter extends BasicFormatter implements FatalPresenter
* @param ExampleEvent $event
* @param string $type
*/
protected function printSpecificException(ExampleEvent $event, string $type)
protected function printSpecificException(ExampleEvent $event, string $type): void
{
$title = str_replace('\\', DIRECTORY_SEPARATOR, $event->getSpecification()->getTitle());
$message = $this->getPresenter()->presentException($event->getException(), $this->io->isVerbose());
@@ -94,7 +94,7 @@ abstract class ConsoleFormatter extends BasicFormatter implements FatalPresenter
$this->io->writeln();
}
public function displayFatal(CurrentExampleTracker $currentExample, $error)
public function displayFatal(CurrentExampleTracker $currentExample, $error): void
{
if (
(null !== $error && ($currentExample->getCurrentExample() || $error['type'] == E_ERROR)) ||

View File

@@ -92,7 +92,7 @@ final class DotFormatter extends ConsoleFormatter
$this->outputSuiteSummary($event);
}
private function outputExceptions()
private function outputExceptions(): void
{
$stats = $this->getStatisticsCollector();
$notPassed = array_filter(array(
@@ -107,7 +107,7 @@ final class DotFormatter extends ConsoleFormatter
}
}
private function outputSuiteSummary(SuiteEvent $event)
private function outputSuiteSummary(SuiteEvent $event): void
{
$this->outputTotalSpecCount();
$this->outputTotalExamplesCount();
@@ -121,19 +121,19 @@ final class DotFormatter extends ConsoleFormatter
return $count !== 1 ? 's' : '';
}
private function outputTotalSpecCount()
private function outputTotalSpecCount(): void
{
$count = $this->getStatisticsCollector()->getTotalSpecs();
$this->getIO()->writeln(sprintf("%d spec%s", $count, $this->plural($count)));
}
private function outputTotalExamplesCount()
private function outputTotalExamplesCount(): void
{
$count = $this->getStatisticsCollector()->getEventsCount();
$this->getIO()->write(sprintf("%d example%s ", $count, $this->plural($count)));
}
private function outputSpecificExamplesCount()
private function outputSpecificExamplesCount(): void
{
$typesWithEvents = array_filter($this->getStatisticsCollector()->getCountsHash());

View File

@@ -17,5 +17,5 @@ use PhpSpec\Message\CurrentExampleTracker;
interface FatalPresenter
{
public function displayFatal(CurrentExampleTracker $currentExample, $error);
public function displayFatal(CurrentExampleTracker $currentExample, $error): void;
}

View File

@@ -20,7 +20,7 @@ final class HtmlIO implements IO
/**
* @param $message
*/
public function write($message)
public function write(string $message): void
{
echo $message;
}

View File

@@ -51,7 +51,7 @@ class ReportFailedItem
/**
* @param int $index
*/
public function write(int $index)
public function write(int $index): void
{
$code = $this->presenter->presentException($this->event->getException(), true);
$this->template->render(
@@ -70,7 +70,7 @@ class ReportFailedItem
/**
* @return string
*/
private function formatBacktrace(): string
private function formatBacktrace() : string
{
$backtrace = '';
foreach ($this->event->getBacktrace() as $step) {

View File

@@ -16,7 +16,7 @@ namespace PhpSpec\Formatter\Html;
interface ReportItem
{
/**
* @return mixed
* @return void
*/
public function write();
public function write(): void;
}

View File

@@ -60,7 +60,7 @@ class ReportItemFactory
*
* @throws InvalidExampleResultException
*/
private function invalidResultException(int $result)
private function invalidResultException(int $result): void
{
throw new InvalidExampleResultException(
"Unrecognised example result $result"

View File

@@ -37,10 +37,7 @@ class ReportPassedItem
$this->event = $event;
}
/**
*
*/
public function write()
public function write(): void
{
$this->template->render(Template::DIR.'/Template/ReportPass.html', array(
'title' => $this->event->getTitle()

View File

@@ -41,10 +41,7 @@ class ReportPendingItem
$this->event = $event;
}
/**
*
*/
public function write()
public function write(): void
{
$this->template->render(Template::DIR.'/Template/ReportPending.html', array(
'title' => $this->event->getTitle(),

View File

@@ -37,10 +37,7 @@ class ReportSkippedItem
$this->event = $event;
}
/**
*
*/
public function write()
public function write(): void
{
$this->template->render(Template::DIR.'/Template/ReportSkipped.html', array(
'title' => htmlentities(strip_tags($this->event->getTitle())),

View File

@@ -37,7 +37,7 @@ final class Template implements TemplateInterface
* @param string $text
* @param array $templateVars
*/
public function render(string $text, array $templateVars = array())
public function render(string $text, array $templateVars = array()): void
{
if (file_exists($text)) {
$text = file_get_contents($text);

View File

@@ -64,7 +64,7 @@ final class JUnitFormatter extends BasicFormatter
*
* @param array $testCaseNodes
*/
public function setTestCaseNodes(array $testCaseNodes)
public function setTestCaseNodes(array $testCaseNodes): void
{
$this->testCaseNodes = $testCaseNodes;
}
@@ -210,7 +210,7 @@ final class JUnitFormatter extends BasicFormatter
/**
* Initialize test case nodes and example status counts
*/
protected function initTestCaseNodes()
protected function initTestCaseNodes(): void
{
$this->testCaseNodes = array();
$this->exampleStatusCounts = array(

View File

@@ -13,31 +13,44 @@
namespace PhpSpec\Formatter\Presenter\Differ;
use SebastianBergmann\Exporter\Exporter;
final class ArrayEngine extends StringEngine
{
public function supports($expected, $actual) : bool
private const PAD_SIZE = 2;
private const PAD_STRING = ' ';
private $exporter;
public function __construct(Exporter $exporter)
{
$this->exporter = $exporter;
}
public function supports($expected, $actual): bool
{
return \is_array($expected) && \is_array($actual);
}
public function compare($expected, $actual) : string
public function compare($expected, $actual): string
{
$expectedString = $this->convertArrayToString($expected);
$actualString = $this->convertArrayToString($actual);
$actualString = $this->convertArrayToString($actual);
return parent::compare($expectedString, $actualString);
}
private function convertArrayToString(array $a, $pad = 2)
private function convertArrayToString(array $a, $pad = 1): string
{
$str = str_pad('', $pad, ' ').'[';
$str = str_pad('', $pad * self::PAD_SIZE, self::PAD_STRING) . '[';
foreach ($a as $key => $val) {
switch ($type = strtolower(\gettype($val))) {
case 'array':
$line = sprintf(
'%s => %s,',
$key,
ltrim($this->convertArrayToString($val, $pad+2))
ltrim($this->convertArrayToString($val, $pad + 1))
);
break;
case 'null':
@@ -47,11 +60,12 @@ final class ArrayEngine extends StringEngine
$line = sprintf('%s => %s,', $key, $val ? 'true' : 'false');
break;
case 'object':
$exporterPadSize = 4;
$padCorrection = self::PAD_SIZE / $exporterPadSize;
$line = sprintf(
'%s => %s#%s,',
'%s => %s,',
$key,
\get_class($val),
spl_object_hash($val)
$this->exporter->export($val, ($pad + 1) * $padCorrection)
);
break;
case 'string':
@@ -65,9 +79,9 @@ final class ArrayEngine extends StringEngine
default:
$line = sprintf('%s => %s:%s,', $key, $type, $val);
}
$str .= PHP_EOL.str_pad('', $pad+2, ' ').$line;
$str .= PHP_EOL . str_pad('', ($pad + 1) * self::PAD_SIZE, self::PAD_STRING) . $line;
}
$str .= PHP_EOL.str_pad('', $pad, ' ').']';
$str .= PHP_EOL . str_pad('', $pad * self::PAD_SIZE, self::PAD_STRING) . ']';
return $str;
}

View File

@@ -22,7 +22,7 @@ class Differ
$this->engines = $engines;
}
public function addEngine(DifferEngine $engine)
public function addEngine(DifferEngine $engine): void
{
$this->engines[] = $engine;
}

View File

@@ -109,7 +109,7 @@ final class PrettyFormatter extends ConsoleFormatter
}
}
protected function printException(ExampleEvent $event, $depth = null)
protected function printException(ExampleEvent $event, $depth = null): void
{
$io = $this->getIO();

View File

@@ -146,7 +146,7 @@ final class ProgressFormatter extends ConsoleFormatter
* @param array $progress
* @param int $total
*/
private function updateProgressBar(ConsoleIO $io, array $progress, int $total)
private function updateProgressBar(ConsoleIO $io, array $progress, int $total): void
{
if ($io->isDecorated()) {
$progressBar = implode('', $progress);
@@ -157,7 +157,7 @@ final class ProgressFormatter extends ConsoleFormatter
}
}
private function drawStats()
private function drawStats(): void
{
$io = $this->getIO();
$stats = $this->getStatisticsCollector();

View File

@@ -19,5 +19,5 @@ interface Template
* @param string $text
* @param array $templateVars
*/
public function render(string $text, array $templateVars = array());
public function render(string $text, array $templateVars = array()): void;
}

View File

@@ -15,7 +15,7 @@ namespace PhpSpec\IO;
interface IO
{
public function write(string $message);
public function write(string $message): void;
public function isVerbose() : bool;
public function isVerbose(): bool;
}

View File

@@ -22,7 +22,7 @@ final class BootstrapListener implements EventSubscriberInterface
return array('beforeSuite' => array('beforeSuite', 1100));
}
public function beforeSuite()
public function beforeSuite(): void
{
if ($bootstrap = $this->io->getBootstrapPath()) {
if (!is_file($bootstrap)) {

View File

@@ -90,7 +90,7 @@ final class CollaboratorMethodNotFoundListener implements EventSubscriberInterfa
/**
* @param ExampleEvent $event
*/
public function afterExample(ExampleEvent $event)
public function afterExample(ExampleEvent $event): void
{
if (!$exception = $this->getMethodNotFoundException($event)) {
return;
@@ -135,7 +135,7 @@ final class CollaboratorMethodNotFoundListener implements EventSubscriberInterfa
/**
* @param SuiteEvent $event
*/
public function afterSuite(SuiteEvent $event)
public function afterSuite(SuiteEvent $event): void
{
foreach ($this->interfaces as $interface => $methods) {
try {
@@ -195,14 +195,14 @@ final class CollaboratorMethodNotFoundListener implements EventSubscriberInterfa
}
}
private function checkIfMethodNameAllowed($methodName)
private function checkIfMethodNameAllowed($methodName): void
{
if (!$this->nameChecker->isNameValid($methodName)) {
$this->wrongMethodNames[] = $methodName;
}
}
private function writeErrorMessage()
private function writeErrorMessage(): void
{
foreach ($this->wrongMethodNames as $methodName) {
$message = sprintf("I cannot generate the method '%s' for you because it is a reserved keyword", $methodName);

View File

@@ -70,7 +70,7 @@ final class CollaboratorNotFoundListener implements EventSubscriberInterface
/**
* @param ExampleEvent $event
*/
public function afterExample(ExampleEvent $event)
public function afterExample(ExampleEvent $event): void
{
if (($exception = $event->getException()) &&
($exception instanceof CollaboratorNotFoundException)) {
@@ -81,7 +81,7 @@ final class CollaboratorNotFoundListener implements EventSubscriberInterface
/**
* @param SuiteEvent $event
*/
public function afterSuite(SuiteEvent $event)
public function afterSuite(SuiteEvent $event): void
{
if (!$this->io->isCodeGenerationEnabled()) {
return;

View File

@@ -39,17 +39,17 @@ final class CurrentExampleListener implements EventSubscriberInterface {
$this->currentExample = $currentExample;
}
public function beforeCurrentExample(ExampleEvent $event)
public function beforeCurrentExample(ExampleEvent $event): void
{
$this->currentExample->setCurrentExample($event->getTitle());
}
public function afterCurrentExample()
public function afterCurrentExample(): void
{
$this->currentExample->setCurrentExample(null);
}
public function afterSuiteEvent(SuiteEvent $event)
public function afterSuiteEvent(SuiteEvent $event): void
{
$this->currentExample->setCurrentExample('Exited with code: ' . $event->getResult());
}

View File

@@ -60,7 +60,7 @@ final class MethodNotFoundListener implements EventSubscriberInterface
);
}
public function afterExample(ExampleEvent $event)
public function afterExample(ExampleEvent $event): void
{
if (null === $exception = $event->getException()) {
return;
@@ -76,7 +76,7 @@ final class MethodNotFoundListener implements EventSubscriberInterface
$this->checkIfMethodNameAllowed($methodName);
}
public function afterSuite(SuiteEvent $event)
public function afterSuite(SuiteEvent $event): void
{
if (!$this->io->isCodeGenerationEnabled()) {
return;
@@ -112,14 +112,14 @@ final class MethodNotFoundListener implements EventSubscriberInterface
}
}
private function checkIfMethodNameAllowed($methodName)
private function checkIfMethodNameAllowed($methodName): void
{
if (!$this->nameChecker->isNameValid($methodName)) {
$this->wrongMethodNames[] = $methodName;
}
}
private function writeWrongMethodNameMessage()
private function writeWrongMethodNameMessage(): void
{
foreach ($this->wrongMethodNames as $methodName) {
$message = sprintf("I cannot generate the method '%s' for you because it is a reserved keyword", $methodName);

View File

@@ -82,12 +82,12 @@ final class MethodReturnedNullListener implements EventSubscriberInterface
);
}
public function afterMethodCall(MethodCallEvent $methodCallEvent)
public function afterMethodCall(MethodCallEvent $methodCallEvent): void
{
$this->lastMethodCallEvent = $methodCallEvent;
}
public function afterExample(ExampleEvent $exampleEvent)
public function afterExample(ExampleEvent $exampleEvent): void
{
$exception = $exampleEvent->getException();
@@ -130,7 +130,7 @@ final class MethodReturnedNullListener implements EventSubscriberInterface
$this->nullMethods[$key]['expected'][] = $exception->getExpected();
}
public function afterSuite(SuiteEvent $event)
public function afterSuite(SuiteEvent $event): void
{
if (!$this->io->isCodeGenerationEnabled()) {
return;

View File

@@ -43,7 +43,7 @@ final class NamedConstructorNotFoundListener implements EventSubscriberInterface
);
}
public function afterExample(ExampleEvent $event)
public function afterExample(ExampleEvent $event): void
{
if (null === $exception = $event->getException()) {
return;
@@ -57,7 +57,7 @@ final class NamedConstructorNotFoundListener implements EventSubscriberInterface
$this->methods[$className .'::'.$exception->getMethodName()] = $exception->getArguments();
}
public function afterSuite(SuiteEvent $event)
public function afterSuite(SuiteEvent $event): void
{
if (!$this->io->isCodeGenerationEnabled()) {
return;

View File

@@ -54,7 +54,7 @@ final class RerunListener implements EventSubscriberInterface
/**
* @param SuiteEvent $suiteEvent
*/
public function beforeSuite(SuiteEvent $suiteEvent)
public function beforeSuite(SuiteEvent $suiteEvent): void
{
$this->suitePrerequisites->guardPrerequisites();
}
@@ -62,7 +62,7 @@ final class RerunListener implements EventSubscriberInterface
/**
* @param SuiteEvent $suiteEvent
*/
public function afterSuite(SuiteEvent $suiteEvent)
public function afterSuite(SuiteEvent $suiteEvent): void
{
if ($suiteEvent->isWorthRerunning()) {
$this->reRunner->reRunSuite();

View File

@@ -40,12 +40,12 @@ class StatisticsCollector implements EventSubscriberInterface
);
}
public function afterSpecification(SpecificationEvent $event)
public function afterSpecification(SpecificationEvent $event): void
{
$this->totalSpecs++;
}
public function afterExample(ExampleEvent $event)
public function afterExample(ExampleEvent $event): void
{
$this->globalResult = max($this->globalResult, $event->getResult());
@@ -68,17 +68,17 @@ class StatisticsCollector implements EventSubscriberInterface
}
}
public function beforeSuite(SuiteEvent $suiteEvent)
public function beforeSuite(SuiteEvent $suiteEvent): void
{
$this->totalSpecsCount = \count($suiteEvent->getSuite()->getSpecifications());
}
public function getGlobalResult()
public function getGlobalResult() : int
{
return $this->globalResult;
}
public function getAllEvents()
public function getAllEvents() : array
{
return array_merge(
$this->passedEvents,
@@ -89,32 +89,32 @@ class StatisticsCollector implements EventSubscriberInterface
);
}
public function getPassedEvents()
public function getPassedEvents() : array
{
return $this->passedEvents;
}
public function getPendingEvents()
public function getPendingEvents() : array
{
return $this->pendingEvents;
}
public function getSkippedEvents()
public function getSkippedEvents() : array
{
return $this->skippedEvents;
}
public function getFailedEvents()
public function getFailedEvents() : array
{
return $this->failedEvents;
}
public function getBrokenEvents()
public function getBrokenEvents() : array
{
return $this->brokenEvents;
}
public function getCountsHash()
public function getCountsHash() : array
{
return array(
'passed' => \count($this->getPassedEvents()),
@@ -125,17 +125,17 @@ class StatisticsCollector implements EventSubscriberInterface
);
}
public function getTotalSpecs()
public function getTotalSpecs() : int
{
return $this->totalSpecs;
}
public function getEventsCount()
public function getEventsCount() : int
{
return \count($this->getAllEvents());
return array_sum($this->getCountsHash());
}
public function getTotalSpecsCount()
public function getTotalSpecsCount() : int
{
return $this->totalSpecsCount;
}

View File

@@ -48,7 +48,7 @@ final class StopOnFailureListener implements EventSubscriberInterface
*
* @throws \PhpSpec\Exception\Example\StopOnFailureException
*/
public function afterExample(ExampleEvent $event)
public function afterExample(ExampleEvent $event): void
{
if (!$this->io->isStopOnFailureEnabled()) {
return;

Some files were not shown because too many files have changed in this diff Show More