Skip to content

Commit

Permalink
Merge pull request #8 from mindplay-dk/1.0.0
Browse files Browse the repository at this point in the history
1.0.0
  • Loading branch information
mindplay-dk authored Feb 25, 2021
2 parents e82361f + 69fc7a9 commit 6501bc0
Show file tree
Hide file tree
Showing 11 changed files with 1,210 additions and 266 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor
.idea
/vendor
/.idea
/test/build/**/*
47 changes: 29 additions & 18 deletions readme.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ Tries to honor the [Go language philosophy of testing](http://golang.org/doc/faq
> mechanisms, but PHP already has all those capabilities; why recreate them? We'd rather write tests in PHP; it's one
> fewer language to learn and the approach keeps the tests straightforward and easy to understand.
The primary test API is procedural-style global functions - you're cool with that, because you don't
have anything else is the global namespace, right?
The primary test API is procedural-style functions in the `test` namespace.

Internally, the procedural API is backed by a pair of simple driver and configuration classes - these are left
as open as possible, and you should feel comfortable extending these and tailoring them specifically to suit the
Expand All @@ -25,29 +24,39 @@ Install via Composer:

Then create a test script - the format is pretty simple:

```PHP
```php
<?php

// import the functions you need:

use function mindplay\testies\{test, ok};

// bootstrap Composer:

require dirname(__DIR__) . '/vendor/autoload.php';

// define your tests:

test(
'Describe your test here',
function () {
ok(true, 'it works!');
}
);

// run your tests:

exit(run()); // exits with errorlevel (for CI tools etc.)
```

You will call `test()` as many times as you need to - the tests will queue up, and execute when you call `run()`.
You can call `test()` as many times as you need to - the tests will queue up, and execute when you call `run()`.


### Procedural API

Basic API overview:
The following functions are available in the `mindplay\testies` namespace:

```PHP
```php
# Assertions:

ok($result, $why, $value); # check the result on an expression
Expand All @@ -64,7 +73,7 @@ format($value, $detailed = false); # format a value for use in diagnosti
Rather than providing hundreds of assertion functions, you perform assertions using PHP expressions,
often in concert with helper, and built-in standard functions in PHP - some examples:

```PHP
```php
test(
'Various things of great importance',
function () {
Expand All @@ -88,7 +97,7 @@ ordinary everyday code.
Your custom assertion functions, like the built-in assertion functions, are just functions - usually
these will call back to the `ok()` function to report the result. For example:

```PHP
```php
/**
* Assert that a numeric value is very close to a given expected value
*
Expand All @@ -112,7 +121,7 @@ test(

You can use the same approach to group multiple assertions:

```PHP
```php
function checkValue($value) {
ok(is_int($value), "value should be numeric", $value);
ok($value > 0, "value should be positive", $value);
Expand Down Expand Up @@ -142,7 +151,7 @@ For test scenarios where the code needs to run out-of-process (such as [mockery]
or if you need to check the response from a script (e.g. using [guzzle](https://packagist.org/packages/guzzlehttp/guzzle)),
we provide a simple wrapper class to launch and shut down a server:

```PHP
```php
use GuzzleHttp\Client;

$server = new TestServer(__DIR__, 8088);
Expand Down Expand Up @@ -179,19 +188,19 @@ to the current instance of `TestConfiguration`.

To enable code coverage and display the summary result on the console:

```PHP
```php
configure()->enableCodeCoverage();
```

To output a `clover.xml` file for integration with external analysis tools, specify an output path:

```PHP
```php
configure()->enableCodeCoverage(__DIR__ . '/build/clover.xml');
```

To enable code coverage analysis only for files in certain folders, pass a path (or array of paths) like so:

```PHP
```php
configure()->enableCodeCoverage(__DIR__ . '/build/clover.xml', dirname(__DIR__) . '/src');
```

Expand All @@ -201,17 +210,19 @@ configure()->enableCodeCoverage(__DIR__ . '/build/clover.xml', dirname(__DIR__)
By default, test output does not produce messages about successful assertions, only failures - if you
want more stuff to look at, enable verbose output:

```PHP
```php
configure()->enableVerboseOutput();
```

You can also enable this from the command line with the `-v` or `--verbose` switch.


### Strict Error Handling

By default, all PHP errors/warnings/notices are automatically mapped to exceptions via a simple
built-in error handler. If you're testing something that has custom error handling, you can disable it with:

```PHP
```php
configure()->disableErrorHandler();
```

Expand All @@ -225,7 +236,7 @@ how special objects are formatted for output on the console.

To use a custom, derived `TestConfiguration` class:

```PHP
```php
// Derive your custom configuration class:

class MyTestConfiguration extends TestConfiguration
Expand All @@ -242,7 +253,7 @@ Then proceed with business as usual.

To use a custom, derived `TestDriver` class:

```PHP
```php
// Derive your custom driver class:

class MyTestDriver extends TestDriver
Expand All @@ -257,7 +268,7 @@ configure(new TestConfiguration(new TestDriver));

Alternatively, create a configuration class that provides a custom default driver class:

```PHP
```php
class MyTestDriver extends TestDriver
{
// ...
Expand Down
9 changes: 9 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Upgrading From 0.x to 1.0

Version 0.x had functions in the global namespace - these have been moved to the `mindplay\testies` namespace.

In your test-suites, you must explicitly import the functions you need:

```php
use function mindplay\testies\{configure, test, ok, eq, run};
```
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
"authors": [
{
"name": "Rasmus Schultz",
"email": "rasc@fynskemedier.dk"
"email": "rasmus@mindplay.dk"
}
],
"suggest": {
"phpunit/php-code-coverage": "^3.0"
"require": {
"php": "^7.3 || ^8.0"
},
"require-dev": {
"phpunit/php-code-coverage": "^3.0",
"guzzlehttp/guzzle": "5.*"
"phpunit/php-code-coverage": "^9.2.5",
"guzzlehttp/guzzle": "^6.3.3"
},
"suggest": {
"phpunit/php-code-coverage": "^9.2.5"
},
"autoload": {
"files": ["header.php"],
"files": ["src/test.func.php"],
"psr-4": {
"mindplay\\testies\\": "src/"
}
Expand Down
Loading

0 comments on commit 6501bc0

Please sign in to comment.