这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"psr/container": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^8.4",
"zalas/phpunit-globals": "^1.1"
"phpunit/phpunit": "^8.4 || ^9.1",
"zalas/phpunit-globals": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
8 changes: 4 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.0/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.1/phpunit.xsd"
bootstrap="vendor/autoload.php"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
Expand All @@ -25,9 +25,9 @@
</whitelist>
</filter>

<listeners>
<listener class="Zalas\PHPUnit\Globals\AnnotationListener" />
</listeners>
<extensions>
<extension class="Zalas\PHPUnit\Globals\AnnotationExtension"/>
</extensions>

<logging>
<log type="coverage-html" target="build/coverage" lowUpperBound="50" highLowerBound="95"/>
Expand Down
3 changes: 3 additions & 0 deletions tests/Cli/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
use Zalas\Toolbox\Cli\Command\InstallCommand;
use Zalas\Toolbox\Cli\Command\ListCommand;
use Zalas\Toolbox\Cli\ServiceContainer;
use Zalas\Toolbox\Tests\Prophecy\Prophecy;

class ApplicationTest extends TestCase
{
use Prophecy;

private const VERSION = 'test';

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/Cli/Command/InstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
use Prophecy\Prophecy\ObjectProphecy;
use Zalas\Toolbox\Cli\Command\InstallCommand;
use Zalas\Toolbox\Runner\Runner;
use Zalas\Toolbox\Tests\Prophecy\Prophecy;
use Zalas\Toolbox\Tool\Command;
use Zalas\Toolbox\Tool\Filter;
use Zalas\Toolbox\UseCase\InstallTools;

class InstallCommandTest extends ToolboxCommandTestCase
{
use Prophecy;

protected const CLI_COMMAND_NAME = InstallCommand::NAME;

/**
Expand Down
7 changes: 5 additions & 2 deletions tests/Cli/Command/ListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Zalas\Toolbox\Cli\Command\ListCommand;
use Zalas\Toolbox\Tests\Prophecy\Prophecy;
use Zalas\Toolbox\Tool\Collection;
use Zalas\Toolbox\Tool\Filter;
use Zalas\Toolbox\Tool\Tool;
use Zalas\Toolbox\UseCase\ListTools;

class ListCommandTest extends ToolboxCommandTestCase
{
use Prophecy;

protected const CLI_COMMAND_NAME = ListCommand::NAME;

/**
Expand All @@ -35,8 +38,8 @@ public function test_it_runs_the_list_tools_use_case()
$tester = $this->executeCliCommand();

$this->assertSame(0, $tester->getStatusCode());
$this->assertRegExp('#Available tools#i', $tester->getDisplay());
$this->assertRegExp('#Behat.*?Tests business expectations.*?http://behat.org#smi', $tester->getDisplay());
$this->assertMatchesRegularExpression('#Available tools#i', $tester->getDisplay());
$this->assertMatchesRegularExpression('#Behat.*?Tests business expectations.*?http://behat.org#smi', $tester->getDisplay());
}

public function test_it_filters_by_tags()
Expand Down
3 changes: 3 additions & 0 deletions tests/Cli/Command/TestCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
use Prophecy\Prophecy\ObjectProphecy;
use Zalas\Toolbox\Cli\Command\TestCommand;
use Zalas\Toolbox\Runner\Runner;
use Zalas\Toolbox\Tests\Prophecy\Prophecy;
use Zalas\Toolbox\Tool\Command;
use Zalas\Toolbox\Tool\Filter;
use Zalas\Toolbox\UseCase\TestTools;

class TestCommandTest extends ToolboxCommandTestCase
{
use Prophecy;

protected const CLI_COMMAND_NAME = TestCommand::NAME;

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/Cli/Runner/DryRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
use Symfony\Component\Console\Output\OutputInterface;
use Zalas\Toolbox\Cli\Runner\DryRunner;
use Zalas\Toolbox\Runner\Runner;
use Zalas\Toolbox\Tests\Prophecy\Prophecy;
use Zalas\Toolbox\Tool\Command;

class DryRunnerTest extends TestCase
{
use Prophecy;

/**
* @var DryRunner
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/Cli/ServiceContainer/LazyRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
use Zalas\Toolbox\Cli\ServiceContainer\LazyRunner;
use Zalas\Toolbox\Cli\ServiceContainer\RunnerFactory;
use Zalas\Toolbox\Runner\Runner;
use Zalas\Toolbox\Tests\Prophecy\Prophecy;
use Zalas\Toolbox\Tool\Command;

class LazyRunnerTest extends TestCase
{
use Prophecy;

/**
* @var LazyRunner
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/Cli/ServiceContainer/RunnerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
use Zalas\Toolbox\Cli\ServiceContainer\RunnerFactory;
use Zalas\Toolbox\Runner\ParametrisedRunner;
use Zalas\Toolbox\Runner\PassthruRunner;
use Zalas\Toolbox\Tests\Prophecy\Prophecy;
use Zalas\Toolbox\Tool\Command;

class RunnerFactoryTest extends TestCase
{
use Prophecy;

/**
* @var ContainerInterface|ObjectProphecy
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/Cli/ServiceContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
use Zalas\Toolbox\Cli\ServiceContainer;
use Zalas\Toolbox\Cli\ServiceContainer\LazyRunner;
use Zalas\Toolbox\Runner\Runner;
use Zalas\Toolbox\Tests\Prophecy\Prophecy;

class ServiceContainerTest extends TestCase
{
use Prophecy;

/**
* @var ServiceContainer
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/Json/Factory/BoxBuildCommandFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function test_it_creates_a_command()
]);

$this->assertInstanceOf(BoxBuildCommand::class, $command);
$this->assertRegExp('#git checkout '.self::VERSION.'#', (string) $command);
$this->assertMatchesRegularExpression('#git checkout '.self::VERSION.'#', (string) $command);
}

public function test_the_version_is_not_required()
Expand Down
2 changes: 1 addition & 1 deletion tests/Json/Factory/ComposerInstallCommandFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function test_it_creates_a_command()
]);

$this->assertInstanceOf(ComposerInstallCommand::class, $command);
$this->assertRegExp('#git checkout '.self::VERSION.'#', (string) $command);
$this->assertMatchesRegularExpression('#git checkout '.self::VERSION.'#', (string) $command);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Json/JsonToolsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function test_it_is_a_tools_repository()
public function test_it_throws_an_exception_if_resource_is_missing()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/Could not read the file/');
$this->expectExceptionMessageMatches('/Could not read the file/');

$tools = new JsonTools($this->locator(['/foo/tools.json']));
$tools->all($this->filter());
Expand All @@ -28,7 +28,7 @@ public function test_it_throws_an_exception_if_resource_is_missing()
public function test_it_throws_an_exception_if_resource_contains_invalid_json()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessageRegExp('/Failed to parse json/');
$this->expectExceptionMessageMatches('/Failed to parse json/');

$tools = new JsonTools($this->locator([__DIR__.'/../resources/invalid.json']));
$tools->all($this->filter());
Expand All @@ -37,7 +37,7 @@ public function test_it_throws_an_exception_if_resource_contains_invalid_json()
public function test_it_throws_an_exception_if_tools_are_not_present_in_the_resource()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessageRegExp('/Failed to find any tools/');
$this->expectExceptionMessageMatches('/Failed to find any tools/');

$tools = new JsonTools($this->locator([__DIR__.'/../resources/no-tools.json']));
$tools->all($this->filter());
Expand All @@ -46,7 +46,7 @@ public function test_it_throws_an_exception_if_tools_are_not_present_in_the_reso
public function test_it_throws_an_exception_if_tools_is_not_a_collection()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessageRegExp('/Failed to find any tools/');
$this->expectExceptionMessageMatches('/Failed to find any tools/');

$tools = new JsonTools($this->locator([__DIR__.'/../resources/invalid-tools.json']));
$tools->all($this->filter());
Expand Down
111 changes: 111 additions & 0 deletions tests/Prophecy/Prophecy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php declare(strict_types=1);

namespace Zalas\Toolbox\Tests\Prophecy;

use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\TestCase;
use Prophecy\Exception\Doubler\DoubleException;
use Prophecy\Exception\Doubler\InterfaceNotFoundException;
use Prophecy\Exception\Prediction\PredictionException;
use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy;
use Prophecy\Prophet;

/**
* @mixin TestCase
* Copied from https://github.com/phpspec/prophecy-phpunit/blob/master/src/ProphecyTrait.php
*/
trait Prophecy
{
/**
* @var Prophet|null
*
* @internal
*/
private $prophet;

/**
* @var bool
*
* @internal
*/
private $prophecyAssertionsCounted = false;

/**
* @throws DoubleException
* @throws InterfaceNotFoundException
*
* @psalm-param class-string|null $type
*/
protected function prophesize(?string $classOrInterface = null): ObjectProphecy
{
if (\is_string($classOrInterface)) {
\assert($this instanceof TestCase);
$this->recordDoubledType($classOrInterface);
}

return $this->getProphet()->prophesize($classOrInterface);
}

/**
* @postCondition
*/
protected function verifyProphecyDoubles(): void
{
if (null === $this->prophet) {
return;
}

try {
$this->prophet->checkPredictions();
} catch (PredictionException $e) {
throw new AssertionFailedError($e->getMessage());
} finally {
$this->countProphecyAssertions();
}
}

/**
* @after
*/
protected function tearDownProphecy(): void
{
if (null !== $this->prophet && !$this->prophecyAssertionsCounted) {
// Some Prophecy assertions may have been done in tests themselves even when a failure happened before checking mock objects.
$this->countProphecyAssertions();
}

$this->prophet = null;
}

/**
* @internal
*/
private function countProphecyAssertions(): void
{
\assert($this instanceof TestCase);
$this->prophecyAssertionsCounted = true;

foreach ($this->prophet->getProphecies() as $objectProphecy) {
foreach ($objectProphecy->getMethodProphecies() as $methodProphecies) {
foreach ($methodProphecies as $methodProphecy) {
\assert($methodProphecy instanceof MethodProphecy);

$this->addToAssertionCount(\count($methodProphecy->getCheckedPredictions()));
}
}
}
}

/**
* @internal
*/
private function getProphet(): Prophet
{
if (null === $this->prophet) {
$this->prophet = new Prophet;
}

return $this->prophet;
}
}
3 changes: 3 additions & 0 deletions tests/Runner/ParametrisedRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
use Prophecy\Prophecy\ObjectProphecy;
use Zalas\Toolbox\Runner\ParametrisedRunner;
use Zalas\Toolbox\Runner\Runner;
use Zalas\Toolbox\Tests\Prophecy\Prophecy;
use Zalas\Toolbox\Tool\Command;

class ParametrisedRunnerTest extends TestCase
{
use Prophecy;

/**
* @var ParametrisedRunner
*/
Expand Down
18 changes: 9 additions & 9 deletions tests/Tool/Command/BoxBuildCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function test_it_is_a_command()
self::TMP_DIR,
self::VERSION
);

$this->assertInstanceOf(Command::class, $command);
}

Expand All @@ -40,12 +40,12 @@ public function test_it_generates_the_installation_command()
self::TMP_DIR,
self::VERSION
);
$this->assertRegExp('#git clone '.self::REPOSITORY.'#', (string) $command);
$this->assertRegExp('#cd /tools/behat#', (string) $command);
$this->assertRegExp('#git checkout '.self::VERSION.'#', (string) $command);
$this->assertRegExp('#composer install --no-dev --no-suggest --prefer-dist -n#', (string) $command);
$this->assertRegExp('#box-legacy build#', (string) $command);

$this->assertMatchesRegularExpression('#git clone '.self::REPOSITORY.'#', (string) $command);
$this->assertMatchesRegularExpression('#cd /tools/behat#', (string) $command);
$this->assertMatchesRegularExpression('#git checkout '.self::VERSION.'#', (string) $command);
$this->assertMatchesRegularExpression('#composer install --no-dev --no-suggest --prefer-dist -n#', (string) $command);
$this->assertMatchesRegularExpression('#box-legacy build#', (string) $command);
}

public function test_it_tries_to_guess_version_number_if_not_given_one()
Expand All @@ -57,7 +57,7 @@ public function test_it_tries_to_guess_version_number_if_not_given_one()
self::TMP_DIR
);

$this->assertRegExp('#git checkout \$\(git describe --tags .*?\)#', (string) $command);
$this->assertMatchesRegularExpression('#git checkout \$\(git describe --tags .*?\)#', (string) $command);
}

public function test_it_uses_a_generic_directory_if_name_cannot_be_guessed_from_the_repository()
Expand All @@ -69,6 +69,6 @@ public function test_it_uses_a_generic_directory_if_name_cannot_be_guessed_from_
self::TMP_DIR
);

$this->assertRegExp('#cd /tools/tmp#', (string) $command);
$this->assertMatchesRegularExpression('#cd /tools/tmp#', (string) $command);
}
}
Loading