Compare commits

...

21 Commits

Author SHA1 Message Date
15edde8e87 docs: updates changelog 2020-06-21 17:43:28 +02:00
211f5c2433 tests: makes incomplete tests success 2020-06-21 17:40:41 +02:00
5d58d58f71 chore: updates phpstan config 2020-06-21 17:40:29 +02:00
d5a4008d3e chore: bumps dev dependencies 2020-06-21 17:40:17 +02:00
1bf802268f Merge pull request #103 from nuernbergerA/feature/depends
Add support for PHPUnit's @depends
2020-06-21 17:10:58 +02:00
807a4b004f Merge branch 'master' into feature/depends 2020-06-21 17:10:51 +02:00
f7a3fa15f4 Merge pull request #101 from fetzi/bugfix/dataset-name-creation
Fix dataset name creation with objects
2020-06-20 21:42:16 +02:00
6dd3ca20e4 Also handle multiple descriptions within whole dataset 2020-06-20 11:29:07 +02:00
d9ea378819 Only append numbers when data set desc is the same 2020-06-20 09:53:38 +02:00
6aa0356570 add more tests 2020-06-19 23:22:14 +02:00
45b0d5d899 feat(depends): adds phpdocs 2020-06-19 21:39:01 +02:00
5be1edd7b7 added missing return types 2020-06-19 21:25:38 +02:00
75f7ee0acf added feedback from @nunomaduro 2020-06-19 20:39:09 +02:00
d0a74931dd implemented support for PHPUnit's @depends 2020-06-19 19:50:54 +02:00
0738e113ad Fix dataset name creation with objects
fixes #98
2020-06-19 16:03:47 +02:00
283d8f3e03 docs: updates changelog 2020-06-17 18:57:54 +02:00
1c3e820283 Merge pull request #97 from fkraefft/fix-traits
Fix in Test Repository use method.
2020-06-17 18:47:00 +02:00
accd4eb7b4 Multiple global uses registered in the same path test added. 2020-06-17 11:57:08 -03:00
ae7991c7e9 Style fixes. 2020-06-17 11:56:24 -03:00
e9e72d607e vscode folder added to gitignore. 2020-06-17 11:55:48 -03:00
40766f9275 Fix in Test Repository use method. 2020-06-17 09:59:46 -03:00
15 changed files with 177 additions and 25 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ coverage.xml
.temp/coverage.php
*.swp
*.swo
.vscode/

View File

@ -6,6 +6,17 @@ 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))
## [v0.2.0 (2020-06-14)](https://github.com/pestphp/pest/compare/v0.1.5...v0.2.0)
### Adds
- `--init` option to install Pest on a new blank project ([70b3c7e](https://github.com/pestphp/pest/commit/70b3c7ea1ddb031f3bbfaabdc28d56270608ebbd))

View File

@ -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",
@ -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",

View File

@ -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.#"

View File

@ -129,16 +129,25 @@ trait TestCase
/**
* 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);
});
}

View File

@ -74,12 +74,30 @@ final class Datasets
$data = iterator_to_array($data);
}
$namedData = [];
$dataSetDescriptions = [];
$dataSetValues = [];
foreach ($data as $values) {
$values = is_array($values) ? $values : [$values];
$name = $description . self::getDataSetDescription($values);
$namedData[$name] = $values;
$dataSetDescriptions[] = $description . self::getDataSetDescription($values);
$dataSetValues[] = $values;
}
foreach (array_count_values($dataSetDescriptions) as $descriptionToCheck => $count) {
if ($count > 1) {
$index = 1;
foreach ($dataSetDescriptions as $i => $dataSetDescription) {
if ($dataSetDescription === $descriptionToCheck) {
$dataSetDescriptions[$i] .= sprintf(' #%d', $index++);
}
}
}
}
$namedData = [];
foreach ($dataSetDescriptions as $i => $dataSetDescription) {
$namedData[$dataSetDescription] = $dataSetValues[$i];
}
return $namedData;

View File

@ -132,10 +132,14 @@ final class TestCaseFactory
$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);

View File

@ -84,6 +84,18 @@ final class 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.
*/
@ -95,7 +107,7 @@ final class TestCall
}
/**
* Sets the test groups(s).
* Sets the test group(s).
*/
public function group(string ...$groups): TestCall
{

View File

@ -104,7 +104,14 @@ final class TestRepository
}
foreach ($paths as $path) {
$this->uses[$path] = [$classOrTraits, $groups];
if (array_key_exists($path, $this->uses)) {
$this->uses[$path] = [
array_merge($this->uses[$path][0], $classOrTraits),
array_merge($this->uses[$path][1], $groups),
];
} else {
$this->uses[$path] = [$classOrTraits, $groups];
}
}
}

View File

@ -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);

View File

@ -41,6 +41,21 @@
✓ eager wrapped registered datasets with (2)
✓ eager registered wrapped datasets did the job right
✓ lazy named datasets with (Bar Object (...))
✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), true) #1
✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), true) #2
✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), false)
✓ it creates unique test case names with ('Name 2', Pest\Plugin Object (), false)
✓ it creates unique test case names with ('Name 2', Pest\Plugin Object (), true)
✓ 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
@ -101,6 +116,7 @@
PASS Tests\Plugins\Traits
✓ it allows global uses
✓ it allows multiple global uses registered in the same path
PASS Tests\Unit\Actions\AddsDefaults
✓ it sets defaults
@ -143,5 +159,5 @@
WARN Tests\Visual\Success
s visual snapshot of test suite on success
Tests: 6 skipped, 78 passed
Time: 3.09s
Tests: 6 skipped, 92 passed
Time: 3.40s

View File

@ -12,4 +12,13 @@ trait PluginTrait
}
}
trait SecondPluginTrait
{
public function assertSecondPluginTraitGotRegistered(): void
{
assertTrue(true);
}
}
Pest\Plugin::uses(PluginTrait::class);
Pest\Plugin::uses(SecondPluginTrait::class);

View File

@ -3,6 +3,7 @@
use Pest\Datasets;
use Pest\Exceptions\DatasetAlreadyExist;
use Pest\Exceptions\DatasetDoesNotExist;
use Pest\Plugin;
it('throws exception if dataset does not exist', function () {
$this->expectException(DatasetDoesNotExist::class);
@ -106,3 +107,21 @@ $namedDatasets = [
test('lazy named datasets', function ($text) use ($state, $datasets) {
assertTrue(true);
})->with($namedDatasets);
$counter = 0;
it('creates unique test case names', function (string $name, Plugin $plugin, bool $bool) use (&$counter) {
assertTrue(true);
$counter++;
})->with([
['Name 1', new Plugin(), true],
['Name 1', new Plugin(), true],
['Name 1', new Plugin(), false],
['Name 2', new Plugin(), false],
['Name 2', new Plugin(), true],
['Name 1', new Plugin(), true],
]);
it('creates unique test case names - count', function () use (&$counter) {
assertEquals(6, $counter);
});

View File

@ -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');

View File

@ -1,3 +1,5 @@
<?php
it('allows global uses')->assertPluginTraitGotRegistered();
it('allows multiple global uses registered in the same path')->assertSecondPluginTraitGotRegistered();