-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addsunit tests for property renderers (#6)
- Loading branch information
1 parent
8fae316
commit 46b8abb
Showing
15 changed files
with
441 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
tests/Schema/Renderer/ConsoleRenderer/Renderer/ColumnsRendererTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\Schema\Renderer\Tests\ConsoleRenderer\Renderer; | ||
|
||
use Cycle\ORM\SchemaInterface; | ||
use Cycle\Schema\Renderer\ConsoleRenderer\Formatter; | ||
use Cycle\Schema\Renderer\ConsoleRenderer\Formatter\PlainFormatter; | ||
use Cycle\Schema\Renderer\ConsoleRenderer\Renderer\ColumnsRenderer; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ColumnsRendererTest extends TestCase | ||
{ | ||
private Formatter $formatter; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->formatter = new PlainFormatter(); | ||
} | ||
|
||
public function testRenderNullValue() | ||
{ | ||
$renderer = new ColumnsRenderer(); | ||
|
||
$result = $renderer->render($this->formatter, [SchemaInterface::COLUMNS => null], 'bar'); | ||
|
||
$this->assertSame(' Fields: not defined', $result); | ||
} | ||
|
||
public function testRenderStringValue() | ||
{ | ||
$renderer = new ColumnsRenderer(); | ||
|
||
$result = $renderer->render($this->formatter, [SchemaInterface::COLUMNS => 'foo'], 'bar'); | ||
|
||
$this->assertSame(' Fields: not defined', $result); | ||
} | ||
|
||
public function testRenderArrayWithoutTypecastValue() | ||
{ | ||
$renderer = new ColumnsRenderer(); | ||
|
||
$result = $renderer->render($this->formatter, [ | ||
SchemaInterface::COLUMNS => [ | ||
'id' => 'integer', | ||
'title' => 'string(36)', | ||
'description' => 'string', | ||
], | ||
], 'bar'); | ||
|
||
$this->assertSame( | ||
<<<'OUT' | ||
Fields: | ||
(property -> db.field -> typecast) | ||
id -> integer | ||
title -> string(36) | ||
description -> string | ||
OUT | ||
, | ||
$result | ||
); | ||
} | ||
|
||
public function testRenderArrayWithTypecastValue() | ||
{ | ||
$renderer = new ColumnsRenderer(); | ||
|
||
$result = $renderer->render($this->formatter, [ | ||
SchemaInterface::COLUMNS => [ | ||
'id' => 'integer', | ||
'title' => 'string', | ||
'slug' => 'string', | ||
'json' => 'json', | ||
'description' => 'text', | ||
], | ||
SchemaInterface::TYPECAST => [ | ||
'id' => 'int', | ||
'title' => null, | ||
'slug' => '', | ||
'json' => ['Json', 'cast'], | ||
'description' => [], | ||
], | ||
], 'bar'); | ||
|
||
$this->assertSame( | ||
<<<'OUT' | ||
Fields: | ||
(property -> db.field -> typecast) | ||
id -> integer -> int | ||
title -> string | ||
slug -> string | ||
json -> json -> Json::cast | ||
description -> text | ||
OUT | ||
, | ||
$result | ||
); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
tests/Schema/Renderer/ConsoleRenderer/Renderer/KeysRendererTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\Schema\Renderer\Tests\ConsoleRenderer\Renderer; | ||
|
||
use Cycle\Schema\Renderer\ConsoleRenderer\Formatter; | ||
use Cycle\Schema\Renderer\ConsoleRenderer\Formatter\PlainFormatter; | ||
use Cycle\Schema\Renderer\ConsoleRenderer\Renderer\KeysRenderer; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class KeysRendererTest extends TestCase | ||
{ | ||
private Formatter $formatter; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->formatter = new PlainFormatter(); | ||
} | ||
|
||
public function testRenderNullNotRequiredValue() | ||
{ | ||
$renderer = new KeysRenderer(1, 'Foo', false); | ||
|
||
$result = $renderer->render($this->formatter, [1 => null], 'bar'); | ||
|
||
$this->assertNull($result); | ||
} | ||
|
||
public function testRenderNullRequiredValue() | ||
{ | ||
$renderer = new KeysRenderer(1, 'Foo', true); | ||
|
||
$result = $renderer->render($this->formatter, [1 => null], 'bar'); | ||
|
||
$this->assertSame(' Foo: not defined', $result); | ||
} | ||
|
||
public function testRenderStringValue() | ||
{ | ||
$renderer = new KeysRenderer(1, 'Foo'); | ||
|
||
$result = $renderer->render($this->formatter, [1 => 'foo'], 'bar'); | ||
|
||
$this->assertSame(' Foo: foo', $result); | ||
} | ||
|
||
public function testRenderEmptyStringValue() | ||
{ | ||
$renderer = new KeysRenderer(1, 'Foo'); | ||
|
||
$result = $renderer->render($this->formatter, [1 => ''], 'bar'); | ||
|
||
$this->assertSame(' Foo: not defined', $result); | ||
} | ||
|
||
public function testRenderEmptyArrayValue() | ||
{ | ||
$renderer = new KeysRenderer(1, 'Foo'); | ||
|
||
$result = $renderer->render($this->formatter, [1 => []], 'bar'); | ||
|
||
$this->assertSame(' Foo: not defined', $result); | ||
} | ||
|
||
public function testRenderSingleItemArrayValue() | ||
{ | ||
$renderer = new KeysRenderer(1, 'Foo'); | ||
|
||
$result = $renderer->render($this->formatter, [1 => ['hello']], 'bar'); | ||
|
||
$this->assertSame(' Foo: hello', $result); | ||
} | ||
|
||
public function testRenderArrayValue() | ||
{ | ||
$renderer = new KeysRenderer(1, 'Foo'); | ||
|
||
$result = $renderer->render($this->formatter, [1 => ['hello', 'world']], 'bar'); | ||
|
||
$this->assertSame(' Foo: hello, world', $result); | ||
} | ||
} |
Oops, something went wrong.