Skip to content

Commit

Permalink
#111. Add more coverage on Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed May 27, 2018
1 parent e73ffc1 commit a498986
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ storage/
/raml/
.env
.gen/
*_create*_table.php
2 changes: 2 additions & 0 deletions tests/unit/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

abstract class TestCase extends TestCaseLaravel
{
public const DIR_OUTPUT = './tests/_output/';

/**
* The base URL to use while testing the application.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/blocks/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function setUp()
parent::setUp();
$this->gen = new RJApiGenerator();
$this->gen->modulesDir = DirsInterface::MODULES_DIR;
$this->gen->version = 'V1';
$this->gen->version = 'V2';
$this->config = new Config($this->gen);
}

Expand Down
71 changes: 66 additions & 5 deletions tests/unit/blocks/EntitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace rjapitest\unit\blocks;

use Modules\V2\Entities\Article;
use rjapi\blocks\FormRequestModel;
use rjapi\RJApiGenerator;
use rjapi\types\DirsInterface;
Expand All @@ -21,12 +22,72 @@ class EntitiesTest extends TestCase
public function setUp()
{
parent::setUp();
$gen = new RJApiGenerator();
$gen->objectName = 'Article';
$gen->version = 'v1';
$gen->modulesDir = DirsInterface::MODULES_DIR;
$gen = new RJApiGenerator();
$gen->objectName = 'Article';
$gen->version = 'v2';
$gen->modulesDir = DirsInterface::MODULES_DIR;
$gen->entitiesDir = DirsInterface::ENTITIES_DIR;
$this->entities = new Entities($gen);
$gen->types = [
'SID' => [
'type' => 'string',
'required' => true,
'maxLength' => 128,
],
'ArticleAttributes' => [
'description' => 'Article attributes description',
'type' => 'object',
'properties' => [
'title' => [
'required' => true,
'type' => 'string',
'minLength' => 16,
'maxLength' => 256,
'facets' => [
'index' => [
'idx_title' => 'index'
]
]
]
]
],
'Article' => [
'type' => 'object',
'properties' => [
'type' => 'Type',
'id' => 'SID',
'attributes' => 'ArticleAttributes',
'relationships' => [
'type' => 'TagRelationships[] | TopicRelationships',
]
]
]
];
$this->entities = new Entities($gen);
}

/**
* @test
*/
public function it_creates_entity()
{
$this->entities->createEntity('./tests/_output/', 'Test');
$this->assertTrue(file_exists(self::DIR_OUTPUT. 'ArticleTest.php'));
// check props
require_once __DIR__ . '/../../_output/ArticleTest.php';
$article = new Article();
$this->assertFalse($article->incrementing);
$this->assertFalse($article->timestamps);
$extArticle = new class extends Article {
public function getPrimaryKey() {
return $this->primaryKey;
}

public function getTable() {
return $this->table;
}
};
$this->assertEquals('id', $extArticle->getPrimaryKey());
$this->assertEquals('article', $extArticle->getTable());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/blocks/MigrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function setUp()
]
];
$gen->objectName = 'Article';
$gen->version = 'v1';
$gen->version = 'v2';
$gen->modulesDir = DirsInterface::MODULES_DIR;
$gen->middlewareDir = DirsInterface::MIDDLEWARE_DIR;
$gen->migrationsDir = DirsInterface::MIGRATIONS_DIR;
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/helpers/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use League\Fractal\Resource\Collection;
use League\Fractal\Resource\Item;
use Modules\V1\Entities\Article;
use Modules\V1\Http\Middleware\ArticleMiddleware;
use Modules\V2\Entities\Article;
use Modules\V2\Http\Middleware\ArticleMiddleware;
use PHPUnit_Framework_MockObject_MockObject;
use rjapi\extension\BaseFormRequest;
use rjapi\extension\BaseModel;
Expand Down

0 comments on commit a498986

Please sign in to comment.