Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pestphp/pest into patch-1
Browse files Browse the repository at this point in the history
# Conflicts:
#	tests/.snapshots/success.txt
  • Loading branch information
Gummibeer committed Jun 21, 2020
2 parents 74c1480 + 15edde8 commit a47ad6a
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 21 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [v0.2.2 (2020-06-21)](https://github.com/pestphp/pest/compare/v0.2.1...v0.2.2)
### Added
- `depends` phpunit feature ([#103](https://github.com/pestphp/pest/pull/103))

### Fixes
- datasets name conflit ([#101](https://github.com/pestphp/pest/pull/101))

## [v0.2.1 (2020-06-17)](https://github.com/pestphp/pest/compare/v0.2.0...v0.2.1)
### Fixes
- Multiple `uses` in the same path override previous `uses` ([#97](https://github.com/pestphp/pest/pull/97))
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
]
},
"require-dev": {
"ergebnis/phpstan-rules": "^0.14.4",
"ergebnis/phpstan-rules": "^0.15.0",
"friendsofphp/php-cs-fixer": "^2.16.3",
"illuminate/console": "^7.10.3",
"illuminate/support": "^7.10.3",
"mockery/mockery": "^1.3.1",
"phpstan/phpstan": "^0.12.25",
"illuminate/console": "^7.16.1",
"illuminate/support": "^7.16.1",
"mockery/mockery": "^1.4.0",
"phpstan/phpstan": "^0.12.30",
"phpstan/phpstan-strict-rules": "^0.12.2",
"rector/rector": "^0.7.25",
"symfony/var-dumper": "^5.0.8",
"rector/rector": "^0.7.37",
"symfony/var-dumper": "^5.1.2",
"thecodingmachine/phpstan-strict-rules": "^0.12.0"
},
"minimum-stability": "dev",
Expand All @@ -70,7 +70,7 @@
"test:types": "phpstan analyse --ansi",
"test:unit": "php bin/pest --colors=always --exclude-group=integration",
"test:integration": "php bin/pest --colors=always --group=integration",
"test:update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always",
"update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always",
"test": [
"@test:lint",
"@test:types",
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ parameters:
reportUnmatchedIgnoredErrors: true

ignoreErrors:
- "#Undefined variable: \\$this#"
- "#is not allowed to extend#"
- "#Language construct eval#"
- "# with null as default value#"
- "#Using \\$this in static method#"
- "#has parameter \\$closure with default value.#"
- "#has parameter \\$description with default value.#"
19 changes: 14 additions & 5 deletions src/Concerns/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,25 @@ public function toString(): string

/**
* Runs the test.
*
* @return mixed
*
* @throws \Throwable
*/
public function __test(): void
public function __test()
{
$this->__callClosure($this->__test, func_get_args());
return $this->__callClosure($this->__test, func_get_args());
}

private function __callClosure(Closure $closure, array $arguments): void
/**
* @return mixed
*
* @throws \Throwable
*/
private function __callClosure(Closure $closure, array $arguments)
{
ExceptionTrace::ensure(function () use ($closure, $arguments) {
call_user_func_array(Closure::bind($closure, $this, get_class($this)), $arguments);
return ExceptionTrace::ensure(function () use ($closure, $arguments) {
return call_user_func_array(Closure::bind($closure, $this, get_class($this)), $arguments);
});
}

Expand Down
8 changes: 6 additions & 2 deletions src/Factories/TestCaseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,14 @@ public function build(TestSuite $testSuite): array
$proxies = $this->proxies;
$factoryTest = $this->test;

$test = function () use ($chains, $proxies, $factoryTest): void {
/**
* @return mixed
*/
$test = function () use ($chains, $proxies, $factoryTest) {
$proxies->proxy($this);
$chains->chain($this);
call_user_func(Closure::bind($factoryTest, $this, get_class($this)), ...func_get_args());

return call_user_func(Closure::bind($factoryTest, $this, get_class($this)), ...func_get_args());
};

$className = $this->makeClassFromFilename($this->filename);
Expand Down
14 changes: 13 additions & 1 deletion src/PendingObjects/TestCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ public function with($data): TestCall
return $this;
}

/**
* Sets the test depends.
*/
public function depends(string ...$tests): TestCall
{
$this->testCaseFactory
->factoryProxies
->add(Backtrace::file(), Backtrace::line(), 'setDependencies', [$tests]);

return $this;
}

/**
* Makes the test suite only this test case.
*/
Expand All @@ -95,7 +107,7 @@ public function only(): TestCall
}

/**
* Sets the test groups(s).
* Sets the test group(s).
*/
public function group(string ...$groups): TestCall
{
Expand Down
8 changes: 6 additions & 2 deletions src/Support/ExceptionTrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ final class ExceptionTrace
/**
* Ensures the given closure reports
* the good execution context.
*
* @return mixed
*
* @throws \Throwable
*/
public static function ensure(Closure $closure): void
public static function ensure(Closure $closure)
{
try {
$closure();
return $closure();
} catch (Throwable $throwable) {
if (Str::startsWith($message = $throwable->getMessage(), self::UNDEFINED_METHOD)) {
$message = str_replace(self::UNDEFINED_METHOD, 'Call to undefined method ', $message);
Expand Down
12 changes: 10 additions & 2 deletions tests/.snapshots/success.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@
✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), true) #3
✓ it creates unique test case names - count

PASS Tests\Features\Depends
✓ first
✓ second
✓ depends
✓ depends with ...params
✓ depends with defined arguments
✓ depends run test only once

PASS Tests\Features\Exceptions
✓ it gives access the the underlying expectException
✓ it catch exceptions
Expand Down Expand Up @@ -155,5 +163,5 @@
WARN Tests\Visual\Success
s visual snapshot of test suite on success

Tests: 6 skipped, 88 passed
Time: 3.53s
Tests: 6 skipped, 94 passed
Time: 3.73s
40 changes: 40 additions & 0 deletions tests/Features/Depends.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

$runCounter = 0;

test('first', function () use (&$runCounter) {
assertTrue(true);
$runCounter++;

return 'first';
});

test('second', function () use (&$runCounter) {
assertTrue(true);
$runCounter++;

return 'second';
});

test('depends', function () {
assertEquals(
['first', 'second'],
func_get_args()
);
})->depends('first', 'second');

test('depends with ...params', function (string ...$params) {
assertEquals(
['first', 'second'],
$params
);
})->depends('first', 'second');

test('depends with defined arguments', function (string $first, string $second) {
assertEquals('first', $first);
assertEquals('second', $second);
})->depends('first', 'second');

test('depends run test only once', function () use (&$runCounter) {
assertEquals(2, $runCounter);
})->depends('first', 'second');

0 comments on commit a47ad6a

Please sign in to comment.