Skip to content

Commit

Permalink
Apply fixes from StyleCI (#47)
Browse files Browse the repository at this point in the history
Co-authored-by: Cyvelnet <Cyvelnet@users.noreply.github.com>
  • Loading branch information
Cyvelnet and Cyvelnet committed Sep 7, 2020
1 parent fbd60f9 commit 00cd978
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 22 deletions.
Expand Up @@ -90,8 +90,10 @@ public function handle()
$transformer = "{$directory}/{$class}";

if ($this->filesystem->exists("{$transformer}.php")) {
if ($usrResponse = strtolower($this->ask("The filesystem ['{$class}'] already exists, overwrite? [y/n]",
null))
if ($usrResponse = strtolower($this->ask(
"The filesystem ['{$class}'] already exists, overwrite? [y/n]",
null
))
) {
switch ($usrResponse) {
case 'y':
Expand All @@ -112,16 +114,20 @@ public function handle()
}

// loading transformers template from views
$view = $this->view->make('fractal::transformer',
$view = $this->view->make(
'fractal::transformer',
[
'namespace' => $namespace,
'class_name' => $class,
'attributes' => $transformerAttrs,
'modelClass' => $model ? $modelClass : null,
'model' => $model,
'parentClass' => $this->config->get('fractal.abstract_parent',
'TransformerAbstract') ?: 'TransformerAbstract',
]);
'parentClass' => $this->config->get(
'fractal.abstract_parent',
'TransformerAbstract'
) ?: 'TransformerAbstract',
]
);

if ($create) {
$this->filesystem->put("{$directory}/{$class}.php", $view->render());
Expand Down
7 changes: 5 additions & 2 deletions tests/JsonApiTransformationTest.php
Expand Up @@ -8,8 +8,11 @@ public function test_with_fieldsets_with_json_api_serializer()
{
$service = $this->getService();

$data = $service->setSerializer(new JsonApiSerializer())->fieldsets(['orders' => 'item, qty'])->collection($this->getTestUserData(),
new UserTransformerWithDefaultIncludesStub(), 'user')->getArray();
$data = $service->setSerializer(new JsonApiSerializer())->fieldsets(['orders' => 'item, qty'])->collection(
$this->getTestUserData(),
new UserTransformerWithDefaultIncludesStub(),
'user'
)->getArray();

$this->assertEquals([
'data' => [
Expand Down
42 changes: 28 additions & 14 deletions tests/TranformationTest.php
Expand Up @@ -11,8 +11,10 @@ public function test_parameter_includes()
{
$service = $this->getService();

$data = $service->includes('orders')->collection($this->getTestUserData(),
new UserTransformerStub())->getArray();
$data = $service->includes('orders')->collection(
$this->getTestUserData(),
new UserTransformerStub()
)->getArray();

$this->assertTrue(isset($data['data'][0]['orders']));
}
Expand All @@ -21,8 +23,10 @@ public function test_parameter_excludes()
{
$service = $this->getService();

$data = $service->excludes('orders')->collection($this->getTestUserData(),
new UserTransformerWithDefaultIncludesStub())->getArray();
$data = $service->excludes('orders')->collection(
$this->getTestUserData(),
new UserTransformerWithDefaultIncludesStub()
)->getArray();

$this->assertFalse(isset($data['data'][0]['orders']));
}
Expand All @@ -31,8 +35,10 @@ public function test_default_includes()
{
$service = $this->getService();

$data = $service->collection($this->getTestUserData(),
new UserTransformerWithDefaultIncludesStub())->getArray();
$data = $service->collection(
$this->getTestUserData(),
new UserTransformerWithDefaultIncludesStub()
)->getArray();

$this->assertTrue(isset($data['data'][0]['orders']));
}
Expand Down Expand Up @@ -61,8 +67,10 @@ public function test_excludes_with_data()
{
$service = $this->getService();

$data = $service->excludes('orders')->collection($this->getTestUserData(),
new UserTransformerWithDefaultIncludesStub())->getArray();
$data = $service->excludes('orders')->collection(
$this->getTestUserData(),
new UserTransformerWithDefaultIncludesStub()
)->getArray();

$this->assertEquals([
'data' => [
Expand All @@ -82,8 +90,10 @@ public function test_with_meta_data()
{
$service = $this->getService();

$data = $service->addMeta('foo', 'bar')->collection($this->getTestUserData(),
new UserTransformerStub())->getArray();
$data = $service->addMeta('foo', 'bar')->collection(
$this->getTestUserData(),
new UserTransformerStub()
)->getArray();

$this->assertEquals([
'data' => [
Expand All @@ -106,8 +116,10 @@ public function test_sub_relation_with_getting_only_one_record_from_sub_relation
{
$service = $this->getService();

$data = $service->includes('order_histories:limit(1|0)')->collection($this->getTestUserData(),
new UserTransformerStub())->getArray();
$data = $service->includes('order_histories:limit(1|0)')->collection(
$this->getTestUserData(),
new UserTransformerStub()
)->getArray();

$this->assertEquals(1, count(Arr::get($data, 'data.0.order_histories.data')));
$this->assertEquals([
Expand Down Expand Up @@ -146,8 +158,10 @@ public function test_sub_relation_with_getting_only_n_record_from_sub_relation()
{
$service = $this->getService();

$data = $service->includes('order_histories:limit(3|0)')->collection($this->getTestUserData(),
new UserTransformerStub())->getArray();
$data = $service->includes('order_histories:limit(3|0)')->collection(
$this->getTestUserData(),
new UserTransformerStub()
)->getArray();

$this->assertEquals(3, count(Arr::get($data, 'data.0.order_histories.data')));
}
Expand Down

0 comments on commit 00cd978

Please sign in to comment.