Skip to content

Commit

Permalink
Refactor: brand new testing tool
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jun 2, 2023
1 parent 42f1721 commit 568b188
Show file tree
Hide file tree
Showing 31 changed files with 423 additions and 747 deletions.
69 changes: 46 additions & 23 deletions .docs/README.md
Expand Up @@ -10,34 +10,37 @@ composer require --dev contributte/tester

### Environment

Default configuration:

```php
use Contributte\Tester\Environment;

Environment::setup(__DIR__);
```

One-by-one configuration:

```php
use Contributte\Tester\Environment;

# Configure Nette\Tester
Environment::setupTester();

# Configure timezone (Europe/Prague by default)
Environment::setupTimezone();
# Configure timezone
Environment::setupTimezone('Europe/Prague');

# Configure many constants
Environment::setupVariables(__DIR__);
# Create folders (/tmp)
Environment::setupFolders(__DIR__);

# Fill global variables
Environment::setupGlobalVariables();

# Register robot loader
Environment::setupRobotLoader();
Environment::setupRobotLoader(function($loader){});
```

### TestCases

There are many predefined test cases.
// Configure sessions save path
Environment::setupSessions(__DIR__);

- `BaseTestCase`
- `BaseMockeryTestCase` + `TMockeryTestCase`
- `BaseMockistaTestCase` + `TMockistaTestCase`
- `BaseContainerTestCase` + `TContainerTestCase`
// Allow global test() function
Environment::setupFunctions();
```

### Toolkit

Expand All @@ -48,19 +51,39 @@ There are many predefined test cases.
- `Toolkit::bind($object)` binds new context into test function, you can access `$this->` inside.
- `Toolkit::test(function() { ... })` triggers test function.

### Notes
### Utils

#### Notes

Util class for capturing messages. Useful for callback testing.

```php
use Contributte\Tester\Utils\Notes;
use Tester\Assert;

$someClass->process(function() {
Notes::add('called');
});

Assert::equal(['called'], Notes::fetch());
```

Little helper to your tests.
## Demo

Complete example of [`tests/bootstrap.php`](`../tests/bootstrap.php`).

```php
use Contributte\Tester\Notes;
<?php declare(strict_types = 1);

Notes::add('My note');
use Contributte\Tester\Environment;

# ['My note']
$notes = Notes::fetch();
if (@!include __DIR__ . '/../vendor/autoload.php') {
echo 'Install dependencies using `composer update --dev`';
exit(1);
}

Notes::clear();
// Configure environment
Environment::setup(__DIR__);
```

---------------
Expand Down
10 changes: 10 additions & 0 deletions .github/.kodiak.toml
@@ -0,0 +1,10 @@
version = 1

[merge]
automerge_label = "automerge"
blacklist_title_regex = "^WIP.*"
blacklist_labels = ["WIP"]
method = "rebase"
delete_branch_on_merge = true
notify_on_conflict = true
optimistic_updates = false
15 changes: 15 additions & 0 deletions .github/workflows/codesniffer.yml
@@ -0,0 +1,15 @@
name: "Codesniffer"

on:
pull_request:

push:
branches: ["*"]

schedule:
- cron: "0 8 * * 1"

jobs:
codesniffer:
name: "Codesniffer"
uses: contributte/.github/.github/workflows/codesniffer.yml@v1
17 changes: 17 additions & 0 deletions .github/workflows/coverage.yml
@@ -0,0 +1,17 @@
name: "Coverage"

on:
pull_request:

push:
branches: ["*"]

schedule:
- cron: "0 8 * * 1"

jobs:
test80:
name: "Nette Tester"
uses: contributte/.github/.github/workflows/nette-tester-coverage.yml@v1
with:
php: "8.0"

0 comments on commit 568b188

Please sign in to comment.