Skip to content

Commit

Permalink
Merge branch 'release/v1.0.0-alpha.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
nekofar committed Sep 22, 2021
2 parents 0b7029a + 5388972 commit 67af713
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 45 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
- name: Install Dependencies
run: composer update --no-interaction --no-progress --ansi

- name: Run PHP-CS-Fixer
run: vendor/bin/php-cs-fixer fix -v --allow-risky=yes --dry-run --ansi
- name: Run PHP CodeSniffer
run: composer run-script phpcs

phpstan:
runs-on: ubuntu-latest
Expand All @@ -48,4 +48,4 @@ jobs:
run: composer update --prefer-stable --no-interaction --no-progress --ansi

- name: Run PHPStan
run: vendor/bin/phpstan analyse --no-progress --ansi
run: composer run-script phpstan
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
run: composer update --${{ matrix.dependency-version }} --no-interaction --no-progress --ansi

- name: Unit Tests
run: ./vendor/bin/pest --colors=always
run: composer run-script pest
28 changes: 0 additions & 28 deletions .php-cs-fixer.dist.php

This file was deleted.

28 changes: 21 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,28 @@
"preferred-install": "dist"
},
"scripts": {
"lint": "php-cs-fixer fix -v",
"test:lint": "php-cs-fixer fix -v --dry-run",
"test:types": "phpstan analyse --ansi",
"test:unit": "pest --colors=always",
"lint": "@scan",
"pest": "pest",
"phpcbf": "phpcbf",
"phpcs": "phpcs",
"phpstan": "phpstan analyse --no-progress --ansi --memory-limit 256M",
"scan": [
"@phpcs",
"@phpstan"
],
"test": [
"@test:lint",
"@test:types",
"@test:unit"
"@scan",
"@pest"
]
},
"scripts-descriptions": {
"pest": "Runs Pest tests",
"phpcbf": "Runs PHP_CodeSniffer fixes",
"phpcs": "Runs PHP_CodeSniffer tests",
"phpstan": "Runs PHPStan tests",
"phpunit": "Runs PHPUnit tests",
"scan": "Runs all scans!",
"test": "Runs all tests!"
}

}
34 changes: 34 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<ruleset name="Custom ruleset">
<description>RealtyBloc API</description>

<!-- What to scan -->
<file>.</file>

<!-- Show sniff and progress -->
<arg value="spn"/>
<arg name="colors"/>

<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="./"/>

<!-- Enables parallel processing when available for faster results. -->
<arg name="parallel" value="8"/>

<!-- Only check the PHP files. JS files are checked separately with JSCS and JSHint. -->
<arg name="extensions" value="php"/>

<!-- Exclude the behavioral tests data. -->
<exclude-pattern>/features/*</exclude-pattern>

<!-- Exclude the temporary files directory. -->
<exclude-pattern>/temp/*</exclude-pattern>

<!-- Exclude the Composer Vendor directory. -->
<exclude-pattern>/vendor/*</exclude-pattern>

<!-- Exclude the Node Modules directory. -->
<exclude-pattern>/node_modules/*</exclude-pattern>

<rule ref="NekofarCodingStandard"/>
</ruleset>
20 changes: 18 additions & 2 deletions src/Autoload.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
<?php

/*
* (c) Milad Nekofar <milad@nekofar.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Nekofar\Pest\MockClient;

function client(): MockClient
use Pest\Plugin;

Plugin::uses(ClientTrait::class);

/**
* Creates a new mock client or return an existing instance.
*
* @return object|MockClient
*/
function mockClient()
{
return new MockClient();
return test()->mockClient();
}
33 changes: 33 additions & 0 deletions src/ClientTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* (c) Milad Nekofar <milad@nekofar.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Nekofar\Pest\MockClient;

/**
* @internal
*/
trait ClientTrait
{
/**
* @var MockClient
*/
protected $mockClient;

/**
* Creates a new mock client or return an existing instance.
*
* @return object|MockClient
*/
public function mockClient()
{
return $this->mockClient ?? ($this->mockClient = new MockClient());
}
}
20 changes: 18 additions & 2 deletions src/MockClient.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
<?php

/*
* (c) Milad Nekofar <milad@nekofar.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Nekofar\Pest\MockClient;

use Http\Mock\Client;
use PHPUnit\Framework\Assert as PHPUnit;
use Psr\Http\Client\ClientInterface;

/**
Expand All @@ -27,12 +35,20 @@ public function __construct()
$this->client = new Client();
}

/**
* Assert that the client has the expected count of requests at the given.
*/
public function assertRequestCount(int $count): void
{
PHPUnit::assertCount($count, $this->getRequests());
}

/**
* Proxies calls to the original client object.
*
* @param array<int, mixed> $arguments
* @param array<int, object|callable|null> $arguments
*
* @return mixed
* @return void|object|boolean
*/
public function __call(string $method, array $arguments)
{
Expand Down
6 changes: 4 additions & 2 deletions tests/Functions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use function Nekofar\Pest\MockClient\client;
declare(strict_types=1);

client();
use function Nekofar\Pest\MockClient\mockClient;

mockClient()->assertRequestCount(0);
16 changes: 16 additions & 0 deletions tests/MockClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use GuzzleHttp\Psr7\Request;

use function Nekofar\Pest\MockClient\mockClient;

it('can send multiple requests', function (): void {
$request = new Request('GET', '/');

mockClient()->sendRequest($request);
mockClient()->sendRequest($request);

expect(mockClient()->getRequests())->toHaveCount(2);
});

0 comments on commit 67af713

Please sign in to comment.