Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald committed Jun 26, 2024
1 parent 8d21af3 commit d06e5c1
Showing 1 changed file with 0 additions and 30 deletions.
30 changes: 0 additions & 30 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ composer require timacdonald/callable-fake --dev
This packge requires you to be testing a pretty specfic type of API / interaction to be useful. Imagine you are developing a package that ships with the following interface...

```php
<?php

interface DependencyRepository
{
public function each(callable $callback): void;
Expand All @@ -34,8 +32,6 @@ This interface accepts a callback, and under the hood loops through all "depende
Let's see what the a test for this method might look like...

```php
<?php

public function testEachLoopsOverAllDependencies(): void
{
// arrange
Expand All @@ -58,8 +54,6 @@ public function testEachLoopsOverAllDependencies(): void
### After

```php
<?php

public function testEachLoopsOverAllDependencies(): void
{
// arrange
Expand Down Expand Up @@ -88,8 +82,6 @@ All assertions are chainable.
### assertCalled(callable $callback): self

```php
<?php

$callable->assertCalled(function (Dependency $dependency): bool {
return Str::startsWith($dependency->name, 'spatie/');
});
Expand All @@ -98,8 +90,6 @@ $callable->assertCalled(function (Dependency $dependency): bool {
### assertNotCalled(callable $callback): self

```php
<?php

$callable->assertNotCalled(function (Dependency $dependency): bool {
return Str::startsWith($dependency->name, 'timacdonald/');
});
Expand All @@ -109,8 +99,6 @@ $callable->assertNotCalled(function (Dependency $dependency): bool {

Ensure the callable was called in an explicit order, i.e. it was called as the 0th and 5th invocation.
```php
<?php

$callable->assertCalledIndex(function (Dependency $dependency): bool {
return Str::startsWith($dependency, 'spatie/');
}, [0, 5]);
Expand All @@ -119,8 +107,6 @@ $callable->assertCalledIndex(function (Dependency $dependency): bool {
### assertCalledTimes(callable $callback, int $times): self

```php
<?php

$callable->assertCalledTimes(function (Dependency $dependency): bool {
return Str::startsWith($dependency, 'spatie/');
}, 999);
Expand All @@ -129,24 +115,18 @@ $callable->assertCalledTimes(function (Dependency $dependency): bool {
### assertTimesInvoked(int $times): self

```php
<?php

$callable->assertTimesInvoked(2);
```

### assertInvoked(): self

```php
<?php

$callable->assertInvoked();
```

### assertNotInvoked(): self

```php
<?php

$callable->assertNotInvoked();
```

Expand All @@ -157,8 +137,6 @@ $callable->assertNotInvoked();
If the method is type-hinted with `\Closure` instead of callable, you can use this method to transform the callable to an instance of `\Closure`.

```php
<?php

$callable = new CallableFake;

$thing->closureTypeHintedMethod($callable->asClosure());
Expand All @@ -169,8 +147,6 @@ $callable->assertInvoked();
### wasInvoked(): bool

```php
<?php

if ($callable->wasInvoked()) {
//
}
Expand All @@ -179,8 +155,6 @@ if ($callable->wasInvoked()) {
### wasNotInvoked(): bool

```php
<?php

if ($callable->wasNotInvoked()) {
//
}
Expand All @@ -189,8 +163,6 @@ if ($callable->wasNotInvoked()) {
### called(callable $callback): array

```php
<?php

$invocationArguments = $callable->called(function (Dependency $dependency): bool {
return Str::startsWith($dependency->name, 'spatie/')
});
Expand All @@ -201,8 +173,6 @@ $invocationArguments = $callable->called(function (Dependency $dependency): bool
If you need to specify return values, this _could_ be an indicator that this is not the right tool for the job. But there are some cases where return values determine control flow, so it can be handy, in which case you can pass a "return resolver" to the named constructor `withReturnResolver`.

```php
<?php

$callable = CallableFake::withReturnResolver(function (Dependency $dependency): bool {
if ($dependency->version === '*') {
return '🤠';
Expand Down

0 comments on commit d06e5c1

Please sign in to comment.