Skip to content

Commit

Permalink
Refactor class names
Browse files Browse the repository at this point in the history
  • Loading branch information
JaZo committed May 18, 2018
1 parent 5fc4721 commit 68247be
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 74 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ If you are using Laravel < 5.5 or have disabled package auto discover, you must
``` php
'providers' => [
...,
\Swis\Laravel\JavaScriptData\JavaScriptDataServiceProvider::class,
\Swis\Laravel\JavaScriptData\ServiceProvider::class,
],
```

Expand Down Expand Up @@ -111,7 +111,7 @@ return [
If you would like to make changes to the default configuration, publish and edit the configuration file:

``` bash
php artisan vendor:publish --provider="Swis\Laravel\JavaScriptData\JavaScriptDataServiceProvider" --tag="config"
php artisan vendor:publish --provider="Swis\Laravel\JavaScriptData\ServiceProvider" --tag="config"
```

## Change log
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"extra": {
"laravel": {
"providers": [
"Swis\\Laravel\\JavaScriptData\\JavaScriptDataServiceProvider"
"Swis\\Laravel\\JavaScriptData\\ServiceProvider"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/JavaScriptDataBuilder.php → src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use InvalidArgumentException;
use JsonSerializable;

class JavaScriptDataBuilder
class Builder
{
/**
* @param string $name The name for this data using dot notation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

namespace Swis\Laravel\JavaScriptData;

use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Contracts\Routing\ResponseFactory as ResponseFactoryContract;
use Illuminate\Http\Response;

class JavaScriptDataResponseFactory
class ResponseFactory
{
/**
* @var \Illuminate\Contracts\Routing\ResponseFactory
*/
private $responseFactory;

/**
* @var \Swis\Laravel\JavaScriptData\JavaScriptDataBuilder
* @var \Swis\Laravel\JavaScriptData\Builder
*/
private $javaScriptDataBuilder;
private $builder;

/**
* @param \Illuminate\Contracts\Routing\ResponseFactory $responseFactory
* @param \Swis\Laravel\JavaScriptData\JavaScriptDataBuilder $javaScriptDataBuilder
* @param \Illuminate\Contracts\Routing\ResponseFactory $responseFactory
* @param \Swis\Laravel\JavaScriptData\Builder $builder
*/
public function __construct(ResponseFactory $responseFactory, JavaScriptDataBuilder $javaScriptDataBuilder)
public function __construct(ResponseFactoryContract $responseFactory, Builder $builder)
{
$this->responseFactory = $responseFactory;
$this->javaScriptDataBuilder = $javaScriptDataBuilder;
$this->builder = $builder;
}

/**
Expand Down Expand Up @@ -55,7 +55,7 @@ public function make(string $name, $data = [], int $status = 200, array $headers
}

return $this->responseFactory->make(
$this->javaScriptDataBuilder->build($name, $data, $options),
$this->builder->build($name, $data, $options),
$status,
$headers
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Swis\Laravel\JavaScriptData;

use Illuminate\Support\Facades\Response;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\ServiceProvider as BaseServiceProvider;

class JavaScriptDataServiceProvider extends ServiceProvider
class ServiceProvider extends BaseServiceProvider
{
/**
* Bootstrap the application services.
Expand All @@ -24,7 +24,7 @@ public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/javascript-data-response.php', 'javascript-data-response');

$this->app->singleton(JavaScriptDataBuilder::class);
$this->app->singleton(Builder::class);
}

/**
Expand All @@ -37,8 +37,8 @@ protected function registerResponseMacro(string $name)
Response::macro(
$name,
function () {
$builder = app(JavaScriptDataBuilder::class);
$factory = new JavaScriptDataResponseFactory(/* @scrutinizer ignore-type */ $this, $builder);
$builder = app(Builder::class);
$factory = new ResponseFactory(/* @scrutinizer ignore-type */ $this, $builder);

return $factory->make(...\func_get_args());
}
Expand Down
18 changes: 9 additions & 9 deletions tests/JavaScriptDataBuilderTest.php → tests/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use Swis\Laravel\JavaScriptData\Stub\JsonableStub;
use Swis\Laravel\JavaScriptData\Stub\JsonSerializableStub;

class JavaScriptDataBuilderTest extends TestCase
class BuilderTest extends TestCase
{
/**
* @test
*/
public function itBuilds()
{
$builder = new JavaScriptDataBuilder();
$builder = new Builder();
$javascript = $builder->build('namespace', ['foo' => 'bar']);

$this->assertEquals(
Expand All @@ -28,7 +28,7 @@ public function itBuilds()
*/
public function itBuildsANestedNamespace()
{
$builder = new JavaScriptDataBuilder();
$builder = new Builder();
$javascript = $builder->build('name.space.string', ['foo' => 'bar']);

$this->assertEquals(
Expand All @@ -42,7 +42,7 @@ public function itBuildsANestedNamespace()
*/
public function itBuildsWithExtraJsonEncodeOptions()
{
$builder = new JavaScriptDataBuilder();
$builder = new Builder();
$javascript = $builder->build('namespace', ['test' => 'tést/tëst', 'foo' => []], JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE);

$this->assertEquals(
Expand All @@ -56,7 +56,7 @@ public function itBuildsWithExtraJsonEncodeOptions()
*/
public function itBuildsPrettyPrinted()
{
$builder = new JavaScriptDataBuilder();
$builder = new Builder();
$javascript = $builder->build('name.space', ['foo' => 'bar'], JSON_PRETTY_PRINT);

$this->assertEquals(
Expand All @@ -75,7 +75,7 @@ public function itBuildsPrettyPrinted()
*/
public function itBuildsWithArrayableData()
{
$builder = new JavaScriptDataBuilder();
$builder = new Builder();
$javascript = $builder->build('namespace', new ArrayableStub());

$this->assertEquals(
Expand All @@ -89,7 +89,7 @@ public function itBuildsWithArrayableData()
*/
public function itBuildsWithJsonableData()
{
$builder = new JavaScriptDataBuilder();
$builder = new Builder();
$javascript = $builder->build('namespace', new JsonableStub());

$this->assertEquals(
Expand All @@ -103,7 +103,7 @@ public function itBuildsWithJsonableData()
*/
public function itBuildsWithJsonSerializableData()
{
$builder = new JavaScriptDataBuilder();
$builder = new Builder();
$javascript = $builder->build('namespace', new JsonSerializableStub());

$this->assertEquals(
Expand All @@ -121,7 +121,7 @@ public function itBuildsWithJsonSerializableData()
*/
public function itThrowsWhenJsonEncodeFailed()
{
$builder = new JavaScriptDataBuilder();
$builder = new Builder();
$builder->build('namespace', "\x80");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@

namespace Swis\Laravel\JavaScriptData;

use Illuminate\Routing\ResponseFactory;
use Illuminate\Routing\ResponseFactory as IlluminateResponseFactory;
use Orchestra\Testbench\TestCase;

class JavaScriptDataResponseFactoryTest extends TestCase
class ResponseFactoryTest extends TestCase
{
/**
* @test
*/
public function itMakesAResponse()
{
/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(ResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\JavaScriptDataBuilder $javaScriptDataBuilder */
$javaScriptDataBuilder = $this->getMockBuilder(JavaScriptDataBuilder::class)
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->getMock();
$javaScriptDataBuilder
$builder
->expects($this->once())
->method('build')
->with('namespace', [], 0)
->willReturn('foo bar');

$factory = new JavaScriptDataResponseFactory($responseFactory, $javaScriptDataBuilder);
$factory = new ResponseFactory($responseFactory, $builder);
$response = $factory->make('namespace', [], 200, [], 0);

$this->assertSame('foo bar', $response->getContent());
Expand All @@ -38,17 +38,17 @@ public function itMakesAResponseWithDefaultNamespace()
$this->app['config']->set('javascript-data-response.namespace', 'foo.bar');

/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(ResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\JavaScriptDataBuilder $javaScriptDataBuilder */
$javaScriptDataBuilder = $this->getMockBuilder(JavaScriptDataBuilder::class)
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->getMock();
$javaScriptDataBuilder
$builder
->expects($this->once())
->method('build')
->with('foo.bar.namespace');

$factory = new JavaScriptDataResponseFactory($responseFactory, $javaScriptDataBuilder);
$factory = new ResponseFactory($responseFactory, $builder);
$factory->make('namespace');
}

Expand All @@ -60,17 +60,17 @@ public function itMakesAResponseWithPrettyPrintOption()
$this->app['config']->set('javascript-data-response.pretty-print', true);

/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(ResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\JavaScriptDataBuilder $javaScriptDataBuilder */
$javaScriptDataBuilder = $this->getMockBuilder(JavaScriptDataBuilder::class)
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->getMock();
$javaScriptDataBuilder
$builder
->expects($this->once())
->method('build')
->with($this->anything(), $this->anything(), JSON_PRETTY_PRINT);

$factory = new JavaScriptDataResponseFactory($responseFactory, $javaScriptDataBuilder);
$factory = new ResponseFactory($responseFactory, $builder);
$factory->make('namespace');
}

Expand All @@ -80,13 +80,13 @@ public function itMakesAResponseWithPrettyPrintOption()
public function itMakesAResponseWithDefaultStatus()
{
/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(ResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\JavaScriptDataBuilder $javaScriptDataBuilder */
$javaScriptDataBuilder = $this->getMockBuilder(JavaScriptDataBuilder::class)
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->getMock();

$factory = new JavaScriptDataResponseFactory($responseFactory, $javaScriptDataBuilder);
$factory = new ResponseFactory($responseFactory, $builder);
$response = $factory->make('namespace');

$this->assertSame(200, $response->getStatusCode());
Expand All @@ -98,13 +98,13 @@ public function itMakesAResponseWithDefaultStatus()
public function itMakesAResponseWithCustomStatus()
{
/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(ResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\JavaScriptDataBuilder $javaScriptDataBuilder */
$javaScriptDataBuilder = $this->getMockBuilder(JavaScriptDataBuilder::class)
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->getMock();

$factory = new JavaScriptDataResponseFactory($responseFactory, $javaScriptDataBuilder);
$factory = new ResponseFactory($responseFactory, $builder);
$response = $factory->make('namespace', [], 500);

$this->assertSame(500, $response->getStatusCode());
Expand All @@ -116,13 +116,13 @@ public function itMakesAResponseWithCustomStatus()
public function itMakesAResponseWithDefaultHeaders()
{
/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(ResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\JavaScriptDataBuilder $javaScriptDataBuilder */
$javaScriptDataBuilder = $this->getMockBuilder(JavaScriptDataBuilder::class)
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->getMock();

$factory = new JavaScriptDataResponseFactory($responseFactory, $javaScriptDataBuilder);
$factory = new ResponseFactory($responseFactory, $builder);

// Defaults from Symfony
$response = $factory->make('namespace');
Expand Down Expand Up @@ -157,13 +157,13 @@ public function itMakesAResponseWithCustomHeaders()
);

/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(ResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\JavaScriptDataBuilder $javaScriptDataBuilder */
$javaScriptDataBuilder = $this->getMockBuilder(JavaScriptDataBuilder::class)
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->getMock();

$factory = new JavaScriptDataResponseFactory($responseFactory, $javaScriptDataBuilder);
$factory = new ResponseFactory($responseFactory, $builder);
$response = $factory->make('namespace', [], 200, ['X-Foo' => 'Bar']);

$this->assertTrue($response->headers->has('x-foo'));
Expand All @@ -178,17 +178,17 @@ public function itMakesAResponseWithDefaultOptions()
$this->app['config']->set('javascript-data-response.json_encode-options', JSON_UNESCAPED_UNICODE);

/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(ResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\JavaScriptDataBuilder $javaScriptDataBuilder */
$javaScriptDataBuilder = $this->getMockBuilder(JavaScriptDataBuilder::class)
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->getMock();
$javaScriptDataBuilder
$builder
->expects($this->once())
->method('build')
->with($this->anything(), $this->anything(), JSON_UNESCAPED_UNICODE);

$factory = new JavaScriptDataResponseFactory($responseFactory, $javaScriptDataBuilder);
$factory = new ResponseFactory($responseFactory, $builder);
$factory->make('namespace');
}

Expand All @@ -198,17 +198,17 @@ public function itMakesAResponseWithDefaultOptions()
public function itMakesAResponseWithCustomOptions()
{
/** @var \Illuminate\Routing\ResponseFactory $responseFactory */
$responseFactory = $this->app->make(ResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\JavaScriptDataBuilder $javaScriptDataBuilder */
$javaScriptDataBuilder = $this->getMockBuilder(JavaScriptDataBuilder::class)
$responseFactory = $this->app->make(IlluminateResponseFactory::class);
/** @var \PHPUnit\Framework\MockObject\MockObject|\Swis\Laravel\JavaScriptData\Builder $builder */
$builder = $this->getMockBuilder(Builder::class)
->setMethods(['build'])
->getMock();
$javaScriptDataBuilder
$builder
->expects($this->once())
->method('build')
->with($this->anything(), $this->anything(), JSON_UNESCAPED_UNICODE);

$factory = new JavaScriptDataResponseFactory($responseFactory, $javaScriptDataBuilder);
$factory = new ResponseFactory($responseFactory, $builder);
$factory->make('namespace', [], 200, [], JSON_UNESCAPED_UNICODE);
}
}
Loading

0 comments on commit 68247be

Please sign in to comment.