Skip to content

Commit

Permalink
Merge branch 'update-php-unit' of https://github.com/membrane-php/mem…
Browse files Browse the repository at this point in the history
  • Loading branch information
philsturgeon committed Sep 26, 2023
2 parents 5fe4e58 + 7a9c0db commit d00c770
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 69 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"symfony/psr-http-message-bridge": "^2.1"
},
"require-dev": {
"phpunit/phpunit": "^9.5.27",
"phpunit/phpunit": "^10.0",
"phpstan/phpstan": "^1.8",
"squizlabs/php_codesniffer": "^3.7"
},
Expand Down
36 changes: 11 additions & 25 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" bootstrap="vendor/autoload.php" executionOrder="depends,defects" beStrictAboutOutputDuringTests="true" failOnRisky="true" failOnWarning="true" cacheDirectory=".phpunit.cache" requireCoverageMetadata="true" beStrictAboutCoverageMetadata="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
22 changes: 11 additions & 11 deletions tests/ApiProblemBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@

use Membrane\OpenAPI\Exception\CannotProcessRequest;
use Membrane\Renderer\Renderer;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;

/**
* @covers \Membrane\Laravel\ApiProblemBuilder
* @uses \Membrane\Laravel\ToSymfony
*/
#[CoversClass(ApiProblemBuilder::class)]
#[UsesClass(ToSymfony::class)]
class ApiProblemBuilderTest extends TestCase
{

/** @test */
#[Test]
public function buildFromRendererTest(): void
{
$expected = [
Expand All @@ -40,7 +42,7 @@ public function buildFromRendererTest(): void
self::assertEquals($expected, json_decode($actual->getContent(), true));
}

public function dataSetsToBuildFromException(): array
public static function dataSetsToBuildFromException(): array
{
return [
'path not found, no apiResponseTypes' => [
Expand Down Expand Up @@ -90,11 +92,9 @@ public function dataSetsToBuildFromException(): array
],
];
}

/**
* @test
* @dataProvider dataSetsToBuildFromException
*/

#[Test]
#[DataProvider('dataSetsToBuildFromException')]
public function buildFromExceptionTest(
CannotProcessRequest $exception,
SymfonyResponse $expected,
Expand Down
27 changes: 15 additions & 12 deletions tests/Middleware/RequestValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Membrane\Laravel\ApiProblemBuilder;
use Membrane\Laravel\ToPsr7;
use Membrane\Laravel\ToSymfony;
use Membrane\OpenAPI\Exception\CannotProcessRequest;
use Membrane\OpenAPI\Method;
use Membrane\Result\Result;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;

/**
* @covers \Membrane\Laravel\Middleware\RequestValidation
* @uses \Membrane\Laravel\ApiProblemBuilder
* @uses \Membrane\Laravel\ToPsr7
* @uses \Membrane\Laravel\ToSymfony
*/

#[CoversClass(RequestValidation::class)]
#[UsesClass(ApiProblemBuilder::class)]
#[UsesClass(ToPsr7::class)]
#[UsesClass(ToSymfony::class)]
class RequestValidationTest extends TestCase
{
/** @test */
#[Test]
public function registersResultInstanceInContainer(): void
{
$url = '/pets?limit=5&tags[]=cat&tags[]=tabby';
Expand All @@ -44,7 +49,7 @@ public function registersResultInstanceInContainer(): void
$sut->handle(Request::create($url), fn($var) => new Response());
}

public function dataSetsThatThrowCannotProcessRequest(): array
public static function dataSetsThatThrowCannotProcessRequest(): array
{
return [
'path not found' => [
Expand All @@ -62,10 +67,8 @@ public function dataSetsThatThrowCannotProcessRequest(): array
}


/**
* @test
* @dataProvider dataSetsThatThrowCannotProcessRequest
*/
#[Test]
#[DataProvider('dataSetsThatThrowCannotProcessRequest')]
public function catchesCannotProcessRequest(string $path, Method $method, CannotProcessRequest $expected): void
{
$apiProblemBuilder = self::createMock(ApiProblemBuilder::class);
Expand Down
22 changes: 12 additions & 10 deletions tests/Middleware/ResponseJsonFlatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@
use Illuminate\Contracts\Container\Container;
use Illuminate\Http\Request;
use Membrane\Laravel\ApiProblemBuilder;
use Membrane\Laravel\ToSymfony;
use Membrane\Result\FieldName;
use Membrane\Result\Message;
use Membrane\Result\MessageSet;
use Membrane\Result\Result;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;

/**
* @covers \Membrane\Laravel\Middleware\ResponseJsonFlat
* @uses \Membrane\Laravel\ApiProblemBuilder
* @uses \Membrane\Laravel\ToSymfony
*/

#[CoversClass(ResponseJsonFlat::class)]
#[UsesClass(ApiProblemBuilder::class)]
#[UsesClass(ToSymfony::class)]
class ResponseJsonFlatTest extends TestCase
{
public function dataSetsToHandle(): array
public static function dataSetsToHandle(): array
{
return [
'valid results return valid responses' => [
Expand All @@ -43,10 +47,8 @@ public function dataSetsToHandle(): array
];
}

/**
* @test
* @dataProvider dataSetsToHandle
*/
#[Test]
#[DataProvider('dataSetsToHandle')]
public function handleTest(Result $result, SymfonyResponse $expected): void
{
$request = self::createStub(Request::class);
Expand Down
21 changes: 11 additions & 10 deletions tests/Middleware/ResponseJsonNestedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@
use Membrane\Result\Message;
use Membrane\Result\MessageSet;
use Membrane\Result\Result;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;

/**
* @covers \Membrane\Laravel\Middleware\ResponseJsonNested
* @uses \Membrane\Laravel\ApiProblemBuilder
* @uses \Membrane\Laravel\ToSymfony
*/

#[CoversClass('\Membrane\Laravel\Middleware\ResponseJsonNested')]
#[UsesClass(' \Membrane\Laravel\ApiProblemBuilder')]
#[UsesClass(' \Membrane\Laravel\ToSymfony')]
class ResponseJsonNestedTest extends TestCase
{
public function dataSetsToHandle(): array
public static function dataSetsToHandle(): array
{
return [
'valid results return valid responses' => [
Expand All @@ -43,10 +46,8 @@ public function dataSetsToHandle(): array
];
}

/**
* @test
* @dataProvider dataSetsToHandle
*/
#[Test]
#[DataProvider('dataSetsToHandle')]
public function handleTest(Result $result, SymfonyResponse $expected): void
{
$request = self::createStub(Request::class);
Expand Down

0 comments on commit d00c770

Please sign in to comment.