Skip to content

Commit

Permalink
Merge pull request #8 from swisnl/shift-114256
Browse files Browse the repository at this point in the history
PHPUnit 10 Shift
  • Loading branch information
JaZo authored Mar 28, 2024
2 parents 673033b + fe589d2 commit 806ea6d
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ composer.lock
/vendor

# Tooling
/.phpunit.result.cache
/.phpunit.cache
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
}
],
"require": {
"php" : "^8.1",
"php": "^8.1",
"ext-json": "*",
"laravel/framework": "^10.0"
},
"require-dev": {
"laravel/pint": "^1.15",
"orchestra/testbench": "^8.0",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^10.0"
},
"autoload": {
"psr-4": {
Expand Down
25 changes: 14 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
backupStaticProperties="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
processIsolation="false"
stopOnFailure="false">
stopOnFailure="false"
cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<source>
<include>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion stubs/JsonSerializableStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class JsonSerializableStub implements \JsonSerializable
*
* @since 5.4.0
*/
public function jsonSerialize()
public function jsonSerialize(): array
{
return ['foo' => 'bar'];
}
Expand Down
51 changes: 18 additions & 33 deletions tests/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

namespace Swis\Laravel\JavaScriptData;

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Swis\Laravel\JavaScriptData\Stub\ArrayableStub;
use Swis\Laravel\JavaScriptData\Stub\JsonableStub;
use Swis\Laravel\JavaScriptData\Stub\JsonSerializableStub;

class BuilderTest extends TestCase
final class BuilderTest extends TestCase
{
/**
* @test
*/
public function itBuilds()
#[Test]
public function itBuilds(): void
{
$builder = new Builder();
$javascript = $builder->build('namespace', ['foo' => 'bar']);
Expand All @@ -23,10 +22,8 @@ public function itBuilds()
);
}

/**
* @test
*/
public function itBuildsANestedNamespace()
#[Test]
public function itBuildsANestedNamespace(): void
{
$builder = new Builder();
$javascript = $builder->build('name.space.string', ['foo' => 'bar']);
Expand All @@ -37,10 +34,8 @@ public function itBuildsANestedNamespace()
);
}

/**
* @test
*/
public function itBuildsWithExtraJsonEncodeOptions()
#[Test]
public function itBuildsWithExtraJsonEncodeOptions(): void
{
$builder = new Builder();
$javascript = $builder->build('namespace', ['test' => 'tést/tëst', 'foo' => []], JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE);
Expand All @@ -51,10 +46,8 @@ public function itBuildsWithExtraJsonEncodeOptions()
);
}

/**
* @test
*/
public function itBuildsPrettyPrinted()
#[Test]
public function itBuildsPrettyPrinted(): void
{
$builder = new Builder();
$javascript = $builder->build('name.space', ['foo' => 'bar'], JSON_PRETTY_PRINT);
Expand All @@ -70,10 +63,8 @@ public function itBuildsPrettyPrinted()
);
}

/**
* @test
*/
public function itBuildsWithArrayableData()
#[Test]
public function itBuildsWithArrayableData(): void
{
$builder = new Builder();
$javascript = $builder->build('namespace', new ArrayableStub());
Expand All @@ -84,10 +75,8 @@ public function itBuildsWithArrayableData()
);
}

/**
* @test
*/
public function itBuildsWithJsonableData()
#[Test]
public function itBuildsWithJsonableData(): void
{
$builder = new Builder();
$javascript = $builder->build('namespace', new JsonableStub());
Expand All @@ -98,10 +87,8 @@ public function itBuildsWithJsonableData()
);
}

/**
* @test
*/
public function itBuildsWithJsonSerializableData()
#[Test]
public function itBuildsWithJsonSerializableData(): void
{
$builder = new Builder();
$javascript = $builder->build('namespace', new JsonSerializableStub());
Expand All @@ -112,10 +99,8 @@ public function itBuildsWithJsonSerializableData()
);
}

/**
* @test
*/
public function itThrowsWhenJsonEncodeFailed()
#[Test]
public function itThrowsWhenJsonEncodeFailed(): void
{
$this->expectExceptionObject(new \InvalidArgumentException('Malformed UTF-8 characters, possibly incorrectly encoded', 5));

Expand Down
75 changes: 29 additions & 46 deletions tests/ResponseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@

use Illuminate\Routing\ResponseFactory as IlluminateResponseFactory;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\Test;

class ResponseFactoryTest extends TestCase
final class ResponseFactoryTest extends TestCase
{
/**
* @test
*/
public function itMakesAResponse()
#[Test]
public function itMakesAResponse(): void
{
/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->onlyMethods(['build'])
->getMock();
$builder
->expects($this->once())
Expand All @@ -30,18 +29,16 @@ public function itMakesAResponse()
$this->assertSame('foo bar', $response->getContent());
}

/**
* @test
*/
public function itMakesAResponseWithDefaultNamespace()
#[Test]
public function itMakesAResponseWithDefaultNamespace(): void
{
$this->app['config']->set('javascript-data-response.namespace', 'foo.bar');

/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->onlyMethods(['build'])
->getMock();
$builder
->expects($this->once())
Expand All @@ -52,18 +49,16 @@ public function itMakesAResponseWithDefaultNamespace()
$factory->make('namespace');
}

/**
* @test
*/
public function itMakesAResponseWithPrettyPrintOption()
#[Test]
public function itMakesAResponseWithPrettyPrintOption(): void
{
$this->app['config']->set('javascript-data-response.pretty-print', true);

/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->onlyMethods(['build'])
->getMock();
$builder
->expects($this->once())
Expand All @@ -74,16 +69,14 @@ public function itMakesAResponseWithPrettyPrintOption()
$factory->make('namespace');
}

/**
* @test
*/
public function itMakesAResponseWithDefaultStatus()
#[Test]
public function itMakesAResponseWithDefaultStatus(): void
{
/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->onlyMethods(['build'])
->getMock();

$factory = new ResponseFactory($responseFactory, $builder);
Expand All @@ -92,16 +85,14 @@ public function itMakesAResponseWithDefaultStatus()
$this->assertSame(200, $response->getStatusCode());
}

/**
* @test
*/
public function itMakesAResponseWithCustomStatus()
#[Test]
public function itMakesAResponseWithCustomStatus(): void
{
/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->onlyMethods(['build'])
->getMock();

$factory = new ResponseFactory($responseFactory, $builder);
Expand All @@ -110,16 +101,14 @@ public function itMakesAResponseWithCustomStatus()
$this->assertSame(500, $response->getStatusCode());
}

/**
* @test
*/
public function itMakesAResponseWithDefaultHeaders()
#[Test]
public function itMakesAResponseWithDefaultHeaders(): void
{
/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->onlyMethods(['build'])
->getMock();

$factory = new ResponseFactory($responseFactory, $builder);
Expand All @@ -146,10 +135,8 @@ public function itMakesAResponseWithDefaultHeaders()
$this->assertSame('application/javascript; charset=utf-8', $response->headers->get('content-type'));
}

/**
* @test
*/
public function itMakesAResponseWithCustomHeaders()
#[Test]
public function itMakesAResponseWithCustomHeaders(): void
{
$this->app['config']->set(
'javascript-data-response.headers',
Expand All @@ -160,7 +147,7 @@ public function itMakesAResponseWithCustomHeaders()
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->onlyMethods(['build'])
->getMock();

$factory = new ResponseFactory($responseFactory, $builder);
Expand All @@ -170,18 +157,16 @@ public function itMakesAResponseWithCustomHeaders()
$this->assertSame('Bar', $response->headers->get('x-foo'));
}

/**
* @test
*/
public function itMakesAResponseWithDefaultOptions()
#[Test]
public function itMakesAResponseWithDefaultOptions(): void
{
$this->app['config']->set('javascript-data-response.json_encode-options', JSON_UNESCAPED_UNICODE);

/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->onlyMethods(['build'])
->getMock();
$builder
->expects($this->once())
Expand All @@ -192,16 +177,14 @@ public function itMakesAResponseWithDefaultOptions()
$factory->make('namespace');
}

/**
* @test
*/
public function itMakesAResponseWithCustomOptions()
#[Test]
public function itMakesAResponseWithCustomOptions(): void
{
/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->onlyMethods(['build'])
->getMock();
$builder
->expects($this->once())
Expand Down
9 changes: 4 additions & 5 deletions tests/ResponseMacroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

use Illuminate\Support\Facades\Response;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\Test;

class ResponseMacroTest extends TestCase
final class ResponseMacroTest extends TestCase
{
protected function getPackageProviders($app)
{
Expand All @@ -17,10 +18,8 @@ protected function getEnvironmentSetUp($app)
$app['config']->set('javascript-data-response.pretty-print', false);
}

/**
* @test
*/
public function itMakesAResponse()
#[Test]
public function itMakesAResponse(): void
{
/** @var \Illuminate\Http\Response $response */
$response = Response::javascriptData('namespace', ['foo' => 'bar']);
Expand Down
Loading

0 comments on commit 806ea6d

Please sign in to comment.