Compare commits

...

115 Commits

Author SHA1 Message Date
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
a3fd60ce4d docs: updates changelog 2020-06-14 17:01:15 +02:00
f9a3e39902 tests: removes test coverage for now
Co-Authored-By: Johannes Pichler <fetzi@users.noreply.github.com>
2020-06-14 16:35:30 +02:00
06d707fb41 feat(container): makes it autowirable
Co-Authored-By: Johannes Pichler <fetzi@users.noreply.github.com>
2020-06-14 16:25:51 +02:00
a70c64d704 tests: removes unused file 2020-06-14 16:23:54 +02:00
3a78aaef8f fix(container): resolves dependencies without contructor
Co-Authored-By: Johannes Pichler <fetzi@users.noreply.github.com>
2020-06-14 16:15:05 +02:00
c79c0feec8 feat(namespaced-functions): updates stubs 2020-06-14 02:16:14 +02:00
39a5a94f3e feat(namespaced-helpers): udpates stubs 2020-06-14 01:03:35 +02:00
961bfcaff7 Merge pull request #80 from owenvoke/feature/problem-matchers
Add problem matcher output to CI
2020-06-12 14:47:45 +02:00
52ba5dbd00 Add problem matcher output to CI 2020-06-12 13:37:17 +01:00
518b056fb9 fix: do not force having tests folder 2020-06-12 02:12:51 +02:00
f9a936b4d9 tests: namespace helpers 2020-06-11 21:56:15 +02:00
4448761852 Merge pull request #78 from felixdorn/patch-1
Optimise debug_backtrace calls
2020-06-11 21:46:23 +02:00
1192d13e6b add memory optimisation for Backtrace::testFile() 2020-06-11 16:38:31 +02:00
57b982de48 fix ci build 2020-06-11 16:31:14 +02:00
a3366379e0 optimise debug_backtrace calls 2020-06-11 16:13:17 +02:00
cd8d8fce61 chore: skips visual tests on windows for now 2020-06-10 21:38:45 +02:00
4254d71039 tests: fixes visual testing on windows 2020-06-10 21:32:54 +02:00
bd48232c61 chore: runs tests on windows 2020-06-10 21:17:56 +02:00
70b3c7ea1d chore: adds init plugin 2020-06-07 20:16:26 +02:00
c186035a13 chore: fixes duplicated branch alias 2020-06-05 22:44:48 +02:00
2efed3ef80 Merge pull request #65 from fetzi/feature/add-container
Add basic container implementation
2020-06-05 22:39:57 +02:00
58f2581307 Merge branch 'master' into feature/add-container 2020-06-05 22:39:02 +02:00
6c4fd61db5 tests: fixes testing running in php 7.3 2020-06-05 20:51:57 +02:00
afbbc35984 tests: refactor visual testing 2020-06-05 20:49:14 +02:00
a13c19cc29 chore: fixes deps 2020-06-05 20:04:10 +02:00
7d7c5f1ab1 Merge pull request #61 from dimitrioskarvounaris/windows-gitbash
Fixes autoloading, plugins and tests on Windows
2020-06-05 20:01:55 +02:00
865f33bf80 // fixing type check 2020-06-05 19:45:58 +02:00
e33419545c // fixing once more, wrong code pasted :( 2020-06-05 19:42:07 +02:00
b93cd724c1 // tiny fix 2020-06-05 19:37:53 +02:00
40a5d067ec // fixing type checks 2020-06-05 19:35:13 +02:00
3640ab0945 // unnecessary linebreak 2020-06-05 19:30:35 +02:00
cb2336d220 // missing change 2020-06-05 19:29:43 +02:00
71fcb281b0 Merge branch 'windows-gitbash' of github.com:dimitrioskarvounaris/pest into windows-gitbash 2020-06-05 19:25:23 +02:00
d24830121e Reverting changes from c05df432 2020-06-05 19:24:56 +02:00
5a00a732e3 Merge branch 'master' into windows-gitbash 2020-06-05 18:37:24 +02:00
38584bec93 Updating success.txt snapshot 2020-06-05 18:31:40 +02:00
ffa3f1d683 Skip visual snapshot test on Windows 2020-06-05 18:26:52 +02:00
dff9bbc134 Fix file paths not being used properly
basename() will strip full path information on some systems.
What is needed is to use both dirname() & basename() on paths,
as recognized by all systems, and only afterwards do any
replacements.
2020-06-05 18:24:03 +02:00
f5f717f1ad chore: requires more than collision beta1 2020-06-05 18:18:06 +02:00
9bdd254007 tests: adapts to collision beta 2 2020-06-05 18:14:27 +02:00
6e18912ea6 Test to check if the full test path is shown 2020-06-05 17:38:59 +02:00
d35320c697 Compare filename correctly on all OS 2020-06-05 17:25:53 +02:00
fe11140fc2 Adding dom extension to CI 2020-06-05 16:23:12 +02:00
0d198f589d Fix changes in success snapshot 2020-06-05 16:23:12 +02:00
8a42d40506 traits from Autoload.php not loading on Windows
Windows requires realpath() so the case of the
paths and filenames are always identical
2020-06-05 16:23:11 +02:00
83797431fb in() does not handle absolute paths under Windows
This fixes plugins to be included incorrectly under Windows
2020-06-05 16:23:11 +02:00
c05df43217 Compare lines without involving linebreaks
Fixes tests failing under Windows environments
for any linebreak character differences
2020-06-05 16:23:11 +02:00
f6859eeb3b Launch pest as php subprocess 2020-06-05 16:23:11 +02:00
a0b8082631 Fix issue with case-insensitive windows paths 2020-06-05 16:23:11 +02:00
926d8ecb8d Call binary as php sub process 2020-06-05 16:23:11 +02:00
24f85354e2 Normalize Windows dir name in TestCaseFactory 2020-06-05 16:21:35 +02:00
163de28338 Make sure PHP is called before calling pest as sub process 2020-06-05 16:21:35 +02:00
3d2c83a501 Make sure test targets are sanitized in a windows-compatible way 2020-06-05 16:21:35 +02:00
b0c964d4d9 Don't use "reapath" in binary for cross-compatibility 2020-06-05 16:21:35 +02:00
20d2d9f3b7 Merge pull request #69 from octoper/master
Update Changelog action
2020-06-05 16:15:30 +02:00
6b7aa10e91 Update changelog.yml 2020-06-05 17:03:32 +03:00
067aa58817 Merge branch 'feature/add-container' of github.com:fetzi/pest into feature/add-container 2020-06-05 11:53:17 +02:00
337e751200 Update plugin interfaces and instantiate container 2020-06-05 11:52:23 +02:00
b20f208b55 Add basic container implementation 2020-06-05 11:51:33 +02:00
9899b3c3a4 Update plugin interfaces and instantiate container 2020-06-05 07:48:51 +02:00
6437db7aa0 Updated changelog action 2020-06-05 06:18:18 +03:00
7d38d4bd4f Updated changelog action 2020-06-05 06:16:03 +03:00
e8d426f574 Removes windows for now 2020-06-04 23:09:40 +02:00
bb711108a2 Merge pull request #68 from octoper/patch-1
Update CHANGELOG.md
2020-06-04 22:14:16 +02:00
a482341b99 Update CHANGELOG.md 2020-06-04 21:22:29 +03:00
f5ce472006 Merge pull request #66 from pestphp/feat/pending-higher-order-tests
feat: adds pending higher order tests
2020-06-04 19:40:18 +02:00
a53ff3e459 Merge pull request #67 from octoper/master
fixed changelog action
2020-06-04 16:31:38 +02:00
e15d77f3f6 Update changelog.yml 2020-06-04 17:03:47 +03:00
504128730c Update changelog.yml 2020-06-04 16:53:08 +03:00
098acaecc0 Merge pull request #1 from pestphp/master
Pulling changes from pestphp/pest
2020-06-04 16:50:19 +03:00
b2dd573a67 Merge pull request #64 from octoper/master
Created Update CHANGELOG action
2020-06-04 15:17:29 +02:00
84c9078bb7 Add basic container implementation 2020-06-04 11:58:28 +02:00
aa1917c28d feat(pending-higher-order-tests): adds code and tests 2020-06-04 01:34:03 +02:00
c81dce0f6d feat(pending-higher-order-tests): adds code and tests 2020-06-04 01:33:33 +02:00
249869c2db Updated update_changelog to changelog action 2020-06-03 17:37:48 +03:00
d59d8d6245 Created update_changelog action 2020-06-03 17:32:07 +03:00
b0680b7e2c chore: cs 2020-05-31 13:42:27 +02:00
c7fd21999b Merge pull request #51 from Jibbarth/feature/support-colors-never
Feature/support colors never
2020-05-31 13:39:55 +02:00
28d06663d3 Add tests for --colors=never option 2020-05-31 12:33:27 +02:00
73f56e58a5 Pass color and verbosity args to printer (fix #49) 2020-05-31 12:32:43 +02:00
76796ffc67 refacto: includes coverage plugin 2020-05-30 01:43:02 +02:00
01daf0316c refacto: removes unused code about coverage 2020-05-29 22:44:41 +02:00
1f2976c0e0 tests: types 2020-05-29 22:35:20 +02:00
2e7ed741b6 fix: keeps result from plugin to plugin 2020-05-29 22:33:05 +02:00
a0a4730ef8 Merge branch 'master' of https://github.com/pestphp/pest 2020-05-29 22:28:47 +02:00
5ed927d226 Merge pull request #43 from fetzi/plugins
Integrate pest-plugins with 2 interfaces
2020-05-29 22:08:39 +02:00
78cdd4da36 Update composer.json 2020-05-29 21:15:51 +02:00
332139e614 Merge pull request #37 from owenvoke/bugfix/windows
Fix Windows builds running Pest
2020-05-29 20:12:54 +02:00
b093e8ee29 Integrate pest-plugins with 2 interfaces
integrate pest-plugin package and remove core coverage stuff
2020-05-29 11:28:06 +02:00
937374431a Fix Windows builds running Pest 2020-05-28 08:46:05 +01:00
ddc08cf0f9 docs: updates changelog 2020-05-24 21:41:35 +02:00
88d2391d2e fix: colors on coverage 2020-05-24 21:40:10 +02:00
bd02196950 docs: updates changelog 2020-05-24 21:32:53 +02:00
4de6019206 Merge pull request #18 from michaeldyrynda/master
Add support for installing Pest into a Lumen application
2020-05-24 20:43:23 +02:00
85630b0aa2 Merge pull request #22 from pgrimaud/master
Fix typos
2020-05-24 20:03:20 +02:00
0fda39467c Merge pull request #24 from AlexMartinFR/patch-1
Update README.md
2020-05-24 20:02:36 +02:00
415f571910 fix: mockery tests being considered as risky 2020-05-24 20:00:30 +02:00
8284219035 Update README.md
Typo.
2020-05-24 19:35:35 +02:00
d0d34c7872 Fix typos 2020-05-24 12:37:33 +02:00
2869f11ae5 use ->in(__DIR__) in base Pest.php file 2020-05-24 13:36:17 +09:30
340c7ca04e Merge pull request #20 from aniplaylist/patch-1
Fix typo in beforeAll() PHPDoc block
2020-05-24 00:48:21 +02:00
81a646d64e Fix typo in beforeAll() PHPDoc block 2020-05-23 23:01:03 +02:00
c23f2e4bd6 fix errors from type checks 2020-05-23 21:09:28 +09:30
4496e9d9ee Add support for installing Pest into a Lumen application
This entails creating Laravel and Lumen-specific stubs, and ensuring
that the appropriate stubs are copied as part of the pest install.
2020-05-23 20:52:15 +09:30
ce14ffd49a chore: fixes duplicated name on workflow 2020-05-21 23:25:43 +02:00
c18c481628 chore: updates names in github actions workflow 2020-05-21 23:13:32 +02:00
0695ea5d33 chore: runs formats testing in ubuntu only 2020-05-21 23:00:16 +02:00
2e321f5465 chore: fixes build 2020-05-21 22:49:46 +02:00
cbeec31bfc chore: adds windows build 2020-05-21 22:46:46 +02:00
55 changed files with 809 additions and 460 deletions

52
.github/workflows/changelog.yml vendored Normal file
View File

@ -0,0 +1,52 @@
name: Changelog
on:
push:
branches: [ master ]
paths:
- CHANGELOG.md
pull_request:
branches: [ master ]
paths:
- CHANGELOG.md
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout website repository
uses: actions/checkout@v2
with:
token: ${{ secrets.CHANGELOG_KEY }}
repository: pestphp/website
path: pestphp-website
- name: Read CHANGELOG.md
id: package
uses: juliangruber/read-file-action@v1
with:
path: ./CHANGELOG.md
- name: Add file headers
uses: DamianReeves/write-file-action@v1.0
with:
path: ./CHANGELOG.md
contents: |
---
title: Changelog
description: Changelog
extends: _layouts.documentation
section: content
---
${{ steps.package.outputs.content }}
write-mode: overwrite
- name: Copy CHANGELOG to website repository
run: cp CHANGELOG.md pestphp-website/source/docs/changelog.md
- name: Create Pull Request
uses: peter-evans/create-pull-request@v2
with:
token: ${{ secrets.CHANGELOG_KEY }}
commit-message: Update changelog.md
committer: GitHub Action <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
title: 'Update changelog.md'
path: ./pestphp-website

View File

@ -1,18 +1,19 @@
name: Continuous Integration
name: Formats
on: ['push', 'pull_request']
jobs:
ci:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
php: [7.3, 7.4]
os: [ubuntu-latest]
php: [7.4]
dependency-version: [prefer-lowest, prefer-stable]
name: CI - PHP ${{ matrix.php }} (${{ matrix.dependency-version }})
name: Formats P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}
steps:
@ -29,7 +30,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, zip
extensions: dom, mbstring, zip
tools: prestissimo
coverage: pcov
@ -43,9 +44,3 @@ jobs:
- name: Type Checks
run: vendor/bin/phpstan analyse --ansi
- name: Unit Tests
run: bin/pest --colors=always --exclude-group=integration
- name: Integration Tests
run: bin/pest --colors=always --group=integration

48
.github/workflows/tests.yml vendored Normal file
View File

@ -0,0 +1,48 @@
name: Tests
on: ['push', 'pull_request']
jobs:
ci:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
php: [7.3, 7.4]
dependency-version: [prefer-lowest, prefer-stable]
name: Tests P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, mbstring, zip
coverage: none
- name: Install Composer dependencies
run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist
- name: Unit Tests
run: php bin/pest --colors=always --exclude-group=integration
- name: Integration Tests
run: php bin/pest --colors=always --group=integration
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: Setup problem matchers for Pest
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

1
.gitignore vendored
View File

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

View File

@ -6,6 +6,42 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
## [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))
- pending higher orders tests aka tests without description ([aa1917c](https://github.com/pestphp/pest/commit/aa1917c28d9b69c2bd1d51f986c4f61318ee7e16))
### Fixed
- `--verbose` and `--colors` options not being used by printers ([#51](https://github.com/pestphp/pest/pull/51))
- missing support on windows ([#61](https://github.com/pestphp/pest/pull/61))
### Changed
- `helpers.php` stub provides now namespaced functions
- functions provided by plugins are now namespaced functions:
```php
use function Pest\Faker\faker;
it('foo', function () {
$name = faker()->name;
});
```
## [v0.1.5 (2020-05-24)](https://github.com/pestphp/pest/compare/v0.1.4...v0.1.5)
### Fixed
- Missing default decorated output on coverage ([88d2391](https://github.com/pestphp/pest/commit/88d2391d2e6fe9c9416462734b9b523cb418f469))
## [v0.1.4 (2020-05-24)](https://github.com/pestphp/pest/compare/v0.1.3...v0.1.4)
### Added
- Support to Lumen on artisan commands ([#18](https://github.com/pestphp/pest/pull/18))
### Fixed
- Mockery tests without assertions being considered risky ([415f571](https://github.com/pestphp/pest/commit/415f5719101b30c11d87f74810a71686ef2786c6))
## [v0.1.3 (2020-05-21)](https://github.com/pestphp/pest/compare/v0.1.2...v0.1.3)
### Added
- `Plugin::uses()` method for making traits globally available ([6c4be01](https://github.com/pestphp/pest/commit/6c4be0190e9493702a976b996bbbf5150cc6bb53))

View File

@ -9,7 +9,7 @@
</p>
------
**Pest** it's an elegant PHP Testing Framework with a focus on simplicity. It was carefully crafted to bring the joy of testing to PHP.
**Pest** is an elegant PHP Testing Framework with a focus on simplicity. It was carefully crafted to bring the joy of testing to PHP.
- Explore the docs: **[pestphp.com »](https://pestphp.com)**
- Follow us on Twitter: **[@pestphp »](https://twitter.com/pestphp)**

View File

@ -1,31 +1,39 @@
#!/usr/bin/env php
<?php declare(strict_types=1);
use NunoMaduro\Collision\Provider;
use Pest\Actions\ValidatesEnvironment;
use Pest\Console\Command;
use Pest\Support\Container;
use Pest\TestSuite;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
(static function () {
// Used when Pest is required using composer.
$vendorPath = realpath(__DIR__ . '/../../../../vendor/autoload.php');
$vendorPath = dirname(__DIR__, 4) . '/vendor/autoload.php';
// Used when Pest maintainers are running Pest tests.
$localPath = realpath(__DIR__ . '/../vendor/autoload.php');
$localPath = dirname(__DIR__) . '/vendor/autoload.php';
if ($vendorPath) {
if (file_exists($vendorPath)) {
include_once $vendorPath;
} else {
include_once $localPath;
}
(new \NunoMaduro\Collision\Provider)->register();
(new Provider())->register();
$rootPath = getcwd();
$testSuite = TestSuite::getInstance($rootPath);
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, true);
$container = Container::getInstance();
$container->add(TestSuite::class, $testSuite);
$container->add(OutputInterface::class, $output);
ValidatesEnvironment::in($testSuite);
exit((new Command($testSuite, new ConsoleOutput()))->run($_SERVER['argv']));
exit($container->get(Command::class)->run($_SERVER['argv']));
})();

View File

@ -18,7 +18,10 @@
],
"require": {
"php": "^7.3",
"nunomaduro/collision": "^5.0",
"nunomaduro/collision": "^5.0.0-BETA2",
"pestphp/pest-plugin": "^0.2",
"pestphp/pest-plugin-coverage": "^0.2",
"pestphp/pest-plugin-init": "^0.2",
"phpunit/phpunit": "^9.1.4",
"sebastian/environment": "^5.1"
},
@ -65,9 +68,9 @@
"lint": "rector process src && php-cs-fixer fix -v",
"test:lint": "php-cs-fixer fix -v --dry-run && rector process src --dry-run",
"test:types": "phpstan analyse --ansi",
"test:unit": "bin/pest --colors=always --exclude-group=integration",
"test:integration": "bin/pest --colors=always --group=integration",
"test:integration:snapshots": "REBUILD_SNAPSHOTS=true bin/pest --colors=always",
"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",
"test": [
"@test:lint",
"@test:types",
@ -76,6 +79,9 @@
]
},
"extra": {
"branch-alias": {
"dev-master": "0.2.x-dev"
},
"laravel": {
"providers": [
"Pest\\Laravel\\PestServiceProvider"

View File

@ -20,3 +20,4 @@ parameters:
- "# with null as default value#"
- "#Using \\$this in static method#"
- "#has parameter \\$closure with default value.#"
- "#has parameter \\$description with default value.#"

View File

@ -1,79 +0,0 @@
<?php
declare(strict_types=1);
namespace Pest\Actions;
use Pest\Console\Coverage;
use Pest\Support\Str;
use Pest\TestSuite;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
/**
* @internal
*/
final class AddsCoverage
{
/**
* @var string
*/
private const COVERAGE_OPTION = 'coverage';
/**
* @var string
*/
private const MIN_OPTION = 'min';
/**
* Holds the coverage related options.
*
* @var array<int, string>
*/
private const OPTIONS = [self::COVERAGE_OPTION, self::MIN_OPTION];
/**
* If any, adds the coverage params to the given original arguments.
*
* @param array<int, string> $originals
*
* @return array<int, string>
*/
public static function from(TestSuite $testSuite, array $originals): array
{
$arguments = array_merge([''], array_values(array_filter($originals, function ($original): bool {
foreach (self::OPTIONS as $option) {
if ($original === sprintf('--%s', $option) || Str::startsWith($original, sprintf('--%s=', $option))) {
return true;
}
}
return false;
})));
$originals = array_flip($originals);
foreach ($arguments as $argument) {
unset($originals[$argument]);
}
$originals = array_flip($originals);
$inputs = [];
$inputs[] = new InputOption(self::COVERAGE_OPTION, null, InputOption::VALUE_NONE);
$inputs[] = new InputOption(self::MIN_OPTION, null, InputOption::VALUE_REQUIRED);
$input = new ArgvInput($arguments, new InputDefinition($inputs));
if ((bool) $input->getOption(self::COVERAGE_OPTION)) {
$testSuite->coverage = true;
$originals[] = '--coverage-php';
$originals[] = Coverage::getPath();
}
if ($input->getOption(self::MIN_OPTION) !== null) {
/* @phpstan-ignore-next-line */
$testSuite->coverageMin = (float) $input->getOption(self::MIN_OPTION);
}
return $originals;
}
}

View File

@ -21,7 +21,7 @@ final class AddsDefaults
public static function to(array $arguments): array
{
if (!array_key_exists('printer', $arguments)) {
$arguments['printer'] = new Printer();
$arguments['printer'] = new Printer(null, $arguments['verbose'] ?? false, $arguments['colors'] ?? 'always');
}
return $arguments;

View File

@ -19,7 +19,6 @@ final class ValidatesEnvironment
*/
private const NEEDED_FILES = [
'composer.json',
'tests',
];
/**

View File

@ -4,11 +4,13 @@ declare(strict_types=1);
namespace Pest\Console;
use Pest\Actions\AddsCoverage;
use Pest\Actions\AddsDefaults;
use Pest\Actions\AddsTests;
use Pest\Actions\LoadStructure;
use Pest\Actions\ValidatesConfiguration;
use Pest\Contracts\Plugins\AddsOutput;
use Pest\Contracts\Plugins\HandlesArguments;
use Pest\Plugin\Loader;
use Pest\TestSuite;
use PHPUnit\Framework\TestSuite as BaseTestSuite;
use PHPUnit\TextUI\Command as BaseCommand;
@ -54,9 +56,14 @@ final class Command extends BaseCommand
protected function handleArguments(array $argv): void
{
/*
* First, let's handle pest is own `--coverage` param.
* First, let's call all plugins that want to handle arguments
*/
$argv = AddsCoverage::from($this->testSuite, $argv);
$plugins = Loader::getPlugins(HandlesArguments::class);
/** @var HandlesArguments $plugin */
foreach ($plugins as $plugin) {
$argv = $plugin->handleArguments($argv);
}
/*
* Next, as usual, let's send the console arguments to PHPUnit.
@ -81,6 +88,8 @@ final class Command extends BaseCommand
*/
$this->arguments = AddsDefaults::to($this->arguments);
LoadStructure::in($this->testSuite->rootPath);
$testRunner = new TestRunner($this->arguments['loader']);
$testSuite = $this->arguments['test'];
@ -102,7 +111,6 @@ final class Command extends BaseCommand
$this->arguments['test'] = $testSuite;
}
LoadStructure::in($this->testSuite->rootPath);
AddsTests::to($testSuite, $this->testSuite);
return $testRunner;
@ -119,25 +127,14 @@ final class Command extends BaseCommand
{
$result = parent::run($argv, false);
if ($result === 0 && $this->testSuite->coverage) {
if (!Coverage::isAvailable()) {
$this->output->writeln(
"\n <fg=white;bg=red;options=bold> ERROR </> No code coverage driver is available.</>",
);
exit(1);
}
/*
* Let's call all plugins that want to add output after test execution
*/
$plugins = Loader::getPlugins(AddsOutput::class);
$coverage = Coverage::report($this->output);
$result = (int) ($coverage < $this->testSuite->coverageMin);
if ($result === 1) {
$this->output->writeln(sprintf(
"\n <fg=white;bg=red;options=bold> FAIL </> Code coverage below expected:<fg=red;options=bold> %s %%</>. Minimum:<fg=white;options=bold> %s %%</>.",
number_format($coverage, 1),
number_format($this->testSuite->coverageMin, 1)
));
}
/** @var AddsOutput $plugin */
foreach ($plugins as $plugin) {
$result = $plugin->addOutput($result);
}
exit($result);

View File

@ -1,167 +0,0 @@
<?php
declare(strict_types=1);
namespace Pest\Console;
use Pest\Exceptions\ShouldNotHappen;
use SebastianBergmann\CodeCoverage\Node\Directory;
use SebastianBergmann\CodeCoverage\Node\File;
use SebastianBergmann\Environment\Runtime;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Terminal;
/**
* @internal
*/
final class Coverage
{
/**
* Returns the coverage path.
*/
public static function getPath(): string
{
return implode(DIRECTORY_SEPARATOR, [
dirname(__DIR__, 2),
'.temp',
'coverage.php',
]);
}
/**
* Runs true there is any code
* coverage driver available.
*/
public static function isAvailable(): bool
{
return (new Runtime())->canCollectCodeCoverage();
}
/**
* Reports the code coverage report to the
* console and returns the result in float.
*/
public static function report(OutputInterface $output): float
{
if (!file_exists($reportPath = self::getPath())) {
throw ShouldNotHappen::fromMessage(sprintf('Coverage not found in path: %s.', $reportPath));
}
/** @var \SebastianBergmann\CodeCoverage\CodeCoverage $codeCoverage */
$codeCoverage = require $reportPath;
unlink($reportPath);
$totalWidth = (new Terminal())->getWidth();
$dottedLineLength = $totalWidth <= 70 ? $totalWidth : 70;
$totalCoverage = $codeCoverage->getReport()->getLineExecutedPercent();
$output->writeln(
sprintf(
' <fg=white;options=bold>Cov: </><fg=default>%s</>',
$totalCoverage
)
);
$output->writeln('');
/** @var Directory<File|Directory> $report */
$report = $codeCoverage->getReport();
foreach ($report->getIterator() as $file) {
if (!$file instanceof File) {
continue;
}
$dirname = dirname($file->getId());
$basename = basename($file->getId(), '.php');
$name = $dirname === '.' ? $basename : implode(DIRECTORY_SEPARATOR, [
$dirname,
$basename,
]);
$rawName = $dirname === '.' ? $basename : implode(DIRECTORY_SEPARATOR, [
$dirname,
$basename,
]);
$linesExecutedTakenSize = 0;
if ($file->getLineExecutedPercent() != '0.00%') {
$linesExecutedTakenSize = strlen($uncoveredLines = trim(implode(', ', self::getMissingCoverage($file)))) + 1;
$name .= sprintf(' <fg=red>%s</>', $uncoveredLines);
}
$percentage = $file->getNumExecutableLines() === 0
? '100.0'
: number_format((float) $file->getLineExecutedPercent(), 1, '.', '');
$takenSize = strlen($rawName . $percentage) + 4 + $linesExecutedTakenSize; // adding 3 space and percent sign
$percentage = sprintf(
'<fg=%s>%s</>',
$percentage === '100.0' ? 'green' : ($percentage === '0.0' ? 'red' : 'yellow'),
$percentage
);
$output->writeln(sprintf(' %s %s %s %%',
$name,
str_repeat('.', max($dottedLineLength - $takenSize, 1)),
$percentage
));
}
return (float) $totalCoverage;
}
/**
* Generates an array of missing coverage on the following format:.
*
* ```
* ['11', '20..25', '50', '60...80'];
* ```
*
* @param File $file
*
* @return array<int, string>
*/
public static function getMissingCoverage($file): array
{
$shouldBeNewLine = true;
$eachLine = function (array $array, array $tests, int $line) use (&$shouldBeNewLine): array {
if (count($tests) > 0) {
$shouldBeNewLine = true;
return $array;
}
if ($shouldBeNewLine) {
$array[] = (string) $line;
$shouldBeNewLine = false;
return $array;
}
$lastKey = count($array) - 1;
if (array_key_exists($lastKey, $array) && strpos($array[$lastKey], '..') !== false) {
[$from] = explode('..', $array[$lastKey]);
$array[$lastKey] = sprintf('%s..%s', $from, $line);
return $array;
}
$array[$lastKey] = sprintf('%s..%s', $array[$lastKey], $line);
return $array;
};
$array = [];
foreach (array_filter($file->getCoverageData(), 'is_array') as $line => $tests) {
$array = $eachLine($array, $tests, $line);
}
return $array;
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace Pest\Contracts\Plugins;
/**
* @internal
*/
interface AddsOutput
{
/**
* Allows to add custom output after the test suite was executed.
*/
public function addOutput(int $testReturnCode): int;
}

View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Pest\Contracts\Plugins;
/**
* @internal
*/
interface HandlesArguments
{
/**
* Allows to handle custom command line arguments.
*
* PLEASE NOTE: it is necessary to remove any custom argument from the array
* because otherwise the application will complain about them
*
* @param array<int, string> $arguments
*
* @return array<int, string> the updated list of arguments
*/
public function handleArguments(array $arguments): array;
}

View File

@ -8,6 +8,7 @@ use Closure;
use Pest\Concerns;
use Pest\Contracts\HasPrintableTestCaseName;
use Pest\Datasets;
use Pest\Exceptions\ShouldNotHappen;
use Pest\Support\HigherOrderMessageCollection;
use Pest\Support\NullClosure;
use Pest\TestSuite;
@ -39,9 +40,10 @@ final class TestCaseFactory
/**
* Holds the test description.
*
* @readonly
* If the description is null, means that it
* will be created with the given assertions.
*
* @var string
* @var string|null
*/
public $description;
@ -104,7 +106,7 @@ final class TestCaseFactory
/**
* Creates a new anonymous test case pending object.
*/
public function __construct(string $filename, string $description, Closure $closure = null)
public function __construct(string $filename, string $description = null, Closure $closure = null)
{
$this->filename = $filename;
$this->description = $description;
@ -122,6 +124,10 @@ final class TestCaseFactory
*/
public function build(TestSuite $testSuite): array
{
if ($this->description === null) {
throw ShouldNotHappen::fromMessage('Description can not be empty.');
}
$chains = $this->chains;
$proxies = $this->proxies;
$factoryTest = $this->test;
@ -152,16 +158,25 @@ final class TestCaseFactory
*/
public function makeClassFromFilename(string $filename): string
{
if ('\\' === DIRECTORY_SEPARATOR) {
// In case Windows, strtolower drive name, like in UsesCall.
$filename = (string) preg_replace_callback('~^(?P<drive>[a-z]+:\\\)~i', function ($match): string {
return strtolower($match['drive']);
}, $filename);
}
$filename = (string) realpath($filename);
$rootPath = TestSuite::getInstance()->rootPath;
$relativePath = str_replace($rootPath . DIRECTORY_SEPARATOR, '', $filename);
$relativePath = dirname(ucfirst($relativePath)) . DIRECTORY_SEPARATOR . basename($relativePath, '.php');
$relativePath = str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath);
// Strip out any %-encoded octets.
$relativePath = (string) preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $relativePath);
// Limit to A-Z, a-z, 0-9, '_', '-'.
$relativePath = (string) preg_replace('/[^A-Za-z0-9.\/]/', '', $relativePath);
$classFQN = 'P\\' . basename(ucfirst(str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath)), '.php');
$relativePath = (string) preg_replace('/[^A-Za-z0-9.\\\]/', '', $relativePath);
$classFQN = 'P\\' . $relativePath;
if (class_exists($classFQN)) {
return $classFQN;
}

View File

@ -7,6 +7,7 @@ namespace Pest\Laravel\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Pest\Exceptions\InvalidConsoleArgument;
use Pest\Support\Str;
/**
* @internal
@ -36,6 +37,7 @@ final class PestInstallCommand extends Command
$pest = base_path('tests/Pest.php');
/* @phpstan-ignore-next-line */
$helpers = base_path('tests/Helpers.php');
$stubs = $this->isLumen() ? 'stubs/Lumen' : 'stubs/Laravel';
foreach ([$pest, $helpers] as $file) {
if (File::exists($file)) {
@ -45,17 +47,26 @@ final class PestInstallCommand extends Command
File::copy(implode(DIRECTORY_SEPARATOR, [
dirname(__DIR__, 3),
'stubs',
$stubs,
'Pest.php',
]), $pest);
File::copy(implode(DIRECTORY_SEPARATOR, [
dirname(__DIR__, 3),
'stubs',
$stubs,
'Helpers.php',
]), $helpers);
$this->output->success('`tests/Pest.php` created successfully.');
$this->output->success('`tests/Helpers.php` created successfully.');
}
/**
* Determine if this is a Lumen application.
*/
private function isLumen(): bool
{
/* @phpstan-ignore-next-line */
return Str::startsWith(app()->version(), 'Lumen');
}
}

View File

@ -9,12 +9,22 @@ use Pest\Factories\TestCaseFactory;
use Pest\Support\Backtrace;
use Pest\Support\NullClosure;
use Pest\TestSuite;
use SebastianBergmann\Exporter\Exporter;
/**
* @internal
*/
final class TestCall
{
/**
* Holds the test suite.
*
* @readonly
*
* @var TestSuite
*/
private $testSuite;
/**
* Holds the test case factory.
*
@ -24,14 +34,23 @@ final class TestCall
*/
private $testCaseFactory;
/**
* If test call is descriptionLess.
*
* @readonly
*
* @var bool
*/
private $descriptionLess = false;
/**
* Creates a new instance of a pending test call.
*/
public function __construct(TestSuite $testSuite, string $filename, string $description, Closure $closure = null)
public function __construct(TestSuite $testSuite, string $filename, string $description = null, Closure $closure = null)
{
$this->testCaseFactory = new TestCaseFactory($filename, $description, $closure);
$testSuite->tests->set($this->testCaseFactory);
$this->testSuite = $testSuite;
$this->descriptionLess = $description === null;
}
/**
@ -128,6 +147,23 @@ final class TestCall
->chains
->add(Backtrace::file(), Backtrace::line(), $name, $arguments);
if ($this->descriptionLess) {
$exporter = new Exporter();
if ($this->testCaseFactory->description !== null) {
$this->testCaseFactory->description .= ' → ';
}
$this->testCaseFactory->description .= sprintf('%s %s', $name, $exporter->shortenedRecursiveExport($arguments));
}
return $this;
}
/**
* Adds the current test case factory
* to the tests repository.
*/
public function __destruct()
{
$this->testSuite->tests->set($this->testCaseFactory);
}
}

View File

@ -59,7 +59,17 @@ final class UsesCall
public function in(string ...$targets): void
{
$targets = array_map(function ($path): string {
return $path[0] === DIRECTORY_SEPARATOR
$startChar = DIRECTORY_SEPARATOR;
if ('\\' === DIRECTORY_SEPARATOR || preg_match('~\A[A-Z]:(?![^/\\\\])~i', $path) > 0) {
$path = (string) preg_replace_callback('~^(?P<drive>[a-z]+:\\\)~i', function ($match): string {
return strtolower($match['drive']);
}, $path);
$startChar = strtolower((string) preg_replace('~^([a-z]+:\\\).*$~i', '$1', __DIR__));
}
return 0 === strpos($path, $startChar)
? $path
: implode(DIRECTORY_SEPARATOR, [
dirname($this->filename),
@ -68,12 +78,12 @@ final class UsesCall
}, $targets);
$this->targets = array_map(function ($target): string {
$realTarget = realpath($target);
if ($realTarget === false) {
$isValid = is_dir($target) || file_exists($target);
if (!$isValid) {
throw new InvalidUsesPath($target);
}
return $realTarget;
return (string) realpath($target);
}, $targets);
}

View File

@ -41,6 +41,12 @@ final class AfterEachRepository
return ChainableClosure::from(function (): void {
if (class_exists(Mockery::class)) {
/* @phpstan-ignore-next-line */
if ($container = Mockery::getContainer()) {
/* @phpstan-ignore-next-line */
$this->addToAssertionCount($container->mockery_getExpectationCount());
}
Mockery::close();
}
}, $afterEach);

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Pest\Repositories;
use Pest\Exceptions\ShouldNotHappen;
use Pest\Exceptions\TestAlreadyExist;
use Pest\Exceptions\TestCaseAlreadyInUse;
use Pest\Exceptions\TestCaseClassOrTraitNotFound;
@ -54,7 +55,6 @@ final class TestRepository
if ($testCase->class !== \PHPUnit\Framework\TestCase::class) {
throw new TestCaseAlreadyInUse($testCase->class, $class, $filename);
}
$testCase->class = $class;
} elseif (trait_exists($class)) {
$testCase->traits[] = $class;
@ -104,15 +104,26 @@ final class TestRepository
}
foreach ($paths as $path) {
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];
}
}
}
/**
* Sets a test case by the given filename and description.
*/
public function set(TestCaseFactory $test): void
{
if ($test->description === null) {
throw ShouldNotHappen::fromMessage('Trying to create a test without description.');
}
if (array_key_exists(sprintf('%s@%s', $test->filename, $test->description), $this->state)) {
throw new TestAlreadyExist($test->filename, $test->description);
}

View File

@ -4,17 +4,48 @@ declare(strict_types=1);
namespace Pest\Support;
use Pest\Exceptions\ShouldNotHappen;
/**
* @internal
*/
final class Backtrace
{
/**
* @var string
*/
private const FILE = 'file';
private const BACKTRACE_OPTIONS = DEBUG_BACKTRACE_IGNORE_ARGS;
/**
* Returns the current test file.
*/
public static function testFile(): string
{
$current = null;
foreach (debug_backtrace(self::BACKTRACE_OPTIONS) as $trace) {
if (Str::endsWith($trace[self::FILE], (string) realpath('vendor/phpunit/phpunit/src/Util/FileLoader.php'))) {
break;
}
$current = $trace;
}
if ($current === null) {
throw ShouldNotHappen::fromMessage('Test file not found.');
}
return $current[self::FILE];
}
/**
* Returns the filename that called the current function/method.
*/
public static function file(): string
{
return debug_backtrace()[1]['file'];
return debug_backtrace(self::BACKTRACE_OPTIONS)[1][self::FILE];
}
/**
@ -22,7 +53,7 @@ final class Backtrace
*/
public static function dirname(): string
{
return dirname(debug_backtrace()[1]['file']);
return dirname(debug_backtrace(self::BACKTRACE_OPTIONS)[1][self::FILE]);
}
/**
@ -30,6 +61,6 @@ final class Backtrace
*/
public static function line(): int
{
return debug_backtrace()[1]['line'];
return debug_backtrace(self::BACKTRACE_OPTIONS)[1]['line'];
}
}

101
src/Support/Container.php Normal file
View File

@ -0,0 +1,101 @@
<?php
declare(strict_types=1);
namespace Pest\Support;
use Pest\Exceptions\ShouldNotHappen;
use ReflectionClass;
use ReflectionParameter;
/**
* @internal
*/
final class Container
{
/**
* @var self
*/
private static $instance;
/**
* @var array<string, mixed>
*/
private $instances = [];
/**
* Gets a new or already existing container.
*/
public static function getInstance(): self
{
if (static::$instance === null) {
static::$instance = new static();
}
return static::$instance;
}
/**
* Gets a dependency from the container.
*
* @return object
*/
public function get(string $id)
{
if (array_key_exists($id, $this->instances)) {
return $this->instances[$id];
}
$this->instances[$id] = $this->build($id);
return $this->instances[$id];
}
/**
* Adds the given instance to the container.
*
* @param mixed $instance
*/
public function add(string $id, $instance): void
{
$this->instances[$id] = $instance;
}
/**
* Tries to build the given instance.
*/
private function build(string $id): object
{
/** @phpstan-ignore-next-line */
$reflectionClass = new ReflectionClass($id);
if ($reflectionClass->isInstantiable()) {
$constructor = $reflectionClass->getConstructor();
if ($constructor !== null) {
$params = array_map(
function (ReflectionParameter $param) use ($id) {
$candidate = null;
if ($param->getType() !== null && $param->getType()->isBuiltin()) {
$candidate = $param->getName();
} elseif ($param->getClass() !== null) {
$candidate = $param->getClass()->getName();
} else {
throw ShouldNotHappen::fromMessage(sprintf('The type of `$%s` in `%s` cannot be determined.', $id, $param->getName()));
}
return $this->get($candidate);
},
$constructor->getParameters()
);
return $reflectionClass->newInstanceArgs($params);
}
return $reflectionClass->newInstance();
}
throw ShouldNotHappen::fromMessage(sprintf('A dependency with the name `%s` cannot be resolved.', $id));
}
}

View File

@ -78,7 +78,9 @@ final class HigherOrderMessage
if ($throwable->getMessage() === sprintf(self::UNDEFINED_METHOD, $this->methodName)) {
/** @var \ReflectionClass $reflection */
$reflection = (new ReflectionClass($target))->getParentClass();
$reflection = new ReflectionClass($target);
/* @phpstan-ignore-next-line */
$reflection = $reflection->getParentClass() ?: $reflection;
Reflection::setPropertyValue($throwable, 'message', sprintf('Call to undefined method %s::%s()', $reflection->getName(), $this->methodName));
}

View File

@ -30,20 +30,6 @@ final class TestSuite
*/
public $tests;
/**
* Whether should show the coverage or not.
*
* @var bool
*/
public $coverage = false;
/**
* The minimum coverage.
*
* @var float
*/
public $coverageMin = 0.0;
/**
* Holds the before each repository.
*
@ -97,7 +83,7 @@ final class TestSuite
$this->afterEach = new AfterEachRepository();
$this->afterAll = new AfterAllRepository();
$this->rootPath = $rootPath;
$this->rootPath = (string) realpath($rootPath);
}
/**

View File

@ -13,7 +13,7 @@ use Pest\TestSuite;
use PHPUnit\Framework\TestCase;
/**
* Runs the given closure after all tests in the current file.
* Runs the given closure before all tests in the current file.
*/
function beforeAll(Closure $closure): void
{
@ -66,7 +66,7 @@ function test(string $description = null, Closure $closure = null)
return new HigherOrderTapProxy(TestSuite::getInstance()->test);
}
$filename = Backtrace::file();
$filename = Backtrace::testFile();
return new TestCall(TestSuite::getInstance(), $filename, $description, $closure);
}
@ -80,9 +80,9 @@ function test(string $description = null, Closure $closure = null)
*/
function it(string $description, Closure $closure = null): TestCall
{
$filename = Backtrace::file();
$description = sprintf('it %s', $description);
return new TestCall(TestSuite::getInstance(), $filename, sprintf('it %s', $description), $closure);
return test($description, $closure);
}
/**

View File

@ -1,12 +0,0 @@
<?php
use Illuminate\Contracts\Auth\Authenticatable;
use Tests\TestCase;
/**
* Set the currently logged in user for the application.
*/
function actingAs(Authenticatable $user, string $driver = null): TestCase
{
return test()->actingAs($user, $driver);
}

11
stubs/Laravel/Helpers.php Normal file
View File

@ -0,0 +1,11 @@
<?php
namespace Tests;
/**
* A basic assert example.
*/
function assertExample(): void
{
test()->assertTrue(true);
}

11
stubs/Lumen/Helpers.php Normal file
View File

@ -0,0 +1,11 @@
<?php
namespace Tests;
/**
* A basic assert example.
*/
function assertExample(): void
{
test()->assertTrue(true);
}

3
stubs/Lumen/Pest.php Normal file
View File

@ -0,0 +1,3 @@
<?php
uses(TestCase::class)->in(__DIR__);

17
stubs/Lumen/phpunit.xml Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
</phpunit>

View File

@ -0,0 +1,7 @@
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
✓ it example 1
PASS Tests\Fixtures\ExampleTest
✓ it example 2
Tests: 2 passed

View File

@ -0,0 +1,4 @@
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
✓ it example 1
Tests: 1 passed

View File

@ -0,0 +1,60 @@
PASS Tests\Playground
✓ basic
Tests: 1 passed
Time: 0.20s
Cov: 6.49%
Actions/AddsDefaults ........................................... 0.0 %
Actions/AddsTests .............................................. 0.0 %
Actions/LoadStructure .......................................... 0.0 %
Actions/ValidatesConfiguration ................................. 0.0 %
Actions/ValidatesEnvironment ................................... 0.0 %
Concerns/TestCase 40..54, 71..88, 123..126, 147 ............... 44.4 %
Console/Command ................................................ 0.0 %
Contracts/HasPrintableTestCaseName ............................. 0.0 %
Contracts/Plugins/AddsOutput ................................ 100.0 %
Contracts/Plugins/HandlesArguments .......................... 100.0 %
Datasets ....................................................... 0.0 %
Exceptions/AfterAllAlreadyExist ................................ 0.0 %
Exceptions/AfterEachAlreadyExist ............................... 0.0 %
Exceptions/AttributeNotSupportedYet ............................ 0.0 %
Exceptions/BeforeEachAlreadyExist .............................. 0.0 %
Exceptions/DatasetAlreadyExist ................................. 0.0 %
Exceptions/DatasetDoesNotExist ................................. 0.0 %
Exceptions/FileOrFolderNotFound ................................ 0.0 %
Exceptions/InvalidConsoleArgument .............................. 0.0 %
Exceptions/InvalidPestCommand .................................. 0.0 %
Exceptions/InvalidUsesPath ..................................... 0.0 %
Exceptions/ShouldNotHappen ..................................... 0.0 %
Exceptions/TestAlreadyExist .................................... 0.0 %
Exceptions/TestCaseAlreadyInUse ................................ 0.0 %
Exceptions/TestCaseClassOrTraitNotFound ........................ 0.0 %
Factories/TestCaseFactory 111..133, 141..204 ................... 8.2 %
Laravel/Commands/PestDatasetCommand ............................ 0.0 %
Laravel/Commands/PestInstallCommand ............................ 0.0 %
Laravel/Commands/PestTestCommand ............................... 0.0 %
Laravel/PestServiceProvider .................................... 0.0 %
PendingObjects/AfterEachCall ................................... 0.0 %
PendingObjects/BeforeEachCall .................................. 0.0 %
PendingObjects/TestCall ........................................ 0.0 %
PendingObjects/UsesCall ........................................ 0.0 %
Plugin ......................................................... 0.0 %
Repositories/AfterAllRepository ................................ 0.0 %
Repositories/AfterEachRepository 28..33 ....................... 60.0 %
Repositories/BeforeAllRepository ............................... 0.0 %
Repositories/BeforeEachRepository 26..31 ...................... 20.0 %
Repositories/TestRepository .................................... 0.0 %
Support/Backtrace .............................................. 0.0 %
Support/ChainableClosure .................................... 100.0 %
Support/Container .............................................. 0.0 %
Support/ExceptionTrace 25..32 ................................. 28.6 %
Support/HigherOrderMessage ..................................... 0.0 %
Support/HigherOrderMessageCollection 24..25, 33, 43 ........... 50.0 %
Support/HigherOrderTapProxy .................................... 0.0 %
Support/NullClosure ......................................... 100.0 %
Support/Reflection ............................................. 0.0 %
Support/Str .................................................... 0.0 %
TestSuite 80..87, 95..101, 105 ................................ 20.0 %
globals ........................................................ 0.0 %

View File

@ -0,0 +1,5 @@
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
it example 1
Tests: 1 passed

View File

@ -0,0 +1,5 @@
 PASS  Tests\Fixtures\DirectoryWithTests\ExampleTest
✓ it example 1
Tests: 1 passed

View File

@ -1,5 +1,5 @@
PASS Tests\CustomTestCase\PhpunitTest
PASS Tests\CustomTestCase\ExecutedTest
✓ that gets executed
PASS Tests\Features\AfterAll
@ -24,7 +24,7 @@
✓ it sets arrays
✓ it gets bound to test case object with ('a')
✓ it gets bound to test case object with ('b')
✓ it truncates the description with (' fooo fooo fooo fooo fooo fooo fooo f...oo fooo')
✓ it truncates the description with ('FoooFoooFoooFoooFoooFoooFoooF...ooFooo')
✓ lazy datasets with (1)
✓ lazy datasets with (2)
✓ lazy datasets did the job right
@ -40,10 +40,10 @@
✓ eager wrapped registered datasets with (1)
✓ eager wrapped registered datasets with (2)
✓ eager registered wrapped datasets did the job right
✓ lazy named datasets with ( bar object (...))
✓ lazy named datasets with (Bar Object (...))
PASS Tests\Features\Exceptions
✓ it gives access the the underlying expect exception
✓ it gives access the the underlying expectException
✓ it catch exceptions
✓ it catch exceptions and messages
@ -53,7 +53,7 @@
✓ it allows to call underlying protected/private methods
✓ it throws error if method do not exist
PASS Tests\Features\HigherOrderMessages
PASS Tests\Features\HigherOrderTests
✓ it proxies calls to object
PASS Tests\Features\It
@ -63,6 +63,10 @@
PASS Tests\Features\Mocks
✓ it has bar
PASS Tests\Features\PendingHigherOrderTests
✓ get 'foo' → get 'bar' → assertTrue true
✓ get 'foo' → assertTrue true
WARN Tests\Features\Skip
✓ it do not skips
s it skips with truthy
@ -70,23 +74,23 @@
s it skips with message → skipped because bar
s it skips with truthy closure condition
✓ it do not skips with falsy closure condition
s it skips with condition and messsage → skipped because foo
s it skips with condition and message → skipped because foo
PASS Tests\Features\Test
✓ a test
✓ higher order message test
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
✓ it example
✓ it example 1
PASS Tests\Fixtures\ExampleTest
✓ it example
✓ it example 2
PASS Tests\PHPUnit\CustomTestCase\UsesPerDirectory
✓ closure was bound to custom test case
✓ closure was bound to CustomTestCase
PASS Tests\PHPUnit\CustomTestCaseInSubFolders\SubFolder\SubFolder\UsesPerSubDirectory
✓ closure was bound to custom test case
✓ closure was bound to CustomTestCase
PASS Tests\PHPUnit\CustomTestCaseInSubFolders\SubFolder2\UsesPerFile
✓ custom traits can be used
@ -97,10 +101,7 @@
PASS Tests\Plugins\Traits
✓ it allows global uses
PASS Tests\Unit\Actions\AddsCoverage
✓ it adds coverage if --coverage exist
✓ it adds coverage if --min exist
✓ it allows multiple global uses registered in the same path
PASS Tests\Unit\Actions\AddsDefaults
✓ it sets defaults
@ -115,12 +116,18 @@
✓ it throws exception when `process isolation` is true
✓ it do not throws exception when `process isolation` is false
PASS Tests\Unit\Console\Coverage
✓ it generates coverage based on file input
PASS Tests\Unit\Support\Backtrace
✓ it gets file name from called file
PASS Tests\Unit\Support\Container
✓ it exists
✓ it gets an instance
✓ autowire
✓ it creates an instance and resolves parameters
✓ it creates an instance and resolves also sub parameters
✓ it can resolve builtin value types
✓ it cannot resolve a parameter without type
PASS Tests\Unit\Support\Reflection
✓ it gets file name from closure
✓ it gets property values
@ -131,9 +138,11 @@
PASS Tests\Visual\SingleTestOrDirectory
✓ allows to run a single test
✓ allows to run a directory
✓ it has ascii chars
✓ it disable decorating printer when colors is set to never
WARN Tests\Visual\Success
s visual snapshot of test suite on success
Tests: 6 skipped, 70 passed
Time: 2.68s
Tests: 6 skipped, 79 passed
Time: 3.44s

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

@ -1,5 +1,7 @@
<?php
use function Tests\mock;
interface Foo
{
public function bar(): int;
@ -11,5 +13,5 @@ it('has bar', function () {
->times(1)
->andReturn(2);
assertEquals(2, $mock->bar());
$mock->bar();
});

View File

@ -0,0 +1,29 @@
<?php
use PHPUnit\Framework\TestCase;
uses(Gettable::class);
/**
* @return TestCase|Gettable
*/
function get(string $route)
{
return test()->get($route);
}
trait Gettable
{
/**
* @return TestCase|Gettable
*/
public function get(string $route)
{
assertNotEmpty($route);
return $this;
}
}
get('foo')->get('bar')->assertTrue(true);
get('foo')->assertTrue(true);

View File

@ -24,6 +24,6 @@ it('do not skips with falsy closure condition')
->skip(function () { return false; })
->assertTrue(true);
it('skips with condition and messsage')
it('skips with condition and message')
->skip(true, 'skipped because foo')
->assertTrue(false);

View File

@ -1,3 +1,3 @@
<?php
it('example')->assertTrue(true);
it('example 1')->assertTrue(true);

View File

@ -1,3 +1,3 @@
<?php
it('example')->assertTrue(true);
it('example 2')->assertTrue(true);

View File

@ -1,5 +1,8 @@
<?php
namespace Tests;
use Mockery;
use Mockery\MockInterface;
function mock(string $class): MockInterface

View File

@ -7,7 +7,7 @@ namespace Tests\CustomTestCase;
use function PHPUnit\Framework\assertTrue;
use PHPUnit\Framework\TestCase;
class PhpunitTest extends TestCase
class ExecutedTest extends TestCase
{
public static $executed = false;
@ -16,8 +16,8 @@ class PhpunitTest extends TestCase
{
self::$executed = true;
$this->assertTrue(true);
assertTrue(true);
}
}
// register_shutdown_function(fn () => assertTrue(PhpunitTest::$executed));
// register_shutdown_function(fn () => assertTrue(ExecutedTest::$executed));

View File

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

View File

@ -1,32 +0,0 @@
<?php
use Pest\Actions\AddsCoverage;
use Pest\TestSuite;
it('adds coverage if --coverage exist', function () {
$testSuite = new TestSuite(getcwd());
assertFalse($testSuite->coverage);
$arguments = AddsCoverage::from($testSuite, []);
assertEquals([], $arguments);
assertFalse($testSuite->coverage);
$arguments = AddsCoverage::from($testSuite, ['--coverage']);
assertEquals(['--coverage-php', \Pest\Console\Coverage::getPath()], $arguments);
assertTrue($testSuite->coverage);
});
it('adds coverage if --min exist', function () {
$testSuite = new TestSuite(getcwd());
assertEquals($testSuite->coverageMin, 0.0);
assertFalse($testSuite->coverage);
AddsCoverage::from($testSuite, []);
assertEquals($testSuite->coverageMin, 0.0);
AddsCoverage::from($testSuite, ['--min=2']);
assertEquals($testSuite->coverageMin, 2.0);
AddsCoverage::from($testSuite, ['--min=2.4']);
assertEquals($testSuite->coverageMin, 2.4);
});

View File

@ -1,24 +0,0 @@
<?php
use Pest\Console\Coverage;
it('generates coverage based on file input', function () {
assertEquals([
'4..6', '102',
], Coverage::getMissingCoverage(new class() {
public function getCoverageData(): array
{
return [
1 => ['foo'],
2 => ['bar'],
4 => [],
5 => [],
6 => [],
7 => null,
100 => null,
101 => ['foo'],
102 => [],
];
}
}));
});

View File

@ -0,0 +1,69 @@
<?php
use Pest\Exceptions\ShouldNotHappen;
use Pest\Support\Container;
use Pest\TestSuite;
uses()->group('container');
beforeEach(function () {
$this->container = new Container();
});
it('exists')
->assertTrue(class_exists(Container::class));
it('gets an instance', function () {
$this->container->add(Container::class, $this->container);
assertSame($this->container, $this->container->get(Container::class));
});
test('autowire', function () {
assertInstanceOf(Container::class, $this->container->get(Container::class));
});
it('creates an instance and resolves parameters', function () {
$this->container->add(Container::class, $this->container);
$instance = $this->container->get(ClassWithDependency::class);
assertInstanceOf(ClassWithDependency::class, $instance);
});
it('creates an instance and resolves also sub parameters', function () {
$this->container->add(Container::class, $this->container);
$instance = $this->container->get(ClassWithSubDependency::class);
assertInstanceOf(ClassWithSubDependency::class, $instance);
});
it('can resolve builtin value types', function () {
$this->container->add('rootPath', getcwd());
$instance = $this->container->get(TestSuite::class);
assertInstanceOf(TestSuite::class, $instance);
});
it('cannot resolve a parameter without type', function () {
$this->container->get(ClassWithoutTypeParameter::class);
})->throws(ShouldNotHappen::class);
class ClassWithDependency
{
public function __construct(Container $container)
{
}
}
class ClassWithSubDependency
{
public function __construct(ClassWithDependency $param)
{
}
}
class ClassWithoutTypeParameter
{
public function __construct($param)
{
}
}

View File

@ -2,31 +2,56 @@
use Symfony\Component\Process\Process;
$run = function (string $target) {
$process = new Process(['./bin/pest', $target], dirname(__DIR__, 2));
$run = function (string $target, $decorated = false) {
$process = new Process(['php', 'bin/pest', $target], dirname(__DIR__, 2));
$process->run();
return preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
return $decorated ? $process->getOutput() : preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput());
};
test('allows to run a single test', function () use ($run) {
assertStringContainsString(<<<EOF
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
it example
$snapshot = function ($name) {
$testsPath = dirname(__DIR__);
Tests: 1 passed
EOF, $run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'));
});
return file_get_contents(implode(DIRECTORY_SEPARATOR, [
$testsPath,
'.snapshots',
"$name.txt",
]));
};
test('allows to run a directory', function () use ($run) {
assertStringContainsString(<<<EOF
PASS Tests\Fixtures\DirectoryWithTests\ExampleTest
it example
test('allows to run a single test', function () use ($run, $snapshot) {
assertStringContainsString(
$snapshot('allows-to-run-a-single-test'),
$run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'));
})->skip(PHP_OS_FAMILY === 'Windows');
PASS Tests\Fixtures\ExampleTest
it example
test('allows to run a directory', function () use ($run, $snapshot) {
assertStringContainsString(
$snapshot('allows-to-run-a-directory'),
$run('tests/Fixtures')
);
})->skip(PHP_OS_FAMILY === 'Windows');
Tests: 2 passed
EOF, $run('tests/Fixtures'));
});
it('has ascii chars', function () use ($run, $snapshot) {
assertStringContainsString(
$snapshot('has-ascii-chars'),
$run('tests/Fixtures/DirectoryWithTests/ExampleTest.php', true)
);
})->skip(PHP_OS_FAMILY === 'Windows');
it('disable decorating printer when colors is set to never', function () use ($snapshot) {
$process = new Process([
'php',
'./bin/pest',
'--colors=never',
'tests/Fixtures/DirectoryWithTests/ExampleTest.php',
], dirname(__DIR__, 2));
$process->run();
$output = $process->getOutput();
assertStringContainsString(
$snapshot('disable-decorating-printer'),
$output
);
})->skip(PHP_OS_FAMILY === 'Windows');

View File

@ -9,7 +9,7 @@ test('visual snapshot of test suite on success', function () {
]);
$output = function () use ($testsPath) {
$process = (new Symfony\Component\Process\Process(['./bin/pest'], dirname($testsPath), ['EXCLUDE' => 'integration', 'REBUILD_SNAPSHOTS' => false]));
$process = (new Symfony\Component\Process\Process(['php', 'bin/pest'], dirname($testsPath), ['EXCLUDE' => 'integration', 'REBUILD_SNAPSHOTS' => false]));
$process->run();
@ -24,4 +24,5 @@ test('visual snapshot of test suite on success', function () {
array_pop($output);
assertStringContainsString(implode("\n", $output), file_get_contents($snapshot));
}
})->skip(!getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE'));
})->skip(!getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE'))
->skip(PHP_OS_FAMILY === 'Windows');